Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework the API layers between the standard library and the operating system #2527

Merged
merged 24 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67726e3
extract posix functions from std/os.zig to std/os/posix.zig
andrewrk May 19, 2019
daae7e1
more progress on posix API layer
andrewrk May 20, 2019
2def230
more progress. moving windows API layer to its own file
andrewrk May 24, 2019
17b0166
do Jay's suggestion with posix/os API naming & layout
andrewrk May 24, 2019
3d61e42
rename "posix" to "bits"
andrewrk May 24, 2019
ca6debc
starting to fix the regressions
andrewrk May 25, 2019
7cb6279
clean up references to posix
andrewrk May 25, 2019
2f040a2
clean up references to os
andrewrk May 26, 2019
44a049e
more cleanup. down to just the `@hasDecl` builtin
andrewrk May 26, 2019
2b42e91
behavior tests passing on Linux
andrewrk May 26, 2019
0c6ab61
tests passing on linux
andrewrk May 27, 2019
6be79d7
fixes for Windows and WASI
andrewrk May 27, 2019
129714d
more fixes for windows and wasi
andrewrk May 27, 2019
fda7e0b
std lib fixes for zig build on windows
andrewrk May 27, 2019
abf959a
fix debug builds of WASI
andrewrk May 27, 2019
f1610f6
nanosleep: move windows logic to std.time
andrewrk May 27, 2019
0643553
fixes for darwin
andrewrk May 27, 2019
13265cf
std.fs: fix error set regressions on linux
andrewrk May 27, 2019
b3dc1c3
use close$NOCANCEL on darwin
andrewrk May 27, 2019
db0a5e7
darwin: add missing error handling
andrewrk May 27, 2019
5de07ab
revert hello world examples. macos tests passing
andrewrk May 27, 2019
86bb7e5
fixes for windows to build self hosted compiler
andrewrk May 27, 2019
af4b8eb
windows does not integrate cleanly with libc
andrewrk May 27, 2019
3640303
freebsd fixes
andrewrk May 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ set(ZIG_STD_FILES
"c/linux.zig"
"c/netbsd.zig"
"c/windows.zig"
"child_process.zig"
"coff.zig"
"crypto.zig"
"crypto/blake2.zig"
Expand All @@ -487,8 +488,8 @@ set(ZIG_STD_FILES
"crypto/x25519.zig"
"cstr.zig"
"debug.zig"
"debug/leb128.zig"
"debug/failing_allocator.zig"
"debug/leb128.zig"
"dwarf.zig"
"dynamic_library.zig"
"elf.zig"
Expand All @@ -509,6 +510,10 @@ set(ZIG_STD_FILES
"fmt/errol/enum3.zig"
"fmt/errol/lookup.zig"
"fmt/parse_float.zig"
"fs.zig"
"fs/file.zig"
"fs/get_app_data_dir.zig"
"fs/path.zig"
"hash.zig"
"hash/adler.zig"
"hash/crc.zig"
Expand All @@ -517,8 +522,8 @@ set(ZIG_STD_FILES
"hash_map.zig"
"heap.zig"
"io.zig"
"io/seekable_stream.zig"
"io/c_out_stream.zig"
"io/seekable_stream.zig"
"json.zig"
"lazy_init.zig"
"linked_list.zig"
Expand Down Expand Up @@ -600,40 +605,39 @@ set(ZIG_STD_FILES
"mutex.zig"
"net.zig"
"os.zig"
"os/child_process.zig"
"os/bits.zig"
"os/bits/darwin.zig"
"os/bits/freebsd.zig"
"os/bits/linux.zig"
"os/bits/linux/arm64.zig"
"os/bits/linux/errno.zig"
"os/bits/linux/x86_64.zig"
"os/bits/netbsd.zig"
"os/bits/wasi.zig"
"os/bits/windows.zig"
"os/darwin.zig"
"os/darwin/errno.zig"
"os/epoch.zig"
"os/file.zig"
"os/freebsd.zig"
"os/freebsd/errno.zig"
"os/get_app_data_dir.zig"
"os/get_user_id.zig"
"os/linux.zig"
"os/linux/arm64.zig"
"os/linux/errno.zig"
"os/linux/tls.zig"
"os/linux/vdso.zig"
"os/linux/x86_64.zig"
"os/netbsd.zig"
"os/netbsd/errno.zig"
"os/path.zig"
"os/time.zig"
"os/uefi.zig"
"os/wasi.zig"
"os/wasi/core.zig"
"os/windows.zig"
"os/windows/advapi32.zig"
"os/windows/bits.zig"
"os/windows/error.zig"
"os/windows/kernel32.zig"
"os/windows/ntdll.zig"
"os/windows/ole32.zig"
"os/windows/shell32.zig"
"os/windows/util.zig"
"os/zen.zig"
"packed_int_array.zig"
"pdb.zig"
"priority_queue.zig"
"process.zig"
"rand.zig"
"rand/ziggurat.zig"
"rb.zig"
Expand All @@ -645,17 +649,18 @@ set(ZIG_STD_FILES
"special/build_runner.zig"
"special/c.zig"
"special/compiler_rt.zig"
"special/compiler_rt/stack_probe.zig"
"special/compiler_rt/arm/aeabi_fcmp.zig"
"special/compiler_rt/arm/aeabi_dcmp.zig"
"special/compiler_rt/addXf3.zig"
"special/compiler_rt/arm/aeabi_dcmp.zig"
"special/compiler_rt/arm/aeabi_fcmp.zig"
"special/compiler_rt/ashlti3.zig"
"special/compiler_rt/ashrti3.zig"
"special/compiler_rt/aulldiv.zig"
"special/compiler_rt/aullrem.zig"
"special/compiler_rt/comparetf2.zig"
"special/compiler_rt/comparedf2.zig"
"special/compiler_rt/comparesf2.zig"
"special/compiler_rt/divsf3.zig"
"special/compiler_rt/comparetf2.zig"
"special/compiler_rt/divdf3.zig"
"special/compiler_rt/divsf3.zig"
"special/compiler_rt/divti3.zig"
"special/compiler_rt/extendXfYf2.zig"
"special/compiler_rt/fixdfdi.zig"
Expand All @@ -680,26 +685,25 @@ set(ZIG_STD_FILES
"special/compiler_rt/fixunstfti.zig"
"special/compiler_rt/floatdidf.zig"
"special/compiler_rt/floatsiXf.zig"
"special/compiler_rt/floatunsidf.zig"
"special/compiler_rt/floattidf.zig"
"special/compiler_rt/floattisf.zig"
"special/compiler_rt/floattitf.zig"
"special/compiler_rt/floatundidf.zig"
"special/compiler_rt/floatunditf.zig"
"special/compiler_rt/floatunsidf.zig"
"special/compiler_rt/floatunsitf.zig"
"special/compiler_rt/floatuntidf.zig"
"special/compiler_rt/floatuntisf.zig"
"special/compiler_rt/floatuntitf.zig"
"special/compiler_rt/lshrti3.zig"
"special/compiler_rt/modti3.zig"
"special/compiler_rt/mulXf3.zig"
"special/compiler_rt/muloti4.zig"
"special/compiler_rt/mulodi4.zig"
"special/compiler_rt/muloti4.zig"
"special/compiler_rt/multi3.zig"
"special/compiler_rt/ashlti3.zig"
"special/compiler_rt/ashrti3.zig"
"special/compiler_rt/lshrti3.zig"
"special/compiler_rt/negXf2.zig"
"special/compiler_rt/popcountdi2.zig"
"special/compiler_rt/stack_probe.zig"
"special/compiler_rt/truncXfYf2.zig"
"special/compiler_rt/udivmod.zig"
"special/compiler_rt/udivmoddi4.zig"
Expand All @@ -716,6 +720,9 @@ set(ZIG_STD_FILES
"statically_initialized_mutex.zig"
"std.zig"
"testing.zig"
"thread.zig"
"time.zig"
"time/epoch.zig"
"unicode.zig"
"valgrind.zig"
"valgrind/callgrind.zig"
Expand Down
32 changes: 15 additions & 17 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ const builtin = @import("builtin");
const std = @import("std");
const Builder = std.build.Builder;
const tests = @import("test/tests.zig");
const os = std.os;
const BufMap = std.BufMap;
const warn = std.debug.warn;
const mem = std.mem;
const ArrayList = std.ArrayList;
const Buffer = std.Buffer;
const io = std.io;
const fs = std.fs;

pub fn build(b: *Builder) !void {
const mode = b.standardReleaseOptions();

var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");

const rel_zig_exe = try os.path.relative(b.allocator, b.build_root, b.zig_exe);
const langref_out_path = os.path.join(
const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
const langref_out_path = fs.path.join(
b.allocator,
[][]const u8{ b.cache_root, "langref.html" },
) catch unreachable;
var docgen_cmd = docgen_exe.run();
docgen_cmd.addArgs([][]const u8{
rel_zig_exe,
"doc" ++ os.path.sep_str ++ "langref.html.in",
"doc" ++ fs.path.sep_str ++ "langref.html.in",
langref_out_path,
});
docgen_cmd.step.dependOn(&docgen_exe.step);
Expand Down Expand Up @@ -137,7 +137,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
for (dep.libdirs.toSliceConst()) |lib_dir| {
lib_exe_obj.addLibPath(lib_dir);
}
const lib_dir = os.path.join(
const lib_dir = fs.path.join(
b.allocator,
[][]const u8{ dep.prefix, "lib" },
) catch unreachable;
Expand All @@ -146,7 +146,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
([]const u8)("libncurses.a")
else
b.fmt("lib{}.a", lib);
const static_lib_name = os.path.join(
const static_lib_name = fs.path.join(
b.allocator,
[][]const u8{ lib_dir, static_bare_name },
) catch unreachable;
Expand All @@ -166,18 +166,16 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
}

fn fileExists(filename: []const u8) !bool {
os.File.access(filename) catch |err| switch (err) {
error.PermissionDenied,
error.FileNotFound,
=> return false,
fs.File.access(filename) catch |err| switch (err) {
error.FileNotFound => return false,
else => return err,
};
return true;
}

fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
lib_exe_obj.addObjectFile(os.path.join(b.allocator, [][]const u8{
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [][]const u8{
cmake_binary_dir,
"zig_cpp",
b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()),
Expand Down Expand Up @@ -223,7 +221,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
if (mem.startsWith(u8, lib_arg, "-l")) {
try result.system_libs.append(lib_arg[2..]);
} else {
if (os.path.isAbsolute(lib_arg)) {
if (fs.path.isAbsolute(lib_arg)) {
try result.libs.append(lib_arg);
} else {
try result.system_libs.append(lib_arg);
Expand Down Expand Up @@ -257,8 +255,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
var it = mem.tokenize(stdlib_files, ";");
while (it.next()) |stdlib_file| {
const src_path = os.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
const dest_path = os.path.join(
const src_path = fs.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
const dest_path = fs.path.join(
b.allocator,
[][]const u8{ "lib", "zig", "std", stdlib_file },
) catch unreachable;
Expand All @@ -269,8 +267,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
var it = mem.tokenize(c_header_files, ";");
while (it.next()) |c_header_file| {
const src_path = os.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
const dest_path = os.path.join(
const src_path = fs.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
const dest_path = fs.path.join(
b.allocator,
[][]const u8{ "lib", "zig", "include", c_header_file },
) catch unreachable;
Expand Down Expand Up @@ -315,7 +313,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
}
dependOnLib(b, exe, ctx.llvm);

if (exe.target.getOs() == builtin.Os.linux) {
if (exe.target.getOs() == .linux) {
try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
\\Unable to determine path to libstdc++.a
\\On Fedora, install libstdc++-static and try again.
Expand Down
Loading