Skip to content

Commit 6a56091

Browse files
authored
Merge pull request #2527 from ziglang/posix-layer
rework the API layers between the standard library and the operating system
2 parents df7aa9a + 3640303 commit 6a56091

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+11936
-11821
lines changed

CMakeLists.txt

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ set(ZIG_STD_FILES
474474
"c/linux.zig"
475475
"c/netbsd.zig"
476476
"c/windows.zig"
477+
"child_process.zig"
477478
"coff.zig"
478479
"crypto.zig"
479480
"crypto/blake2.zig"
@@ -487,8 +488,8 @@ set(ZIG_STD_FILES
487488
"crypto/x25519.zig"
488489
"cstr.zig"
489490
"debug.zig"
490-
"debug/leb128.zig"
491491
"debug/failing_allocator.zig"
492+
"debug/leb128.zig"
492493
"dwarf.zig"
493494
"dynamic_library.zig"
494495
"elf.zig"
@@ -509,6 +510,10 @@ set(ZIG_STD_FILES
509510
"fmt/errol/enum3.zig"
510511
"fmt/errol/lookup.zig"
511512
"fmt/parse_float.zig"
513+
"fs.zig"
514+
"fs/file.zig"
515+
"fs/get_app_data_dir.zig"
516+
"fs/path.zig"
512517
"hash.zig"
513518
"hash/adler.zig"
514519
"hash/crc.zig"
@@ -517,8 +522,8 @@ set(ZIG_STD_FILES
517522
"hash_map.zig"
518523
"heap.zig"
519524
"io.zig"
520-
"io/seekable_stream.zig"
521525
"io/c_out_stream.zig"
526+
"io/seekable_stream.zig"
522527
"json.zig"
523528
"lazy_init.zig"
524529
"linked_list.zig"
@@ -600,40 +605,39 @@ set(ZIG_STD_FILES
600605
"mutex.zig"
601606
"net.zig"
602607
"os.zig"
603-
"os/child_process.zig"
608+
"os/bits.zig"
609+
"os/bits/darwin.zig"
610+
"os/bits/freebsd.zig"
611+
"os/bits/linux.zig"
612+
"os/bits/linux/arm64.zig"
613+
"os/bits/linux/errno.zig"
614+
"os/bits/linux/x86_64.zig"
615+
"os/bits/netbsd.zig"
616+
"os/bits/wasi.zig"
617+
"os/bits/windows.zig"
604618
"os/darwin.zig"
605-
"os/darwin/errno.zig"
606-
"os/epoch.zig"
607-
"os/file.zig"
608619
"os/freebsd.zig"
609-
"os/freebsd/errno.zig"
610-
"os/get_app_data_dir.zig"
611-
"os/get_user_id.zig"
612620
"os/linux.zig"
613621
"os/linux/arm64.zig"
614-
"os/linux/errno.zig"
615622
"os/linux/tls.zig"
616623
"os/linux/vdso.zig"
617624
"os/linux/x86_64.zig"
618625
"os/netbsd.zig"
619-
"os/netbsd/errno.zig"
620-
"os/path.zig"
621-
"os/time.zig"
622626
"os/uefi.zig"
623627
"os/wasi.zig"
624-
"os/wasi/core.zig"
625628
"os/windows.zig"
626629
"os/windows/advapi32.zig"
630+
"os/windows/bits.zig"
627631
"os/windows/error.zig"
628632
"os/windows/kernel32.zig"
629633
"os/windows/ntdll.zig"
630634
"os/windows/ole32.zig"
631635
"os/windows/shell32.zig"
632-
"os/windows/util.zig"
633636
"os/zen.zig"
634637
"packed_int_array.zig"
635638
"pdb.zig"
636639
"priority_queue.zig"
640+
"process.zig"
637641
"rand.zig"
638642
"rand/ziggurat.zig"
639643
"rb.zig"
@@ -645,17 +649,18 @@ set(ZIG_STD_FILES
645649
"special/build_runner.zig"
646650
"special/c.zig"
647651
"special/compiler_rt.zig"
648-
"special/compiler_rt/stack_probe.zig"
649-
"special/compiler_rt/arm/aeabi_fcmp.zig"
650-
"special/compiler_rt/arm/aeabi_dcmp.zig"
651652
"special/compiler_rt/addXf3.zig"
653+
"special/compiler_rt/arm/aeabi_dcmp.zig"
654+
"special/compiler_rt/arm/aeabi_fcmp.zig"
655+
"special/compiler_rt/ashlti3.zig"
656+
"special/compiler_rt/ashrti3.zig"
652657
"special/compiler_rt/aulldiv.zig"
653658
"special/compiler_rt/aullrem.zig"
654-
"special/compiler_rt/comparetf2.zig"
655659
"special/compiler_rt/comparedf2.zig"
656660
"special/compiler_rt/comparesf2.zig"
657-
"special/compiler_rt/divsf3.zig"
661+
"special/compiler_rt/comparetf2.zig"
658662
"special/compiler_rt/divdf3.zig"
663+
"special/compiler_rt/divsf3.zig"
659664
"special/compiler_rt/divti3.zig"
660665
"special/compiler_rt/extendXfYf2.zig"
661666
"special/compiler_rt/fixdfdi.zig"
@@ -680,26 +685,25 @@ set(ZIG_STD_FILES
680685
"special/compiler_rt/fixunstfti.zig"
681686
"special/compiler_rt/floatdidf.zig"
682687
"special/compiler_rt/floatsiXf.zig"
683-
"special/compiler_rt/floatunsidf.zig"
684688
"special/compiler_rt/floattidf.zig"
685689
"special/compiler_rt/floattisf.zig"
686690
"special/compiler_rt/floattitf.zig"
687691
"special/compiler_rt/floatundidf.zig"
688692
"special/compiler_rt/floatunditf.zig"
693+
"special/compiler_rt/floatunsidf.zig"
689694
"special/compiler_rt/floatunsitf.zig"
690695
"special/compiler_rt/floatuntidf.zig"
691696
"special/compiler_rt/floatuntisf.zig"
692697
"special/compiler_rt/floatuntitf.zig"
698+
"special/compiler_rt/lshrti3.zig"
693699
"special/compiler_rt/modti3.zig"
694700
"special/compiler_rt/mulXf3.zig"
695-
"special/compiler_rt/muloti4.zig"
696701
"special/compiler_rt/mulodi4.zig"
702+
"special/compiler_rt/muloti4.zig"
697703
"special/compiler_rt/multi3.zig"
698-
"special/compiler_rt/ashlti3.zig"
699-
"special/compiler_rt/ashrti3.zig"
700-
"special/compiler_rt/lshrti3.zig"
701704
"special/compiler_rt/negXf2.zig"
702705
"special/compiler_rt/popcountdi2.zig"
706+
"special/compiler_rt/stack_probe.zig"
703707
"special/compiler_rt/truncXfYf2.zig"
704708
"special/compiler_rt/udivmod.zig"
705709
"special/compiler_rt/udivmoddi4.zig"
@@ -716,6 +720,9 @@ set(ZIG_STD_FILES
716720
"statically_initialized_mutex.zig"
717721
"std.zig"
718722
"testing.zig"
723+
"thread.zig"
724+
"time.zig"
725+
"time/epoch.zig"
719726
"unicode.zig"
720727
"valgrind.zig"
721728
"valgrind/callgrind.zig"

build.zig

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ const builtin = @import("builtin");
22
const std = @import("std");
33
const Builder = std.build.Builder;
44
const tests = @import("test/tests.zig");
5-
const os = std.os;
65
const BufMap = std.BufMap;
76
const warn = std.debug.warn;
87
const mem = std.mem;
98
const ArrayList = std.ArrayList;
109
const Buffer = std.Buffer;
1110
const io = std.io;
11+
const fs = std.fs;
1212

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

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

18-
const rel_zig_exe = try os.path.relative(b.allocator, b.build_root, b.zig_exe);
19-
const langref_out_path = os.path.join(
18+
const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
19+
const langref_out_path = fs.path.join(
2020
b.allocator,
2121
[][]const u8{ b.cache_root, "langref.html" },
2222
) catch unreachable;
2323
var docgen_cmd = docgen_exe.run();
2424
docgen_cmd.addArgs([][]const u8{
2525
rel_zig_exe,
26-
"doc" ++ os.path.sep_str ++ "langref.html.in",
26+
"doc" ++ fs.path.sep_str ++ "langref.html.in",
2727
langref_out_path,
2828
});
2929
docgen_cmd.step.dependOn(&docgen_exe.step);
@@ -137,7 +137,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
137137
for (dep.libdirs.toSliceConst()) |lib_dir| {
138138
lib_exe_obj.addLibPath(lib_dir);
139139
}
140-
const lib_dir = os.path.join(
140+
const lib_dir = fs.path.join(
141141
b.allocator,
142142
[][]const u8{ dep.prefix, "lib" },
143143
) catch unreachable;
@@ -146,7 +146,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
146146
([]const u8)("libncurses.a")
147147
else
148148
b.fmt("lib{}.a", lib);
149-
const static_lib_name = os.path.join(
149+
const static_lib_name = fs.path.join(
150150
b.allocator,
151151
[][]const u8{ lib_dir, static_bare_name },
152152
) catch unreachable;
@@ -166,18 +166,16 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
166166
}
167167

168168
fn fileExists(filename: []const u8) !bool {
169-
os.File.access(filename) catch |err| switch (err) {
170-
error.PermissionDenied,
171-
error.FileNotFound,
172-
=> return false,
169+
fs.File.access(filename) catch |err| switch (err) {
170+
error.FileNotFound => return false,
173171
else => return err,
174172
};
175173
return true;
176174
}
177175

178176
fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
179177
const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
180-
lib_exe_obj.addObjectFile(os.path.join(b.allocator, [][]const u8{
178+
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [][]const u8{
181179
cmake_binary_dir,
182180
"zig_cpp",
183181
b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()),
@@ -223,7 +221,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
223221
if (mem.startsWith(u8, lib_arg, "-l")) {
224222
try result.system_libs.append(lib_arg[2..]);
225223
} else {
226-
if (os.path.isAbsolute(lib_arg)) {
224+
if (fs.path.isAbsolute(lib_arg)) {
227225
try result.libs.append(lib_arg);
228226
} else {
229227
try result.system_libs.append(lib_arg);
@@ -257,8 +255,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
257255
pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
258256
var it = mem.tokenize(stdlib_files, ";");
259257
while (it.next()) |stdlib_file| {
260-
const src_path = os.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
261-
const dest_path = os.path.join(
258+
const src_path = fs.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
259+
const dest_path = fs.path.join(
262260
b.allocator,
263261
[][]const u8{ "lib", "zig", "std", stdlib_file },
264262
) catch unreachable;
@@ -269,8 +267,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
269267
pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
270268
var it = mem.tokenize(c_header_files, ";");
271269
while (it.next()) |c_header_file| {
272-
const src_path = os.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
273-
const dest_path = os.path.join(
270+
const src_path = fs.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
271+
const dest_path = fs.path.join(
274272
b.allocator,
275273
[][]const u8{ "lib", "zig", "include", c_header_file },
276274
) catch unreachable;
@@ -315,7 +313,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
315313
}
316314
dependOnLib(b, exe, ctx.llvm);
317315

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

0 commit comments

Comments
 (0)