authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-26 13:17:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-26 18:32:44-04:00
log2f040a23c8b968db56ab4c4725d6651f5ea3418e
tree58727a1c2ffdf356db2f5c01e84940e4ced0541f
parent7cb6279ac0cec065234347bda5944be64fe8b3da
signaturelock-open Commit is signed but in an unrecognized format.

clean up references to os


39 files changed, 648 insertions(+), 640 deletions(-)

build.zig+14-14
......@@ -2,28 +2,28 @@ const builtin = @import("builtin");
22const std = @import("std");
33const Builder = std.build.Builder;
44const tests = @import("test/tests.zig");
5const os = std.os;
65const BufMap = std.BufMap;
76const warn = std.debug.warn;
87const mem = std.mem;
98const ArrayList = std.ArrayList;
109const Buffer = std.Buffer;
1110const io = std.io;
11const fs = std.fs;
1212
1313pub 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,7 +166,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
166166}
167167
168168fn fileExists(filename: []const u8) !bool {
169 os.File.access(filename) catch |err| switch (err) {
169 fs.File.access(filename) catch |err| switch (err) {
170170 error.PermissionDenied,
171171 error.FileNotFound,
172172 => return false,
......@@ -177,7 +177,7 @@ fn fileExists(filename: []const u8) !bool {
177177
178178fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
179179 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
180 lib_exe_obj.addObjectFile(os.path.join(b.allocator, [][]const u8{
180 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [][]const u8{
181181 cmake_binary_dir,
182182 "zig_cpp",
183183 b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()),
......@@ -223,7 +223,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
223223 if (mem.startsWith(u8, lib_arg, "-l")) {
224224 try result.system_libs.append(lib_arg[2..]);
225225 } else {
226 if (os.path.isAbsolute(lib_arg)) {
226 if (fs.path.isAbsolute(lib_arg)) {
227227 try result.libs.append(lib_arg);
228228 } else {
229229 try result.system_libs.append(lib_arg);
......@@ -257,8 +257,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
257257pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
258258 var it = mem.tokenize(stdlib_files, ";");
259259 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(
260 const src_path = fs.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
261 const dest_path = fs.path.join(
262262 b.allocator,
263263 [][]const u8{ "lib", "zig", "std", stdlib_file },
264264 ) catch unreachable;
......@@ -269,8 +269,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
269269pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
270270 var it = mem.tokenize(c_header_files, ";");
271271 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(
272 const src_path = fs.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
273 const dest_path = fs.path.join(
274274 b.allocator,
275275 [][]const u8{ "lib", "zig", "include", c_header_file },
276276 ) catch unreachable;
......@@ -315,7 +315,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
315315 }
316316 dependOnLib(b, exe, ctx.llvm);
317317
318 if (exe.target.getOs() == builtin.Os.linux) {
318 if (exe.target.getOs() == .linux) {
319319 try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
320320 \\Unable to determine path to libstdc++.a
321321 \\On Fedora, install libstdc++-static and try again.
doc/docgen.zig+30-28
......@@ -1,7 +1,9 @@
11const builtin = @import("builtin");
22const std = @import("std");
33const io = std.io;
4const os = std.os;
4const fs = std.fs;
5const process = std.process;
6const ChildProcess = std.ChildProcess;
57const warn = std.debug.warn;
68const mem = std.mem;
79const testing = std.testing;
......@@ -11,7 +13,7 @@ const max_doc_file_size = 10 * 1024 * 1024;
1113const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
1214const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
1315const tmp_dir_name = "docgen_tmp";
14const test_out_path = tmp_dir_name ++ os.path.sep_str ++ "test" ++ exe_ext;
16const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
1517
1618pub fn main() !void {
1719 var direct_allocator = std.heap.DirectAllocator.init();
......@@ -22,7 +24,7 @@ pub fn main() !void {
2224
2325 const allocator = &arena.allocator;
2426
25 var args_it = os.args();
27 var args_it = process.args();
2628
2729 if (!args_it.skip()) @panic("expected self arg");
2830
......@@ -35,10 +37,10 @@ pub fn main() !void {
3537 const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg"));
3638 defer allocator.free(out_file_name);
3739
38 var in_file = try os.File.openRead(in_file_name);
40 var in_file = try fs.File.openRead(in_file_name);
3941 defer in_file.close();
4042
41 var out_file = try os.File.openWrite(out_file_name);
43 var out_file = try fs.File.openWrite(out_file_name);
4244 defer out_file.close();
4345
4446 var file_in_stream = in_file.inStream();
......@@ -46,13 +48,13 @@ pub fn main() !void {
4648 const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size);
4749
4850 var file_out_stream = out_file.outStream();
49 var buffered_out_stream = io.BufferedOutStream(os.File.WriteError).init(&file_out_stream.stream);
51 var buffered_out_stream = io.BufferedOutStream(fs.File.WriteError).init(&file_out_stream.stream);
5052
5153 var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
5254 var toc = try genToc(allocator, &tokenizer);
5355
54 try os.makePath(allocator, tmp_dir_name);
55 defer os.deleteTree(allocator, tmp_dir_name) catch {};
56 try fs.makePath(allocator, tmp_dir_name);
57 defer fs.deleteTree(allocator, tmp_dir_name) catch {};
5658
5759 try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream, zig_exe);
5860 try buffered_out_stream.flush();
......@@ -950,7 +952,7 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token)
950952fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
951953 var code_progress_index: usize = 0;
952954
953 var env_map = try os.getEnvMap(allocator);
955 var env_map = try process.getEnvMap(allocator);
954956 try env_map.set("ZIG_DEBUG_COLOR", "1");
955957
956958 const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe);
......@@ -1012,7 +1014,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10121014 try tokenizeAndPrint(tokenizer, out, code.source_token);
10131015 try out.write("</pre>");
10141016 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
1015 const tmp_source_file_name = try os.path.join(
1017 const tmp_source_file_name = try fs.path.join(
10161018 allocator,
10171019 [][]const u8{ tmp_dir_name, name_plus_ext },
10181020 );
......@@ -1021,7 +1023,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10211023 switch (code.id) {
10221024 Code.Id.Exe => |expected_outcome| code_block: {
10231025 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
1024 const tmp_bin_file_name = try os.path.join(
1026 const tmp_bin_file_name = try fs.path.join(
10251027 allocator,
10261028 [][]const u8{ tmp_dir_name, name_plus_bin_ext },
10271029 );
......@@ -1056,7 +1058,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10561058 }
10571059 for (code.link_objects) |link_object| {
10581060 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
1059 const full_path_object = try os.path.join(
1061 const full_path_object = try fs.path.join(
10601062 allocator,
10611063 [][]const u8{ tmp_dir_name, name_with_ext },
10621064 );
......@@ -1076,7 +1078,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10761078 }
10771079 }
10781080 if (expected_outcome == .BuildFail) {
1079 const result = try os.ChildProcess.exec(
1081 const result = try ChildProcess.exec(
10801082 allocator,
10811083 build_args.toSliceConst(),
10821084 null,
......@@ -1084,7 +1086,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10841086 max_doc_file_size,
10851087 );
10861088 switch (result.term) {
1087 os.ChildProcess.Term.Exited => |exit_code| {
1089 .Exited => |exit_code| {
10881090 if (exit_code == 0) {
10891091 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
10901092 for (build_args.toSliceConst()) |arg|
......@@ -1113,7 +1115,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11131115 if (code.target_str) |triple| {
11141116 if (mem.startsWith(u8, triple, "wasm32") or
11151117 mem.startsWith(u8, triple, "x86_64-linux") and
1116 (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64))
1118 (builtin.os != .linux or builtin.arch != .x86_64))
11171119 {
11181120 // skip execution
11191121 try out.print("</code></pre>\n");
......@@ -1124,9 +1126,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11241126 const run_args = [][]const u8{tmp_bin_file_name};
11251127
11261128 const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {
1127 const result = try os.ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
1129 const result = try ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
11281130 switch (result.term) {
1129 os.ChildProcess.Term.Exited => |exit_code| {
1131 .Exited => |exit_code| {
11301132 if (exit_code == 0) {
11311133 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
11321134 for (run_args) |arg|
......@@ -1216,9 +1218,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12161218 try out.print(" --release-small");
12171219 },
12181220 }
1219 const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1221 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
12201222 switch (result.term) {
1221 os.ChildProcess.Term.Exited => |exit_code| {
1223 .Exited => |exit_code| {
12221224 if (exit_code == 0) {
12231225 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
12241226 for (test_args.toSliceConst()) |arg|
......@@ -1274,9 +1276,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12741276 },
12751277 }
12761278
1277 const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1279 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
12781280 switch (result.term) {
1279 os.ChildProcess.Term.Exited => |exit_code| {
1281 .Exited => |exit_code| {
12801282 if (exit_code == 0) {
12811283 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
12821284 for (test_args.toSliceConst()) |arg|
......@@ -1310,7 +1312,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13101312 },
13111313 Code.Id.Obj => |maybe_error_match| {
13121314 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
1313 const tmp_obj_file_name = try os.path.join(
1315 const tmp_obj_file_name = try fs.path.join(
13141316 allocator,
13151317 [][]const u8{ tmp_dir_name, name_plus_obj_ext },
13161318 );
......@@ -1318,7 +1320,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13181320 defer build_args.deinit();
13191321
13201322 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
1321 const output_h_file_name = try os.path.join(
1323 const output_h_file_name = try fs.path.join(
13221324 allocator,
13231325 [][]const u8{ tmp_dir_name, name_plus_h_ext },
13241326 );
......@@ -1367,9 +1369,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13671369 }
13681370
13691371 if (maybe_error_match) |error_match| {
1370 const result = try os.ChildProcess.exec(allocator, build_args.toSliceConst(), null, &env_map, max_doc_file_size);
1372 const result = try ChildProcess.exec(allocator, build_args.toSliceConst(), null, &env_map, max_doc_file_size);
13711373 switch (result.term) {
1372 os.ChildProcess.Term.Exited => |exit_code| {
1374 .Exited => |exit_code| {
13731375 if (exit_code == 0) {
13741376 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
13751377 for (build_args.toSliceConst()) |arg|
......@@ -1448,10 +1450,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14481450 }
14491451}
14501452
1451fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !os.ChildProcess.ExecResult {
1452 const result = try os.ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);
1453fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
1454 const result = try ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);
14531455 switch (result.term) {
1454 os.ChildProcess.Term.Exited => |exit_code| {
1456 .Exited => |exit_code| {
14551457 if (exit_code != 0) {
14561458 warn("{}\nThe following command exited with code {}:\n", result.stderr, exit_code);
14571459 for (args) |arg|
doc/langref.html.in+1-1
......@@ -195,7 +195,7 @@ const std = @import("std");
195195
196196pub fn main() !void {
197197 // If this program is run without stdout attached, exit with an error.
198 const stdout_file = try std.os.File.stdout();
198 const stdout_file = try std.io.getStdOut();
199199 // If this program encounters pipe failure when printing to stdout, exit
200200 // with an error.
201201 try stdout_file.write("Hello, world!\n");
src-self-hosted/compilation.zig+11-12
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const os = std.os;
32const io = std.io;
43const mem = std.mem;
54const Allocator = mem.Allocator;
......@@ -54,7 +53,7 @@ pub const ZigCompiler = struct {
5453 };
5554
5655 var seed_bytes: [@sizeOf(u64)]u8 = undefined;
57 try std.os.getRandomBytes(seed_bytes[0..]);
56 try std.crypto.randomBytes(seed_bytes[0..]);
5857 const seed = mem.readIntNative(u64, &seed_bytes);
5958
6059 return ZigCompiler{
......@@ -487,7 +486,7 @@ pub const Compilation = struct {
487486 comp.name = try Buffer.init(comp.arena(), name);
488487 comp.llvm_triple = try target.getTriple(comp.arena());
489488 comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple);
490 comp.zig_std_dir = try std.os.path.join(comp.arena(), [][]const u8{ zig_lib_dir, "std" });
489 comp.zig_std_dir = try std.fs.path.join(comp.arena(), [][]const u8{ zig_lib_dir, "std" });
491490
492491 const opt_level = switch (build_mode) {
493492 builtin.Mode.Debug => llvm.CodeGenLevelNone,
......@@ -529,8 +528,8 @@ pub const Compilation = struct {
529528 defer comp.events.destroy();
530529
531530 if (root_src_path) |root_src| {
532 const dirname = std.os.path.dirname(root_src) orelse ".";
533 const basename = std.os.path.basename(root_src);
531 const dirname = std.fs.path.dirname(root_src) orelse ".";
532 const basename = std.fs.path.basename(root_src);
534533
535534 comp.root_package = try Package.create(comp.arena(), dirname, basename);
536535 comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");
......@@ -558,7 +557,7 @@ pub const Compilation = struct {
558557
559558 if (comp.tmp_dir.getOrNull()) |tmp_dir_result| if (tmp_dir_result.*) |tmp_dir| {
560559 // TODO evented I/O?
561 os.deleteTree(comp.arena(), tmp_dir) catch {};
560 std.fs.deleteTree(comp.arena(), tmp_dir) catch {};
562561 } else |_| {};
563562 }
564563
......@@ -970,8 +969,8 @@ pub const Compilation = struct {
970969 async fn initialCompile(self: *Compilation) !void {
971970 if (self.root_src_path) |root_src_path| {
972971 const root_scope = blk: {
973 // TODO async/await os.path.real
974 const root_src_real_path = os.path.realAlloc(self.gpa(), root_src_path) catch |err| {
972 // TODO async/await std.fs.realpath
973 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
975974 try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));
976975 return;
977976 };
......@@ -1196,7 +1195,7 @@ pub const Compilation = struct {
11961195 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
11971196 defer self.gpa().free(file_name);
11981197
1199 const full_path = try os.path.join(self.gpa(), [][]const u8{ tmp_dir, file_name[0..] });
1198 const full_path = try std.fs.path.join(self.gpa(), [][]const u8{ tmp_dir, file_name[0..] });
12001199 errdefer self.gpa().free(full_path);
12011200
12021201 return Buffer.fromOwnedSlice(self.gpa(), full_path);
......@@ -1217,8 +1216,8 @@ pub const Compilation = struct {
12171216 const zig_dir_path = try getZigDir(self.gpa());
12181217 defer self.gpa().free(zig_dir_path);
12191218
1220 const tmp_dir = try os.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] });
1221 try os.makePath(self.gpa(), tmp_dir);
1219 const tmp_dir = try std.fs.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] });
1220 try std.fs.makePath(self.gpa(), tmp_dir);
12221221 return tmp_dir;
12231222 }
12241223
......@@ -1384,7 +1383,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {
13841383}
13851384
13861385fn getZigDir(allocator: *mem.Allocator) ![]u8 {
1387 return os.getAppDataDir(allocator, "zig");
1386 return std.fs.getAppDataDir(allocator, "zig");
13881387}
13891388
13901389async fn analyzeFnType(
src-self-hosted/errmsg.zig+5-4
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const mem = std.mem;
3const os = std.os;
3const fs = std.fs;
4const process = std.process;
45const Token = std.zig.Token;
56const ast = std.zig.ast;
67const TokenIndex = std.zig.ast.TokenIndex;
......@@ -239,10 +240,10 @@ pub const Msg = struct {
239240 const allocator = msg.getAllocator();
240241 const tree = msg.getTree();
241242
242 const cwd = try os.getCwdAlloc(allocator);
243 const cwd = try process.getCwdAlloc(allocator);
243244 defer allocator.free(cwd);
244245
245 const relpath = try os.path.relative(allocator, cwd, msg.realpath);
246 const relpath = try fs.path.relative(allocator, cwd, msg.realpath);
246247 defer allocator.free(relpath);
247248
248249 const path = if (relpath.len < msg.realpath.len) relpath else msg.realpath;
......@@ -276,7 +277,7 @@ pub const Msg = struct {
276277 try stream.write("\n");
277278 }
278279
279 pub fn printToFile(msg: *const Msg, file: os.File, color: Color) !void {
280 pub fn printToFile(msg: *const Msg, file: fs.File, color: Color) !void {
280281 const color_on = switch (color) {
281282 Color.Auto => file.isTty(),
282283 Color.On => true,
src-self-hosted/introspect.zig+6-6
......@@ -2,19 +2,19 @@
22
33const std = @import("std");
44const mem = std.mem;
5const os = std.os;
5const fs = std.fs;
66
77const warn = std.debug.warn;
88
99/// Caller must free result
1010pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
11 const test_zig_dir = try os.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
11 const test_zig_dir = try fs.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
1212 errdefer allocator.free(test_zig_dir);
1313
14 const test_index_file = try os.path.join(allocator, [][]const u8{ test_zig_dir, "std", "std.zig" });
14 const test_index_file = try fs.path.join(allocator, [][]const u8{ test_zig_dir, "std", "std.zig" });
1515 defer allocator.free(test_index_file);
1616
17 var file = try os.File.openRead(test_index_file);
17 var file = try fs.File.openRead(test_index_file);
1818 file.close();
1919
2020 return test_zig_dir;
......@@ -22,12 +22,12 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![
2222
2323/// Caller must free result
2424pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {
25 const self_exe_path = try os.selfExeDirPathAlloc(allocator);
25 const self_exe_path = try fs.selfExeDirPathAlloc(allocator);
2626 defer allocator.free(self_exe_path);
2727
2828 var cur_path: []const u8 = self_exe_path;
2929 while (true) {
30 const test_dir = os.path.dirname(cur_path) orelse ".";
30 const test_dir = fs.path.dirname(cur_path) orelse ".";
3131
3232 if (mem.eql(u8, test_dir, cur_path)) {
3333 break;
src-self-hosted/libc_installation.zig+18-17
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const event = std.event;
44const Target = @import("target.zig").Target;
55const c = @import("c.zig");
6const fs = std.fs;
67
78/// See the render function implementation for documentation of the fields.
89pub const LibCInstallation = struct {
......@@ -30,7 +31,7 @@ pub const LibCInstallation = struct {
3031 self: *LibCInstallation,
3132 allocator: *std.mem.Allocator,
3233 libc_file: []const u8,
33 stderr: *std.io.OutStream(std.os.File.WriteError),
34 stderr: *std.io.OutStream(fs.File.WriteError),
3435 ) !void {
3536 self.initEmpty();
3637
......@@ -100,7 +101,7 @@ pub const LibCInstallation = struct {
100101 }
101102 }
102103
103 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(std.os.File.WriteError)) !void {
104 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {
104105 @setEvalBranchQuota(4000);
105106 try out.print(
106107 \\# The directory that contains `stdlib.h`.
......@@ -148,7 +149,7 @@ pub const LibCInstallation = struct {
148149 errdefer if (windows_sdk) |sdk| c.zig_free_windows_sdk(@ptrCast(?[*]c.ZigWindowsSDK, sdk));
149150
150151 switch (builtin.os) {
151 builtin.Os.windows => {
152 .windows => {
152153 var sdk: *c.ZigWindowsSDK = undefined;
153154 switch (c.zig_find_windows_sdk(@ptrCast(?[*]?[*]c.ZigWindowsSDK, &sdk))) {
154155 c.ZigFindWindowsSdkError.None => {
......@@ -166,13 +167,13 @@ pub const LibCInstallation = struct {
166167 c.ZigFindWindowsSdkError.PathTooLong => return error.NotFound,
167168 }
168169 },
169 builtin.Os.linux => {
170 .linux => {
170171 try group.call(findNativeIncludeDirLinux, self, loop);
171172 try group.call(findNativeLibDirLinux, self, loop);
172173 try group.call(findNativeStaticLibDir, self, loop);
173174 try group.call(findNativeDynamicLinker, self, loop);
174175 },
175 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
176 .macosx, .freebsd, .netbsd => {
176177 self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include");
177178 },
178179 else => @compileError("unimplemented: find libc for this OS"),
......@@ -181,7 +182,7 @@ pub const LibCInstallation = struct {
181182 }
182183
183184 async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void {
184 const cc_exe = std.os.getEnvPosix("CC") orelse "cc";
185 const cc_exe = std.process.getEnvPosix("CC") orelse "cc";
185186 const argv = []const []const u8{
186187 cc_exe,
187188 "-E",
......@@ -190,7 +191,7 @@ pub const LibCInstallation = struct {
190191 "/dev/null",
191192 };
192193 // TODO make this use event loop
193 const errorable_result = std.os.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024);
194 const errorable_result = std.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024);
194195 const exec_result = if (std.debug.runtime_safety) blk: {
195196 break :blk errorable_result catch unreachable;
196197 } else blk: {
......@@ -205,7 +206,7 @@ pub const LibCInstallation = struct {
205206 }
206207
207208 switch (exec_result.term) {
208 std.os.ChildProcess.Term.Exited => |code| {
209 std.ChildProcess.Term.Exited => |code| {
209210 if (code != 0) return error.CCompilerExitCode;
210211 },
211212 else => {
......@@ -230,7 +231,7 @@ pub const LibCInstallation = struct {
230231 while (path_i < search_paths.len) : (path_i += 1) {
231232 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
232233 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
233 const stdlib_path = try std.os.path.join(loop.allocator, [][]const u8{ search_path, "stdlib.h" });
234 const stdlib_path = try fs.path.join(loop.allocator, [][]const u8{ search_path, "stdlib.h" });
234235 defer loop.allocator.free(stdlib_path);
235236
236237 if (try fileExists(stdlib_path)) {
......@@ -254,7 +255,7 @@ pub const LibCInstallation = struct {
254255 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
255256 try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);
256257
257 const stdlib_path = try std.os.path.join(
258 const stdlib_path = try fs.path.join(
258259 loop.allocator,
259260 [][]const u8{ result_buf.toSliceConst(), "stdlib.h" },
260261 );
......@@ -286,7 +287,7 @@ pub const LibCInstallation = struct {
286287 builtin.Arch.aarch64 => try stream.write("arm"),
287288 else => return error.UnsupportedArchitecture,
288289 }
289 const ucrt_lib_path = try std.os.path.join(
290 const ucrt_lib_path = try fs.path.join(
290291 loop.allocator,
291292 [][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },
292293 );
......@@ -364,7 +365,7 @@ pub const LibCInstallation = struct {
364365 builtin.Arch.aarch64 => try stream.write("arm\\"),
365366 else => return error.UnsupportedArchitecture,
366367 }
367 const kernel32_path = try std.os.path.join(
368 const kernel32_path = try fs.path.join(
368369 loop.allocator,
369370 [][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },
370371 );
......@@ -391,14 +392,14 @@ pub const LibCInstallation = struct {
391392
392393/// caller owns returned memory
393394async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bool) ![]u8 {
394 const cc_exe = std.os.getEnvPosix("CC") orelse "cc";
395 const cc_exe = std.process.getEnvPosix("CC") orelse "cc";
395396 const arg1 = try std.fmt.allocPrint(loop.allocator, "-print-file-name={}", o_file);
396397 defer loop.allocator.free(arg1);
397398 const argv = []const []const u8{ cc_exe, arg1 };
398399
399400 // TODO This simulates evented I/O for the child process exec
400401 await (async loop.yield() catch unreachable);
401 const errorable_result = std.os.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024);
402 const errorable_result = std.ChildProcess.exec(loop.allocator, argv, null, null, 1024 * 1024);
402403 const exec_result = if (std.debug.runtime_safety) blk: {
403404 break :blk errorable_result catch unreachable;
404405 } else blk: {
......@@ -412,7 +413,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
412413 loop.allocator.free(exec_result.stderr);
413414 }
414415 switch (exec_result.term) {
415 std.os.ChildProcess.Term.Exited => |code| {
416 .Exited => |code| {
416417 if (code != 0) return error.CCompilerExitCode;
417418 },
418419 else => {
......@@ -421,7 +422,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
421422 }
422423 var it = std.mem.tokenize(exec_result.stdout, "\n\r");
423424 const line = it.next() orelse return error.LibCRuntimeNotFound;
424 const dirname = std.os.path.dirname(line) orelse return error.LibCRuntimeNotFound;
425 const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound;
425426
426427 if (want_dirname) {
427428 return std.mem.dupe(loop.allocator, u8, dirname);
......@@ -459,7 +460,7 @@ fn fillSearch(search_buf: *[2]Search, sdk: *c.ZigWindowsSDK) []Search {
459460}
460461
461462fn fileExists(path: []const u8) !bool {
462 if (std.os.File.access(path)) |_| {
463 if (fs.File.access(path)) |_| {
463464 return true;
464465 } else |err| switch (err) {
465466 error.FileNotFound, error.PermissionDenied => return false,
src-self-hosted/link.zig+3-3
......@@ -302,7 +302,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
302302 try ctx.args.append(c"--allow-shlib-undefined");
303303 }
304304
305 if (ctx.comp.target.getOs() == builtin.Os.zen) {
305 if (ctx.comp.target.getOs() == .zen) {
306306 try ctx.args.append(c"-e");
307307 try ctx.args.append(c"_start");
308308
......@@ -311,7 +311,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
311311}
312312
313313fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
314 const full_path = try std.os.path.join(&ctx.arena.allocator, [][]const u8{ dirname, basename });
314 const full_path = try std.fs.path.join(&ctx.arena.allocator, [][]const u8{ dirname, basename });
315315 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
316316 try ctx.args.append(full_path_with_null.ptr);
317317}
......@@ -668,7 +668,7 @@ const DarwinPlatform = struct {
668668 break :blk ver;
669669 },
670670 Compilation.DarwinVersionMin.None => blk: {
671 assert(comp.target.getOs() == builtin.Os.macosx);
671 assert(comp.target.getOs() == .macosx);
672672 result.kind = Kind.MacOS;
673673 break :blk "10.10";
674674 },
src-self-hosted/main.zig+41-39
......@@ -4,7 +4,9 @@ const builtin = @import("builtin");
44const event = std.event;
55const os = std.os;
66const io = std.io;
7const fs = std.fs;
78const mem = std.mem;
9const process = std.process;
810const Allocator = mem.Allocator;
911const ArrayList = std.ArrayList;
1012const Buffer = std.Buffer;
......@@ -20,9 +22,9 @@ const Target = @import("target.zig").Target;
2022const errmsg = @import("errmsg.zig");
2123const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
2224
23var stderr_file: os.File = undefined;
24var stderr: *io.OutStream(os.File.WriteError) = undefined;
25var stdout: *io.OutStream(os.File.WriteError) = undefined;
25var stderr_file: fs.File = undefined;
26var stderr: *io.OutStream(fs.File.WriteError) = undefined;
27var stdout: *io.OutStream(fs.File.WriteError) = undefined;
2628
2729pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB
2830
......@@ -62,14 +64,14 @@ pub fn main() !void {
6264 var stderr_out_stream = stderr_file.outStream();
6365 stderr = &stderr_out_stream.stream;
6466
65 const args = try os.argsAlloc(allocator);
67 const args = try process.argsAlloc(allocator);
6668 // TODO I'm getting unreachable code here, which shouldn't happen
67 //defer os.argsFree(allocator, args);
69 //defer process.argsFree(allocator, args);
6870
6971 if (args.len <= 1) {
7072 try stderr.write("expected command argument\n\n");
7173 try stderr.write(usage);
72 os.exit(1);
74 process.exit(1);
7375 }
7476
7577 const commands = []Command{
......@@ -125,7 +127,7 @@ pub fn main() !void {
125127
126128 try stderr.print("unknown command: {}\n\n", args[1]);
127129 try stderr.write(usage);
128 os.exit(1);
130 process.exit(1);
129131}
130132
131133const usage_build_generic =
......@@ -256,7 +258,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
256258
257259 if (flags.present("help")) {
258260 try stdout.write(usage_build_generic);
259 os.exit(0);
261 process.exit(0);
260262 }
261263
262264 const build_mode = blk: {
......@@ -324,14 +326,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
324326 cur_pkg = parent;
325327 } else {
326328 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");
327 os.exit(1);
329 process.exit(1);
328330 }
329331 }
330332 }
331333
332334 if (cur_pkg.parent != null) {
333335 try stderr.print("unmatched --pkg-begin\n");
334 os.exit(1);
336 process.exit(1);
335337 }
336338
337339 const provided_name = flags.single("name");
......@@ -340,18 +342,18 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
340342 1 => flags.positionals.at(0),
341343 else => {
342344 try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));
343 os.exit(1);
345 process.exit(1);
344346 },
345347 };
346348
347349 const root_name = if (provided_name) |n| n else blk: {
348350 if (root_source_file) |file| {
349 const basename = os.path.basename(file);
351 const basename = fs.path.basename(file);
350352 var it = mem.separate(basename, ".");
351353 break :blk it.next() orelse basename;
352354 } else {
353355 try stderr.write("--name [name] not provided and unable to infer\n");
354 os.exit(1);
356 process.exit(1);
355357 }
356358 };
357359
......@@ -361,12 +363,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
361363 const link_objects = flags.many("object");
362364 if (root_source_file == null and link_objects.len == 0 and assembly_files.len == 0) {
363365 try stderr.write("Expected source file argument or at least one --object or --assembly argument\n");
364 os.exit(1);
366 process.exit(1);
365367 }
366368
367369 if (out_type == Compilation.Kind.Obj and link_objects.len != 0) {
368370 try stderr.write("When building an object file, --object arguments are invalid\n");
369 os.exit(1);
371 process.exit(1);
370372 }
371373
372374 var clang_argv_buf = ArrayList([]const u8).init(allocator);
......@@ -379,7 +381,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
379381 }
380382 try ZigCompiler.setLlvmArgv(allocator, mllvm_flags);
381383
382 const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch os.exit(1);
384 const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch process.exit(1);
383385 defer allocator.free(zig_lib_dir);
384386
385387 var override_libc: LibCInstallation = undefined;
......@@ -448,7 +450,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
448450
449451 if (flags.single("mmacosx-version-min") != null and flags.single("mios-version-min") != null) {
450452 try stderr.write("-mmacosx-version-min and -mios-version-min options not allowed together\n");
451 os.exit(1);
453 process.exit(1);
452454 }
453455
454456 if (flags.single("mmacosx-version-min")) |ver| {
......@@ -478,16 +480,16 @@ async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
478480
479481 switch (build_event) {
480482 Compilation.Event.Ok => {
481 stderr.print("Build {} succeeded\n", count) catch os.exit(1);
483 stderr.print("Build {} succeeded\n", count) catch process.exit(1);
482484 },
483485 Compilation.Event.Error => |err| {
484 stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch os.exit(1);
486 stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch process.exit(1);
485487 },
486488 Compilation.Event.Fail => |msgs| {
487 stderr.print("Build {} compile errors:\n", count) catch os.exit(1);
489 stderr.print("Build {} compile errors:\n", count) catch process.exit(1);
488490 for (msgs) |msg| {
489491 defer msg.destroy();
490 msg.printToFile(stderr_file, color) catch os.exit(1);
492 msg.printToFile(stderr_file, color) catch process.exit(1);
491493 }
492494 },
493495 }
......@@ -550,8 +552,8 @@ fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_fil
550552 "Try running `zig libc` to see an example for the native target.\n",
551553 libc_paths_file,
552554 @errorName(err),
553 ) catch os.exit(1);
554 os.exit(1);
555 ) catch process.exit(1);
556 process.exit(1);
555557 };
556558}
557559
......@@ -565,7 +567,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
565567 },
566568 else => {
567569 try stderr.print("unexpected extra parameter: {}\n", args[1]);
568 os.exit(1);
570 process.exit(1);
569571 },
570572 }
571573
......@@ -584,10 +586,10 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
584586
585587async fn findLibCAsync(zig_compiler: *ZigCompiler) void {
586588 const libc = (await (async zig_compiler.getNativeLibC() catch unreachable)) catch |err| {
587 stderr.print("unable to find libc: {}\n", @errorName(err)) catch os.exit(1);
588 os.exit(1);
589 stderr.print("unable to find libc: {}\n", @errorName(err)) catch process.exit(1);
590 process.exit(1);
589591 };
590 libc.render(stdout) catch os.exit(1);
592 libc.render(stdout) catch process.exit(1);
591593}
592594
593595fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
......@@ -596,7 +598,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
596598
597599 if (flags.present("help")) {
598600 try stdout.write(usage_fmt);
599 os.exit(0);
601 process.exit(0);
600602 }
601603
602604 const color = blk: {
......@@ -616,7 +618,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
616618 if (flags.present("stdin")) {
617619 if (flags.positionals.len != 0) {
618620 try stderr.write("cannot use --stdin with positional arguments\n");
619 os.exit(1);
621 process.exit(1);
620622 }
621623
622624 var stdin_file = try io.getStdIn();
......@@ -627,7 +629,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
627629
628630 const tree = std.zig.parse(allocator, source_code) catch |err| {
629631 try stderr.print("error parsing stdin: {}\n", err);
630 os.exit(1);
632 process.exit(1);
631633 };
632634 defer tree.deinit();
633635
......@@ -639,12 +641,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
639641 try msg.printToFile(stderr_file, color);
640642 }
641643 if (tree.errors.len != 0) {
642 os.exit(1);
644 process.exit(1);
643645 }
644646 if (flags.present("check")) {
645647 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
646648 const code = if (anything_changed) u8(1) else u8(0);
647 os.exit(code);
649 process.exit(code);
648650 }
649651
650652 _ = try std.zig.render(allocator, stdout, tree);
......@@ -653,7 +655,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
653655
654656 if (flags.positionals.len == 0) {
655657 try stderr.write("expected at least one source file argument\n");
656 os.exit(1);
658 process.exit(1);
657659 }
658660
659661 var loop: event.Loop = undefined;
......@@ -700,7 +702,7 @@ const FmtError = error{
700702 ReadOnlyFileSystem,
701703 LinkQuotaExceeded,
702704 FileBusy,
703} || os.File.OpenError;
705} || fs.File.OpenError;
704706
705707async fn asyncFmtMain(
706708 loop: *event.Loop,
......@@ -725,7 +727,7 @@ async fn asyncFmtMain(
725727 }
726728 try await (async group.wait() catch unreachable);
727729 if (fmt.any_error) {
728 os.exit(1);
730 process.exit(1);
729731 }
730732}
731733
......@@ -747,13 +749,13 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
747749 )) catch |err| switch (err) {
748750 error.IsDir, error.AccessDenied => {
749751 // TODO make event based (and dir.next())
750 var dir = try std.os.Dir.open(fmt.loop.allocator, file_path);
752 var dir = try fs.Dir.open(fmt.loop.allocator, file_path);
751753 defer dir.close();
752754
753755 var group = event.Group(FmtError!void).init(fmt.loop);
754756 while (try dir.next()) |entry| {
755 if (entry.kind == std.os.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
756 const full_path = try os.path.join(fmt.loop.allocator, [][]const u8{ file_path, entry.name });
757 if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
758 const full_path = try fs.path.join(fmt.loop.allocator, [][]const u8{ file_path, entry.name });
757759 try group.call(fmtPath, fmt, full_path, check_mode);
758760 }
759761 }
......@@ -891,7 +893,7 @@ const usage_internal =
891893fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
892894 if (args.len == 0) {
893895 try stderr.write(usage_internal);
894 os.exit(1);
896 process.exit(1);
895897 }
896898
897899 const sub_commands = []Command{Command{
src-self-hosted/stage1.zig+29-30
......@@ -1,8 +1,24 @@
11// This is Zig code that is used by both stage1 and stage2.
22// The prototypes in src/userland.h must match these definitions.
33
4const std = @import("std");
54const builtin = @import("builtin");
5const std = @import("std");
6const io = std.io;
7const mem = std.mem;
8const fs = std.fs;
9const process = std.process;
10const Allocator = mem.Allocator;
11const ArrayList = std.ArrayList;
12const Buffer = std.Buffer;
13const arg = @import("arg.zig");
14const self_hosted_main = @import("main.zig");
15const Args = arg.Args;
16const Flag = arg.Flag;
17const errmsg = @import("errmsg.zig");
18
19var stderr_file: fs.File = undefined;
20var stderr: *io.OutStream(fs.File.WriteError) = undefined;
21var stdout: *io.OutStream(fs.File.WriteError) = undefined;
622
723// ABI warning
824export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {
......@@ -157,7 +173,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
157173
158174 if (flags.present("help")) {
159175 try stdout.write(self_hosted_main.usage_fmt);
160 os.exit(0);
176 process.exit(0);
161177 }
162178
163179 const color = blk: {
......@@ -177,7 +193,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
177193 if (flags.present("stdin")) {
178194 if (flags.positionals.len != 0) {
179195 try stderr.write("cannot use --stdin with positional arguments\n");
180 os.exit(1);
196 process.exit(1);
181197 }
182198
183199 var stdin_file = try io.getStdIn();
......@@ -188,7 +204,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
188204
189205 const tree = std.zig.parse(allocator, source_code) catch |err| {
190206 try stderr.print("error parsing stdin: {}\n", err);
191 os.exit(1);
207 process.exit(1);
192208 };
193209 defer tree.deinit();
194210
......@@ -197,12 +213,12 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
197213 try printErrMsgToFile(allocator, parse_error, tree, "<stdin>", stderr_file, color);
198214 }
199215 if (tree.errors.len != 0) {
200 os.exit(1);
216 process.exit(1);
201217 }
202218 if (flags.present("check")) {
203219 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
204220 const code = if (anything_changed) u8(1) else u8(0);
205 os.exit(code);
221 process.exit(code);
206222 }
207223
208224 _ = try std.zig.render(allocator, stdout, tree);
......@@ -211,7 +227,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
211227
212228 if (flags.positionals.len == 0) {
213229 try stderr.write("expected at least one source file argument\n");
214 os.exit(1);
230 process.exit(1);
215231 }
216232
217233 var fmt = Fmt{
......@@ -227,7 +243,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
227243 try fmtPath(&fmt, file_path, check_mode);
228244 }
229245 if (fmt.any_error) {
230 os.exit(1);
246 process.exit(1);
231247 }
232248}
233249
......@@ -250,7 +266,7 @@ const FmtError = error{
250266 ReadOnlyFileSystem,
251267 LinkQuotaExceeded,
252268 FileBusy,
253} || os.File.OpenError;
269} || fs.File.OpenError;
254270
255271fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {
256272 const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref);
......@@ -261,12 +277,12 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
261277 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
262278 error.IsDir, error.AccessDenied => {
263279 // TODO make event based (and dir.next())
264 var dir = try std.os.Dir.open(fmt.allocator, file_path);
280 var dir = try fs.Dir.open(fmt.allocator, file_path);
265281 defer dir.close();
266282
267283 while (try dir.next()) |entry| {
268 if (entry.kind == std.os.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
269 const full_path = try os.path.join(fmt.allocator, [][]const u8{ file_path, entry.name });
284 if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
285 const full_path = try fs.path.join(fmt.allocator, [][]const u8{ file_path, entry.name });
270286 try fmtPath(fmt, full_path, check_mode);
271287 }
272288 }
......@@ -329,7 +345,7 @@ fn printErrMsgToFile(
329345 parse_error: *const ast.Error,
330346 tree: *ast.Tree,
331347 path: []const u8,
332 file: os.File,
348 file: fs.File,
333349 color: errmsg.Color,
334350) !void {
335351 const color_on = switch (color) {
......@@ -377,20 +393,3 @@ fn printErrMsgToFile(
377393 try stream.writeByteNTimes('~', last_token.end - first_token.start);
378394 try stream.write("\n");
379395}
380
381const os = std.os;
382const io = std.io;
383const mem = std.mem;
384const Allocator = mem.Allocator;
385const ArrayList = std.ArrayList;
386const Buffer = std.Buffer;
387
388const arg = @import("arg.zig");
389const self_hosted_main = @import("main.zig");
390const Args = arg.Args;
391const Flag = arg.Flag;
392const errmsg = @import("errmsg.zig");
393
394var stderr_file: os.File = undefined;
395var stderr: *io.OutStream(os.File.WriteError) = undefined;
396var stdout: *io.OutStream(os.File.WriteError) = undefined;
src-self-hosted/test.zig+11-11
......@@ -55,12 +55,12 @@ pub const TestContext = struct {
5555 self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);
5656 errdefer allocator.free(self.zig_lib_dir);
5757
58 try std.os.makePath(allocator, tmp_dir_name);
59 errdefer std.os.deleteTree(allocator, tmp_dir_name) catch {};
58 try std.fs.makePath(allocator, tmp_dir_name);
59 errdefer std.fs.deleteTree(allocator, tmp_dir_name) catch {};
6060 }
6161
6262 fn deinit(self: *TestContext) void {
63 std.os.deleteTree(allocator, tmp_dir_name) catch {};
63 std.fs.deleteTree(allocator, tmp_dir_name) catch {};
6464 allocator.free(self.zig_lib_dir);
6565 self.zig_compiler.deinit();
6666 self.loop.deinit();
......@@ -87,10 +87,10 @@ pub const TestContext = struct {
8787 ) !void {
8888 var file_index_buf: [20]u8 = undefined;
8989 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr());
90 const file1_path = try std.os.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 });
90 const file1_path = try std.fs.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 });
9191
92 if (std.os.path.dirname(file1_path)) |dirname| {
93 try std.os.makePath(allocator, dirname);
92 if (std.fs.path.dirname(file1_path)) |dirname| {
93 try std.fs.makePath(allocator, dirname);
9494 }
9595
9696 // TODO async I/O
......@@ -120,11 +120,11 @@ pub const TestContext = struct {
120120 ) !void {
121121 var file_index_buf: [20]u8 = undefined;
122122 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr());
123 const file1_path = try std.os.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 });
123 const file1_path = try std.fs.path.join(allocator, [][]const u8{ tmp_dir_name, file_index, file1 });
124124
125125 const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, Target(Target.Native).exeFileExt());
126 if (std.os.path.dirname(file1_path)) |dirname| {
127 try std.os.makePath(allocator, dirname);
126 if (std.fs.path.dirname(file1_path)) |dirname| {
127 try std.fs.makePath(allocator, dirname);
128128 }
129129
130130 // TODO async I/O
......@@ -164,9 +164,9 @@ pub const TestContext = struct {
164164 Compilation.Event.Ok => {
165165 const argv = []const []const u8{exe_file_2};
166166 // TODO use event loop
167 const child = try std.os.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024);
167 const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024);
168168 switch (child.term) {
169 std.os.ChildProcess.Term.Exited => |code| {
169 .Exited => |code| {
170170 if (code != 0) {
171171 return error.BadReturnCode;
172172 }
std/buffer.zig+1-3
......@@ -139,15 +139,13 @@ pub const Buffer = struct {
139139};
140140
141141test "simple Buffer" {
142 const cstr = @import("cstr.zig");
143
144142 var buf = try Buffer.init(debug.global_allocator, "");
145143 testing.expect(buf.len() == 0);
146144 try buf.append("hello");
147145 try buf.append(" ");
148146 try buf.append("world");
149147 testing.expect(buf.eql("hello world"));
150 testing.expect(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
148 testing.expect(mem.eql(u8, mem.toSliceConst(u8, buf.toSliceConst().ptr), buf.toSliceConst()));
151149
152150 var buf2 = try Buffer.initFromBuffer(buf);
153151 testing.expect(buf.eql(buf2.toSliceConst()));
std/build.zig+82-83
......@@ -1,6 +1,7 @@
11const std = @import("std.zig");
22const builtin = @import("builtin");
33const io = std.io;
4const fs = std.fs;
45const mem = std.mem;
56const debug = std.debug;
67const assert = debug.assert;
......@@ -8,9 +9,7 @@ const warn = std.debug.warn;
89const ArrayList = std.ArrayList;
910const HashMap = std.HashMap;
1011const Allocator = mem.Allocator;
11const os = std.os;
12const StdIo = os.ChildProcess.StdIo;
13const Term = os.ChildProcess.Term;
12const process = std.process;
1413const BufSet = std.BufSet;
1514const BufMap = std.BufMap;
1615const fmt_lib = std.fmt;
......@@ -96,11 +95,11 @@ pub const Builder = struct {
9695
9796 pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {
9897 const env_map = allocator.create(BufMap) catch unreachable;
99 env_map.* = os.getEnvMap(allocator) catch unreachable;
98 env_map.* = process.getEnvMap(allocator) catch unreachable;
10099 var self = Builder{
101100 .zig_exe = zig_exe,
102101 .build_root = build_root,
103 .cache_root = os.path.relative(allocator, build_root, cache_root) catch unreachable,
102 .cache_root = fs.path.relative(allocator, build_root, cache_root) catch unreachable,
104103 .verbose = false,
105104 .verbose_tokenize = false,
106105 .verbose_ast = false,
......@@ -154,8 +153,8 @@ pub const Builder = struct {
154153
155154 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
156155 self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default
157 self.lib_dir = os.path.join(self.allocator, [][]const u8{ self.prefix, "lib" }) catch unreachable;
158 self.exe_dir = os.path.join(self.allocator, [][]const u8{ self.prefix, "bin" }) catch unreachable;
156 self.lib_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "lib" }) catch unreachable;
157 self.exe_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "bin" }) catch unreachable;
159158 }
160159
161160 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -287,7 +286,7 @@ pub const Builder = struct {
287286 if (self.verbose) {
288287 warn("rm {}\n", installed_file);
289288 }
290 os.deleteFile(installed_file) catch {};
289 fs.deleteFile(installed_file) catch {};
291290 }
292291
293292 // TODO remove empty directories
......@@ -326,7 +325,7 @@ pub const Builder = struct {
326325
327326 fn detectNativeSystemPaths(self: *Builder) void {
328327 var is_nixos = false;
329 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
328 if (process.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
330329 is_nixos = true;
331330 var it = mem.tokenize(nix_cflags_compile, " ");
332331 while (true) {
......@@ -345,7 +344,7 @@ pub const Builder = struct {
345344 } else |err| {
346345 assert(err == error.EnvironmentVariableNotFound);
347346 }
348 if (os.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {
347 if (process.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {
349348 is_nixos = true;
350349 var it = mem.tokenize(nix_ldflags, " ");
351350 while (true) {
......@@ -369,7 +368,7 @@ pub const Builder = struct {
369368 }
370369 if (is_nixos) return;
371370 switch (builtin.os) {
372 builtin.Os.windows => {},
371 .windows => {},
373372 else => {
374373 const triple = (CrossTarget{
375374 .arch = builtin.arch,
......@@ -602,7 +601,7 @@ pub const Builder = struct {
602601 printCmd(cwd, argv);
603602 }
604603
605 const child = os.ChildProcess.init(argv, self.allocator) catch unreachable;
604 const child = std.ChildProcess.init(argv, self.allocator) catch unreachable;
606605 defer child.deinit();
607606
608607 child.cwd = cwd;
......@@ -614,7 +613,7 @@ pub const Builder = struct {
614613 };
615614
616615 switch (term) {
617 Term.Exited => |code| {
616 .Exited => |code| {
618617 if (code != 0) {
619618 warn("The following command exited with error code {}:\n", code);
620619 printCmd(cwd, argv);
......@@ -631,7 +630,7 @@ pub const Builder = struct {
631630 }
632631
633632 pub fn makePath(self: *Builder, path: []const u8) !void {
634 os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
633 fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
635634 warn("Unable to create path {}: {}\n", path, @errorName(err));
636635 return err;
637636 };
......@@ -652,7 +651,7 @@ pub const Builder = struct {
652651
653652 ///::dest_rel_path is relative to prefix path or it can be an absolute path
654653 pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
655 const full_dest_path = os.path.resolve(
654 const full_dest_path = fs.path.resolve(
656655 self.allocator,
657656 [][]const u8{ self.prefix, dest_rel_path },
658657 ) catch unreachable;
......@@ -677,20 +676,20 @@ pub const Builder = struct {
677676 warn("cp {} {}\n", source_path, dest_path);
678677 }
679678
680 const dirname = os.path.dirname(dest_path) orelse ".";
679 const dirname = fs.path.dirname(dest_path) orelse ".";
681680 const abs_source_path = self.pathFromRoot(source_path);
682 os.makePath(self.allocator, dirname) catch |err| {
681 fs.makePath(self.allocator, dirname) catch |err| {
683682 warn("Unable to create path {}: {}\n", dirname, @errorName(err));
684683 return err;
685684 };
686 os.copyFileMode(abs_source_path, dest_path, mode) catch |err| {
685 fs.copyFileMode(abs_source_path, dest_path, mode) catch |err| {
687686 warn("Unable to copy {} to {}: {}\n", abs_source_path, dest_path, @errorName(err));
688687 return err;
689688 };
690689 }
691690
692691 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
693 return os.path.resolve(self.allocator, [][]const u8{ self.build_root, rel_path }) catch unreachable;
692 return fs.path.resolve(self.allocator, [][]const u8{ self.build_root, rel_path }) catch unreachable;
694693 }
695694
696695 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
......@@ -702,11 +701,11 @@ pub const Builder = struct {
702701 const exe_extension = (Target{ .Native = {} }).exeFileExt();
703702 for (self.search_prefixes.toSliceConst()) |search_prefix| {
704703 for (names) |name| {
705 if (os.path.isAbsolute(name)) {
704 if (fs.path.isAbsolute(name)) {
706705 return name;
707706 }
708 const full_path = try os.path.join(self.allocator, [][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
709 if (os.path.real(self.allocator, full_path)) |real_path| {
707 const full_path = try fs.path.join(self.allocator, [][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
708 if (fs.path.real(self.allocator, full_path)) |real_path| {
710709 return real_path;
711710 } else |_| {
712711 continue;
......@@ -715,13 +714,13 @@ pub const Builder = struct {
715714 }
716715 if (self.env_map.get("PATH")) |PATH| {
717716 for (names) |name| {
718 if (os.path.isAbsolute(name)) {
717 if (fs.path.isAbsolute(name)) {
719718 return name;
720719 }
721 var it = mem.tokenize(PATH, []u8{os.path.delimiter});
720 var it = mem.tokenize(PATH, []u8{fs.path.delimiter});
722721 while (it.next()) |path| {
723 const full_path = try os.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
724 if (os.path.real(self.allocator, full_path)) |real_path| {
722 const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
723 if (fs.path.real(self.allocator, full_path)) |real_path| {
725724 return real_path;
726725 } else |_| {
727726 continue;
......@@ -730,12 +729,12 @@ pub const Builder = struct {
730729 }
731730 }
732731 for (names) |name| {
733 if (os.path.isAbsolute(name)) {
732 if (fs.path.isAbsolute(name)) {
734733 return name;
735734 }
736735 for (paths) |path| {
737 const full_path = try os.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
738 if (os.path.real(self.allocator, full_path)) |real_path| {
736 const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
737 if (fs.path.real(self.allocator, full_path)) |real_path| {
739738 return real_path;
740739 } else |_| {
741740 continue;
......@@ -749,12 +748,12 @@ pub const Builder = struct {
749748 assert(argv.len != 0);
750749
751750 const max_output_size = 100 * 1024;
752 const child = try os.ChildProcess.init(argv, self.allocator);
751 const child = try std.ChildProcess.init(argv, self.allocator);
753752 defer child.deinit();
754753
755 child.stdin_behavior = os.ChildProcess.StdIo.Ignore;
756 child.stdout_behavior = os.ChildProcess.StdIo.Pipe;
757 child.stderr_behavior = os.ChildProcess.StdIo.Inherit;
754 child.stdin_behavior = .Ignore;
755 child.stdout_behavior = .Pipe;
756 child.stderr_behavior = .Inherit;
758757
759758 try child.spawn();
760759
......@@ -766,7 +765,7 @@ pub const Builder = struct {
766765
767766 const term = child.wait() catch |err| std.debug.panic("unable to spawn {}: {}", argv[0], err);
768767 switch (term) {
769 os.ChildProcess.Term.Exited => |code| {
768 .Exited => |code| {
770769 if (code != 0) {
771770 warn("The following command exited with error code {}:\n", code);
772771 printCmd(null, argv);
......@@ -846,7 +845,7 @@ pub const Target = union(enum) {
846845 }
847846 }
848847
849 pub fn oFileExt(self: *const Target) []const u8 {
848 pub fn oFileExt(self: Target) []const u8 {
850849 const abi = switch (self.*) {
851850 Target.Native => builtin.abi,
852851 Target.Cross => |t| t.abi,
......@@ -857,49 +856,49 @@ pub const Target = union(enum) {
857856 };
858857 }
859858
860 pub fn exeFileExt(self: *const Target) []const u8 {
859 pub fn exeFileExt(self: Target) []const u8 {
861860 return switch (self.getOs()) {
862 builtin.Os.windows => ".exe",
861 .windows => ".exe",
863862 else => "",
864863 };
865864 }
866865
867 pub fn libFileExt(self: *const Target) []const u8 {
866 pub fn libFileExt(self: Target) []const u8 {
868867 return switch (self.getOs()) {
869 builtin.Os.windows => ".lib",
868 .windows => ".lib",
870869 else => ".a",
871870 };
872871 }
873872
874 pub fn getOs(self: *const Target) builtin.Os {
875 return switch (self.*) {
873 pub fn getOs(self: Target) builtin.Os {
874 return switch (self) {
876875 Target.Native => builtin.os,
877876 Target.Cross => |t| t.os,
878877 };
879878 }
880879
881 pub fn isDarwin(self: *const Target) bool {
880 pub fn isDarwin(self: Target) bool {
882881 return switch (self.getOs()) {
883 builtin.Os.ios, builtin.Os.macosx => true,
882 .ios, .macosx, .watchos, .tvos => true,
884883 else => false,
885884 };
886885 }
887886
888 pub fn isWindows(self: *const Target) bool {
887 pub fn isWindows(self: Target) bool {
889888 return switch (self.getOs()) {
890 builtin.Os.windows => true,
889 .windows => true,
891890 else => false,
892891 };
893892 }
894893
895 pub fn isFreeBSD(self: *const Target) bool {
894 pub fn isFreeBSD(self: Target) bool {
896895 return switch (self.getOs()) {
897 builtin.Os.freebsd => true,
896 .freebsd => true,
898897 else => false,
899898 };
900899 }
901900
902 pub fn wantSharedLibSymLinks(self: *const Target) bool {
901 pub fn wantSharedLibSymLinks(self: Target) bool {
903902 return !self.isWindows();
904903 }
905904};
......@@ -1065,19 +1064,19 @@ pub const LibExeObjStep = struct {
10651064
10661065 fn computeOutFileNames(self: *LibExeObjStep) void {
10671066 switch (self.kind) {
1068 Kind.Obj => {
1067 .Obj => {
10691068 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
10701069 },
1071 Kind.Exe => {
1070 .Exe => {
10721071 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
10731072 },
1074 Kind.Test => {
1073 .Test => {
10751074 self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());
10761075 },
1077 Kind.Lib => {
1076 .Lib => {
10781077 if (!self.is_dynamic) {
10791078 switch (self.target.getOs()) {
1080 builtin.Os.windows => {
1079 .windows => {
10811080 self.out_filename = self.builder.fmt("{}.lib", self.name);
10821081 },
10831082 else => {
......@@ -1087,13 +1086,13 @@ pub const LibExeObjStep = struct {
10871086 self.out_lib_filename = self.out_filename;
10881087 } else {
10891088 switch (self.target.getOs()) {
1090 builtin.Os.ios, builtin.Os.macosx => {
1089 .ios, .macosx => {
10911090 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);
10921091 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);
10931092 self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);
10941093 self.out_lib_filename = self.out_filename;
10951094 },
1096 builtin.Os.windows => {
1095 .windows => {
10971096 self.out_filename = self.builder.fmt("{}.dll", self.name);
10981097 self.out_lib_filename = self.builder.fmt("{}.lib", self.name);
10991098 },
......@@ -1228,7 +1227,7 @@ pub const LibExeObjStep = struct {
12281227 /// the make step, from a step that has declared a dependency on this one.
12291228 /// To run an executable built with zig build, use `run`, or create an install step and invoke it.
12301229 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1231 return os.path.join(
1230 return fs.path.join(
12321231 self.builder.allocator,
12331232 [][]const u8{ self.output_dir.?, self.out_filename },
12341233 ) catch unreachable;
......@@ -1238,7 +1237,7 @@ pub const LibExeObjStep = struct {
12381237 /// the make step, from a step that has declared a dependency on this one.
12391238 pub fn getOutputLibPath(self: *LibExeObjStep) []const u8 {
12401239 assert(self.kind == Kind.Lib);
1241 return os.path.join(
1240 return fs.path.join(
12421241 self.builder.allocator,
12431242 [][]const u8{ self.output_dir.?, self.out_lib_filename },
12441243 ) catch unreachable;
......@@ -1249,7 +1248,7 @@ pub const LibExeObjStep = struct {
12491248 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
12501249 assert(self.kind != Kind.Exe);
12511250 assert(!self.disable_gen_h);
1252 return os.path.join(
1251 return fs.path.join(
12531252 self.builder.allocator,
12541253 [][]const u8{ self.output_dir.?, self.out_h_filename },
12551254 ) catch unreachable;
......@@ -1365,7 +1364,7 @@ pub const LibExeObjStep = struct {
13651364 try zig_args.append("--library");
13661365 try zig_args.append(full_path_lib);
13671366
1368 if (os.path.dirname(full_path_lib)) |dirname| {
1367 if (fs.path.dirname(full_path_lib)) |dirname| {
13691368 try zig_args.append("-rpath");
13701369 try zig_args.append(dirname);
13711370 }
......@@ -1391,7 +1390,7 @@ pub const LibExeObjStep = struct {
13911390 }
13921391
13931392 if (self.build_options_contents.len() > 0) {
1394 const build_options_file = try os.path.join(
1393 const build_options_file = try fs.path.join(
13951394 builder.allocator,
13961395 [][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
13971396 );
......@@ -1503,7 +1502,7 @@ pub const LibExeObjStep = struct {
15031502 IncludeDir.OtherStep => |other| {
15041503 const h_path = other.getOutputHPath();
15051504 try zig_args.append("-isystem");
1506 try zig_args.append(os.path.dirname(h_path).?);
1505 try zig_args.append(fs.path.dirname(h_path).?);
15071506 },
15081507 }
15091508 }
......@@ -1576,7 +1575,7 @@ pub const LibExeObjStep = struct {
15761575
15771576 const output_path_nl = try builder.exec(zig_args.toSliceConst());
15781577 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
1579 self.output_dir = os.path.dirname(output_path).?;
1578 self.output_dir = fs.path.dirname(output_path).?;
15801579 }
15811580
15821581 if (self.kind == Kind.Lib and self.is_dynamic and self.target.wantSharedLibSymLinks()) {
......@@ -1637,20 +1636,20 @@ pub const RunStep = struct {
16371636 }
16381637
16391638 pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
1640 const PATH = if (builtin.os == builtin.Os.windows) "Path" else "PATH";
1639 const PATH = if (std.os.windows.is_the_target) "Path" else "PATH";
16411640 const env_map = self.getEnvMap();
16421641 const prev_path = env_map.get(PATH) orelse {
16431642 env_map.set(PATH, search_path) catch unreachable;
16441643 return;
16451644 };
1646 const new_path = self.builder.fmt("{}" ++ [1]u8{os.path.delimiter} ++ "{}", prev_path, search_path);
1645 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path);
16471646 env_map.set(PATH, new_path) catch unreachable;
16481647 }
16491648
16501649 pub fn getEnvMap(self: *RunStep) *BufMap {
16511650 return self.env_map orelse {
16521651 const env_map = self.builder.allocator.create(BufMap) catch unreachable;
1653 env_map.* = os.getEnvMap(self.builder.allocator) catch unreachable;
1652 env_map.* = process.getEnvMap(self.builder.allocator) catch unreachable;
16541653 self.env_map = env_map;
16551654 return env_map;
16561655 };
......@@ -1688,7 +1687,7 @@ pub const RunStep = struct {
16881687 switch (link_object) {
16891688 LibExeObjStep.LinkObject.OtherStep => |other| {
16901689 if (other.target.isWindows() and other.isDynamicLibrary()) {
1691 self.addPathDir(os.path.dirname(other.getOutputPath()).?);
1690 self.addPathDir(fs.path.dirname(other.getOutputPath()).?);
16921691 self.addPathForDynLibs(other);
16931692 }
16941693 },
......@@ -1718,7 +1717,7 @@ const InstallArtifactStep = struct {
17181717 .builder = builder,
17191718 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
17201719 .artifact = artifact,
1721 .dest_file = os.path.join(
1720 .dest_file = fs.path.join(
17221721 builder.allocator,
17231722 [][]const u8{ dest_dir, artifact.out_filename },
17241723 ) catch unreachable,
......@@ -1726,11 +1725,11 @@ const InstallArtifactStep = struct {
17261725 self.step.dependOn(&artifact.step);
17271726 builder.pushInstalledFile(self.dest_file);
17281727 if (self.artifact.kind == LibExeObjStep.Kind.Lib and self.artifact.is_dynamic) {
1729 builder.pushInstalledFile(os.path.join(
1728 builder.pushInstalledFile(fs.path.join(
17301729 builder.allocator,
17311730 [][]const u8{ builder.lib_dir, artifact.major_only_filename },
17321731 ) catch unreachable);
1733 builder.pushInstalledFile(os.path.join(
1732 builder.pushInstalledFile(fs.path.join(
17341733 builder.allocator,
17351734 [][]const u8{ builder.lib_dir, artifact.name_only_filename },
17361735 ) catch unreachable);
......@@ -1743,12 +1742,12 @@ const InstallArtifactStep = struct {
17431742 const builder = self.builder;
17441743
17451744 const mode = switch (builtin.os) {
1746 builtin.Os.windows => {},
1745 .windows => {},
17471746 else => switch (self.artifact.kind) {
1748 LibExeObjStep.Kind.Obj => unreachable,
1749 LibExeObjStep.Kind.Test => unreachable,
1750 LibExeObjStep.Kind.Exe => u32(0o755),
1751 LibExeObjStep.Kind.Lib => if (!self.artifact.is_dynamic) u32(0o666) else u32(0o755),
1747 .Obj => unreachable,
1748 .Test => unreachable,
1749 .Exe => u32(0o755),
1750 .Lib => if (!self.artifact.is_dynamic) u32(0o666) else u32(0o755),
17521751 },
17531752 };
17541753 try builder.copyFileMode(self.artifact.getOutputPath(), self.dest_file, mode);
......@@ -1797,8 +1796,8 @@ pub const WriteFileStep = struct {
17971796 fn make(step: *Step) !void {
17981797 const self = @fieldParentPtr(WriteFileStep, "step", step);
17991798 const full_path = self.builder.pathFromRoot(self.file_path);
1800 const full_path_dir = os.path.dirname(full_path) orelse ".";
1801 os.makePath(self.builder.allocator, full_path_dir) catch |err| {
1799 const full_path_dir = fs.path.dirname(full_path) orelse ".";
1800 fs.makePath(self.builder.allocator, full_path_dir) catch |err| {
18021801 warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));
18031802 return err;
18041803 };
......@@ -1845,7 +1844,7 @@ pub const RemoveDirStep = struct {
18451844 const self = @fieldParentPtr(RemoveDirStep, "step", step);
18461845
18471846 const full_path = self.builder.pathFromRoot(self.dir_path);
1848 os.deleteTree(self.builder.allocator, full_path) catch |err| {
1847 fs.deleteTree(self.builder.allocator, full_path) catch |err| {
18491848 warn("Unable to remove {}: {}\n", full_path, @errorName(err));
18501849 return err;
18511850 };
......@@ -1887,23 +1886,23 @@ pub const Step = struct {
18871886};
18881887
18891888fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
1890 const out_dir = os.path.dirname(output_path) orelse ".";
1891 const out_basename = os.path.basename(output_path);
1889 const out_dir = fs.path.dirname(output_path) orelse ".";
1890 const out_basename = fs.path.basename(output_path);
18921891 // sym link for libfoo.so.1 to libfoo.so.1.2.3
1893 const major_only_path = os.path.join(
1892 const major_only_path = fs.path.join(
18941893 allocator,
18951894 [][]const u8{ out_dir, filename_major_only },
18961895 ) catch unreachable;
1897 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
1896 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
18981897 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
18991898 return err;
19001899 };
19011900 // sym link for libfoo.so to libfoo.so.1
1902 const name_only_path = os.path.join(
1901 const name_only_path = fs.path.join(
19031902 allocator,
19041903 [][]const u8{ out_dir, filename_name_only },
19051904 ) catch unreachable;
1906 os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
1905 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
19071906 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
19081907 return err;
19091908 };
std/child_process.zig+23-25
......@@ -2,7 +2,9 @@ const std = @import("std.zig");
22const cstr = std.cstr;
33const unicode = std.unicode;
44const io = std.io;
5const fs = std.fs;
56const os = std.os;
7const process = std.process;
68const File = std.fs.File;
79const windows = os.windows;
810const mem = std.mem;
......@@ -14,12 +16,10 @@ const Os = builtin.Os;
1416const LinkedList = std.LinkedList;
1517const maxInt = std.math.maxInt;
1618
17const is_windows = builtin.os == .windows;
18
1919pub const ChildProcess = struct {
20 pub pid: if (is_windows) void else i32,
21 pub handle: if (is_windows) windows.HANDLE else void,
22 pub thread_handle: if (is_windows) windows.HANDLE else void,
20 pub pid: if (os.windows.is_the_target) void else i32,
21 pub handle: if (os.windows.is_the_target) windows.HANDLE else void,
22 pub thread_handle: if (os.windows.is_the_target) windows.HANDLE else void,
2323
2424 pub allocator: *mem.Allocator,
2525
......@@ -39,16 +39,16 @@ pub const ChildProcess = struct {
3939 pub stderr_behavior: StdIo,
4040
4141 /// Set to change the user id when spawning the child process.
42 pub uid: if (is_windows) void else ?u32,
42 pub uid: if (os.windows.is_the_target) void else ?u32,
4343
4444 /// Set to change the group id when spawning the child process.
45 pub gid: if (is_windows) void else ?u32,
45 pub gid: if (os.windows.is_the_target) void else ?u32,
4646
4747 /// Set to change the current working directory when spawning the child process.
4848 pub cwd: ?[]const u8,
4949
50 err_pipe: if (is_windows) void else [2]i32,
51 llnode: if (is_windows) void else LinkedList(*ChildProcess).Node,
50 err_pipe: if (os.windows.is_the_target) void else [2]i32,
51 llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node,
5252
5353 pub const SpawnError = error{
5454 ProcessFdQuotaExceeded,
......@@ -98,10 +98,8 @@ pub const ChildProcess = struct {
9898 .term = null,
9999 .env_map = null,
100100 .cwd = null,
101 .uid = if (is_windows) {} else
102 null,
103 .gid = if (is_windows) {} else
104 null,
101 .uid = if (os.windows.is_the_target) {} else null,
102 .gid = if (os.windows.is_the_target) {} else null,
105103 .stdin = null,
106104 .stdout = null,
107105 .stderr = null,
......@@ -121,7 +119,7 @@ pub const ChildProcess = struct {
121119
122120 /// On success must call `kill` or `wait`.
123121 pub fn spawn(self: *ChildProcess) !void {
124 if (is_windows) {
122 if (os.windows.is_the_target) {
125123 return self.spawnWindows();
126124 } else {
127125 return self.spawnPosix();
......@@ -135,7 +133,7 @@ pub const ChildProcess = struct {
135133
136134 /// Forcibly terminates child process and then cleans up all resources.
137135 pub fn kill(self: *ChildProcess) !Term {
138 if (is_windows) {
136 if (os.windows.is_the_target) {
139137 return self.killWindows(1);
140138 } else {
141139 return self.killPosix();
......@@ -165,7 +163,7 @@ pub const ChildProcess = struct {
165163
166164 /// Blocks until child process terminates and then cleans up all resources.
167165 pub fn wait(self: *ChildProcess) !Term {
168 if (is_windows) {
166 if (os.windows.is_the_target) {
169167 return self.waitWindows();
170168 } else {
171169 return self.waitPosix();
......@@ -339,7 +337,7 @@ pub const ChildProcess = struct {
339337 break :x env_map;
340338 } else x: {
341339 we_own_env_map = true;
342 env_map_owned = try os.getEnvMap(self.allocator);
340 env_map_owned = try process.getEnvMap(self.allocator);
343341 break :x &env_map_owned;
344342 };
345343 defer {
......@@ -372,15 +370,15 @@ pub const ChildProcess = struct {
372370 }
373371
374372 if (self.cwd) |cwd| {
375 os.changeCurDir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
373 os.chdir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
376374 }
377375
378376 if (self.gid) |gid| {
379 os.posix_setregid(gid, gid) catch |err| forkChildErrReport(err_pipe[1], err);
377 os.setregid(gid, gid) catch |err| forkChildErrReport(err_pipe[1], err);
380378 }
381379
382380 if (self.uid) |uid| {
383 os.posix_setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err);
381 os.setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err);
384382 }
385383
386384 os.execve(self.allocator, self.argv, env_map) catch |err| forkChildErrReport(err_pipe[1], err);
......@@ -541,7 +539,7 @@ pub const ChildProcess = struct {
541539 // to match posix semantics
542540 const app_name = x: {
543541 if (self.cwd) |cwd| {
544 const resolved = try os.path.resolve(self.allocator, [][]const u8{ cwd, self.argv[0] });
542 const resolved = try fs.path.resolve(self.allocator, [][]const u8{ cwd, self.argv[0] });
545543 defer self.allocator.free(resolved);
546544 break :x try cstr.addNullByte(self.allocator, resolved);
547545 } else {
......@@ -559,12 +557,12 @@ pub const ChildProcess = struct {
559557 windowsCreateProcess(app_name_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
560558 if (no_path_err != error.FileNotFound) return no_path_err;
561559
562 const PATH = try os.getEnvVarOwned(self.allocator, "PATH");
560 const PATH = try process.getEnvVarOwned(self.allocator, "PATH");
563561 defer self.allocator.free(PATH);
564562
565563 var it = mem.tokenize(PATH, ";");
566564 while (it.next()) |search_path| {
567 const joined_path = try os.path.join(self.allocator, [][]const u8{ search_path, app_name });
565 const joined_path = try fs.path.join(self.allocator, [][]const u8{ search_path, app_name });
568566 defer self.allocator.free(joined_path);
569567
570568 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);
......@@ -616,10 +614,10 @@ pub const ChildProcess = struct {
616614
617615 fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) !void {
618616 switch (stdio) {
619 StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno),
617 StdIo.Pipe => try os.dup2(pipe_fd, std_fileno),
620618 StdIo.Close => os.close(std_fileno),
621619 StdIo.Inherit => {},
622 StdIo.Ignore => try os.posixDup2(dev_null_fd, std_fileno),
620 StdIo.Ignore => try os.dup2(dev_null_fd, std_fileno),
623621 }
624622 }
625623};
std/cstr.zig-15
......@@ -9,11 +9,6 @@ pub const line_sep = switch (builtin.os) {
99 else => "\n",
1010};
1111
12/// Deprecated, use mem.len
13pub fn len(ptr: [*]const u8) usize {
14 return mem.len(u8, ptr);
15}
16
1712pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {
1813 var index: usize = 0;
1914 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}
......@@ -26,16 +21,6 @@ pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {
2621 }
2722}
2823
29/// Deprecated, use mem.toSliceConst
30pub fn toSliceConst(str: [*]const u8) []const u8 {
31 return mem.toSliceConst(u8, str);
32}
33
34/// Deprecated, use mem.toSlice
35pub fn toSlice(str: [*]u8) []u8 {
36 return mem.toSlice(u8, str);
37}
38
3924test "cstr fns" {
4025 comptime testCStrFnsImpl();
4126 testCStrFnsImpl();
std/debug.zig+70-70
......@@ -3,16 +3,18 @@ const math = std.math;
33const mem = std.mem;
44const io = std.io;
55const os = std.os;
6const fs = std.fs;
7const process = std.process;
68const elf = std.elf;
79const DW = std.dwarf;
810const macho = std.macho;
911const coff = std.coff;
1012const pdb = std.pdb;
11const windows = os.windows;
1213const ArrayList = std.ArrayList;
1314const builtin = @import("builtin");
1415const maxInt = std.math.maxInt;
1516const File = std.fs.File;
17const windows = std.os.windows;
1618
1719const leb = @import("debug/leb128.zig");
1820
......@@ -20,8 +22,8 @@ pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAlloc
2022pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator;
2123
2224pub const runtime_safety = switch (builtin.mode) {
23 builtin.Mode.Debug, builtin.Mode.ReleaseSafe => true,
24 builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => false,
25 .Debug, .ReleaseSafe => true,
26 .ReleaseFast, .ReleaseSmall => false,
2527};
2628
2729const Module = struct {
......@@ -76,7 +78,7 @@ pub fn getSelfDebugInfo() !*DebugInfo {
7678fn wantTtyColor() bool {
7779 var bytes: [128]u8 = undefined;
7880 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
79 return if (std.os.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| true else |_| stderr_file.isTty();
81 return if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| true else |_| stderr_file.isTty();
8082}
8183
8284/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
......@@ -100,47 +102,44 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
100102/// chopping off the irrelevant frames and shifting so that the returned addresses pointer
101103/// equals the passed in addresses pointer.
102104pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {
103 switch (builtin.os) {
104 builtin.Os.windows => {
105 const addrs = stack_trace.instruction_addresses;
106 const u32_addrs_len = @intCast(u32, addrs.len);
107 const first_addr = first_address orelse {
108 stack_trace.index = windows.RtlCaptureStackBackTrace(
109 0,
110 u32_addrs_len,
111 @ptrCast(**c_void, addrs.ptr),
112 null,
113 );
114 return;
115 };
116 var addr_buf_stack: [32]usize = undefined;
117 const addr_buf = if (addr_buf_stack.len > addrs.len) addr_buf_stack[0..] else addrs;
118 const n = windows.RtlCaptureStackBackTrace(0, u32_addrs_len, @ptrCast(**c_void, addr_buf.ptr), null);
119 const first_index = for (addr_buf[0..n]) |addr, i| {
120 if (addr == first_addr) {
121 break i;
122 }
123 } else {
124 stack_trace.index = 0;
105 if (windows.is_the_target) {
106 const addrs = stack_trace.instruction_addresses;
107 const u32_addrs_len = @intCast(u32, addrs.len);
108 const first_addr = first_address orelse {
109 stack_trace.index = windows.ntdll.RtlCaptureStackBackTrace(
110 0,
111 u32_addrs_len,
112 @ptrCast(**c_void, addrs.ptr),
113 null,
114 );
115 return;
116 };
117 var addr_buf_stack: [32]usize = undefined;
118 const addr_buf = if (addr_buf_stack.len > addrs.len) addr_buf_stack[0..] else addrs;
119 const n = windows.ntdll.RtlCaptureStackBackTrace(0, u32_addrs_len, @ptrCast(**c_void, addr_buf.ptr), null);
120 const first_index = for (addr_buf[0..n]) |addr, i| {
121 if (addr == first_addr) {
122 break i;
123 }
124 } else {
125 stack_trace.index = 0;
126 return;
127 };
128 const slice = addr_buf[first_index..n];
129 // We use a for loop here because slice and addrs may alias.
130 for (slice) |addr, i| {
131 addrs[i] = addr;
132 }
133 stack_trace.index = slice.len;
134 } else {
135 var it = StackIterator.init(first_address);
136 for (stack_trace.instruction_addresses) |*addr, i| {
137 addr.* = it.next() orelse {
138 stack_trace.index = i;
125139 return;
126140 };
127 const slice = addr_buf[first_index..n];
128 // We use a for loop here because slice and addrs may alias.
129 for (slice) |addr, i| {
130 addrs[i] = addr;
131 }
132 stack_trace.index = slice.len;
133 },
134 else => {
135 var it = StackIterator.init(first_address);
136 for (stack_trace.instruction_addresses) |*addr, i| {
137 addr.* = it.next() orelse {
138 stack_trace.index = i;
139 return;
140 };
141 }
142 stack_trace.index = stack_trace.instruction_addresses.len;
143 },
141 }
142 stack_trace.index = stack_trace.instruction_addresses.len;
144143 }
145144}
146145
......@@ -260,9 +259,8 @@ pub const StackIterator = struct {
260259};
261260
262261pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color: bool, start_addr: ?usize) !void {
263 switch (builtin.os) {
264 builtin.Os.windows => return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr),
265 else => {},
262 if (windows.is_the_target) {
263 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr);
266264 }
267265 var it = StackIterator.init(start_addr);
268266 while (it.next()) |return_address| {
......@@ -277,7 +275,7 @@ pub fn writeCurrentStackTraceWindows(
277275 start_addr: ?usize,
278276) !void {
279277 var addr_buf: [1024]usize = undefined;
280 const n = windows.RtlCaptureStackBackTrace(0, addr_buf.len, @ptrCast(**c_void, &addr_buf), null);
278 const n = windows.ntdll.RtlCaptureStackBackTrace(0, addr_buf.len, @ptrCast(**c_void, &addr_buf), null);
281279 const addrs = addr_buf[0..n];
282280 var start_i: usize = if (start_addr) |saddr| blk: {
283281 for (addrs) |addr, i| {
......@@ -291,17 +289,18 @@ pub fn writeCurrentStackTraceWindows(
291289}
292290
293291pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
294 switch (builtin.os) {
295 builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),
296 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
297 builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),
298 else => return error.UnsupportedOperatingSystem,
292 if (windows.is_the_target) {
293 return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color);
299294 }
295 if (os.darwin.is_the_target) {
296 return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color);
297 }
298 return printSourceAtAddressPosix(debug_info, out_stream, address, tty_color);
300299}
301300
302301fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_address: usize, tty_color: bool) !void {
303302 const allocator = getDebugInfoAllocator();
304 const base_address = os.getBaseAddress();
303 const base_address = process.getBaseAddress();
305304 const relative_address = relocated_address - base_address;
306305
307306 var coff_section: *coff.Section = undefined;
......@@ -331,7 +330,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
331330
332331 const mod = &di.modules[mod_index];
333332 try populateModule(di, mod);
334 const obj_basename = os.path.basename(mod.obj_file_name);
333 const obj_basename = fs.path.basename(mod.obj_file_name);
335334
336335 var symbol_i: usize = 0;
337336 const symbol_name = while (symbol_i != mod.symbols.len) {
......@@ -634,7 +633,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach
634633}
635634
636635fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
637 const base_addr = std.os.getBaseAddress();
636 const base_addr = process.getBaseAddress();
638637 const adjusted_addr = 0x100000000 + (address - base_addr);
639638
640639 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
......@@ -649,7 +648,7 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
649648 const symbol_name = mem.toSliceConst(u8, di.strings.ptr + symbol.nlist.n_strx);
650649 const compile_unit_name = if (symbol.ofile) |ofile| blk: {
651650 const ofile_path = mem.toSliceConst(u8, di.strings.ptr + ofile.n_strx);
652 break :blk os.path.basename(ofile_path);
651 break :blk fs.path.basename(ofile_path);
653652 } else "???";
654653 if (getLineNumberInfoMacOs(di, symbol.*, adjusted_addr)) |line_info| {
655654 defer line_info.deinit();
......@@ -716,7 +715,7 @@ pub fn printSourceAtAddressDwarf(
716715 }
717716}
718717
719pub fn printSourceAtAddressLinux(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
718pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
720719 return printSourceAtAddressDwarf(debug_info, out_stream, address, tty_color, printLineFromFileAnyOs);
721720}
722721
......@@ -776,16 +775,17 @@ pub const OpenSelfDebugInfoError = error{
776775};
777776
778777pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
779 switch (builtin.os) {
780 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return openSelfDebugInfoLinux(allocator),
781 builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),
782 builtin.Os.windows => return openSelfDebugInfoWindows(allocator),
783 else => return error.UnsupportedOperatingSystem,
778 if (windows.is_the_target) {
779 return openSelfDebugInfoWindows(allocator);
780 }
781 if (os.darwin.is_the_target) {
782 return openSelfDebugInfoMacOs(allocator);
784783 }
784 return openSelfDebugInfoPosix(allocator);
785785}
786786
787787fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
788 const self_file = try os.openSelfExe();
788 const self_file = try fs.openSelfExe();
789789 defer self_file.close();
790790
791791 const coff_obj = try allocator.create(coff.Coff);
......@@ -812,7 +812,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
812812 const len = try di.coff.getPdbPath(path_buf[0..]);
813813 const raw_path = path_buf[0..len];
814814
815 const path = try os.path.resolve(allocator, [][]const u8{raw_path});
815 const path = try fs.path.resolve(allocator, [][]const u8{raw_path});
816816
817817 try di.pdb.openFile(di.coff, path);
818818
......@@ -1002,13 +1002,13 @@ pub fn openElfDebugInfo(
10021002 return di;
10031003}
10041004
1005fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DwarfInfo {
1005fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
10061006 const S = struct {
10071007 var self_exe_file: File = undefined;
10081008 var self_exe_mmap_seekable: io.SliceSeekableInStream = undefined;
10091009 };
10101010
1011 S.self_exe_file = try os.openSelfExe();
1011 S.self_exe_file = try fs.openSelfExe();
10121012 errdefer S.self_exe_file.close();
10131013
10141014 const self_exe_mmap_len = try S.self_exe_file.getEndPos();
......@@ -1195,7 +1195,7 @@ pub const DwarfInfo = struct {
11951195};
11961196
11971197pub const DebugInfo = switch (builtin.os) {
1198 builtin.Os.macosx, builtin.Os.ios => struct {
1198 .macosx, .ios, .watchos, .tvos => struct {
11991199 symbols: []const MachoSymbol,
12001200 strings: []const u8,
12011201 ofiles: OFileTable,
......@@ -1211,13 +1211,13 @@ pub const DebugInfo = switch (builtin.os) {
12111211 return self.ofiles.allocator;
12121212 }
12131213 },
1214 builtin.Os.uefi, builtin.Os.windows => struct {
1214 .uefi, .windows => struct {
12151215 pdb: pdb.Pdb,
12161216 coff: *coff.Coff,
12171217 sect_contribs: []pdb.SectionContribEntry,
12181218 modules: []Module,
12191219 },
1220 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => DwarfInfo,
1220 .linux, .freebsd, .netbsd => DwarfInfo,
12211221 else => @compileError("Unsupported OS"),
12221222};
12231223
......@@ -1411,7 +1411,7 @@ const LineNumberProgram = struct {
14111411 return error.InvalidDebugInfo;
14121412 } else
14131413 self.include_dirs[file_entry.dir_index];
1414 const file_name = try os.path.join(self.file_entries.allocator, [][]const u8{ dir_name, file_entry.file_name });
1414 const file_name = try fs.path.join(self.file_entries.allocator, [][]const u8{ dir_name, file_entry.file_name });
14151415 errdefer self.file_entries.allocator.free(file_name);
14161416 return LineInfo{
14171417 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,
std/dynamic_library.zig+2-3
......@@ -2,7 +2,6 @@ const builtin = @import("builtin");
22
33const std = @import("std.zig");
44const mem = std.mem;
5const cstr = std.cstr;
65const os = std.os;
76const assert = std.debug.assert;
87const testing = std.testing;
......@@ -223,7 +222,7 @@ pub const ElfLib = struct {
223222 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
224223 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
225224 if (0 == self.syms[i].st_shndx) continue;
226 if (!mem.eql(u8, name, cstr.toSliceConst(self.strings + self.syms[i].st_name))) continue;
225 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
227226 if (maybe_versym) |versym| {
228227 if (!checkver(self.verdef.?, versym[i], vername, self.strings))
229228 continue;
......@@ -246,7 +245,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
246245 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
247246 }
248247 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
249 return mem.eql(u8, vername, cstr.toSliceConst(strings + aux.vda_name));
248 return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name));
250249}
251250
252251pub const WindowsDynLib = struct {
std/event/fs.zig+6-6
......@@ -879,7 +879,7 @@ pub fn Watch(comptime V: type) type {
879879 }
880880
881881 async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V {
882 const resolved_path = try os.path.resolve(self.channel.loop.allocator, [][]const u8{file_path});
882 const resolved_path = try std.fs.path.resolve(self.channel.loop.allocator, [][]const u8{file_path});
883883 var resolved_path_consumed = false;
884884 defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path);
885885
......@@ -967,12 +967,12 @@ pub fn Watch(comptime V: type) type {
967967 async fn addFileLinux(self: *Self, file_path: []const u8, value: V) !?V {
968968 const value_copy = value;
969969
970 const dirname = os.path.dirname(file_path) orelse ".";
970 const dirname = std.fs.path.dirname(file_path) orelse ".";
971971 const dirname_with_null = try std.cstr.addNullByte(self.channel.loop.allocator, dirname);
972972 var dirname_with_null_consumed = false;
973973 defer if (!dirname_with_null_consumed) self.channel.loop.allocator.free(dirname_with_null);
974974
975 const basename = os.path.basename(file_path);
975 const basename = std.fs.path.basename(file_path);
976976 const basename_with_null = try std.cstr.addNullByte(self.channel.loop.allocator, basename);
977977 var basename_with_null_consumed = false;
978978 defer if (!basename_with_null_consumed) self.channel.loop.allocator.free(basename_with_null);
......@@ -1013,7 +1013,7 @@ pub fn Watch(comptime V: type) type {
10131013 const value_copy = value;
10141014 // TODO we might need to convert dirname and basename to canonical file paths ("short"?)
10151015
1016 const dirname = try std.mem.dupe(self.channel.loop.allocator, u8, os.path.dirname(file_path) orelse ".");
1016 const dirname = try std.mem.dupe(self.channel.loop.allocator, u8, std.fs.path.dirname(file_path) orelse ".");
10171017 var dirname_consumed = false;
10181018 defer if (!dirname_consumed) self.channel.loop.allocator.free(dirname);
10191019
......@@ -1021,7 +1021,7 @@ pub fn Watch(comptime V: type) type {
10211021 defer self.channel.loop.allocator.free(dirname_utf16le);
10221022
10231023 // TODO https://github.com/ziglang/zig/issues/265
1024 const basename = os.path.basename(file_path);
1024 const basename = std.fs.path.basename(file_path);
10251025 const basename_utf16le_null = try std.unicode.utf8ToUtf16LeWithNull(self.channel.loop.allocator, basename);
10261026 var basename_utf16le_null_consumed = false;
10271027 defer if (!basename_utf16le_null_consumed) self.channel.loop.allocator.free(basename_utf16le_null);
......@@ -1334,7 +1334,7 @@ async fn testFsWatchCantFail(loop: *Loop, result: *(anyerror!void)) void {
13341334}
13351335
13361336async fn testFsWatch(loop: *Loop) !void {
1337 const file_path = try os.path.join(loop.allocator, [][]const u8{ test_tmp_dir, "file.txt" });
1337 const file_path = try std.fs.path.join(loop.allocator, [][]const u8{ test_tmp_dir, "file.txt" });
13381338 defer loop.allocator.free(file_path);
13391339
13401340 const contents =
std/fmt.zig+1-1
......@@ -226,7 +226,7 @@ pub fn formatType(
226226 builtin.TypeInfo.Pointer.Size.Many => {
227227 if (ptr_info.child == u8) {
228228 if (fmt.len > 0 and fmt[0] == 's') {
229 const len = std.cstr.len(value);
229 const len = mem.len(u8, value);
230230 return formatText(value[0..len], fmt, context, Errors, output);
231231 }
232232 }
std/fs.zig+10-10
......@@ -1,6 +1,8 @@
1const builtin = @import("builtin");
12const std = @import("std.zig");
23const os = std.os;
34const mem = std.mem;
5const Allocator = std.mem.Allocator;
46
57pub const path = @import("fs/path.zig");
68pub const File = @import("fs/file.zig").File;
......@@ -12,8 +14,6 @@ pub const deleteFileC = os.unlinkC;
1214pub const rename = os.rename;
1315pub const renameC = os.renameC;
1416pub const renameW = os.renameW;
15pub const changeCurDir = os.chdir;
16pub const changeCurDirC = os.chdirC;
1717pub const realpath = os.realpath;
1818pub const realpathC = os.realpathC;
1919pub const realpathW = os.realpathW;
......@@ -65,13 +65,13 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
6565 else => return err, // TODO zig should know this set does not include PathAlreadyExists
6666 }
6767
68 const dirname = os.path.dirname(new_path) orelse ".";
68 const dirname = path.dirname(new_path) orelse ".";
6969
7070 var rand_buf: [12]u8 = undefined;
7171 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64.Base64Encoder.calcSize(rand_buf.len));
7272 defer allocator.free(tmp_path);
7373 mem.copy(u8, tmp_path[0..], dirname);
74 tmp_path[dirname.len] = os.path.sep;
74 tmp_path[dirname.len] = path.sep;
7575 while (true) {
7676 try getRandomBytes(rand_buf[0..]);
7777 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
......@@ -143,7 +143,7 @@ pub const AtomicFile = struct {
143143 /// TODO once we have null terminated pointers, use the
144144 /// openWriteNoClobberN function
145145 pub fn init(dest_path: []const u8, mode: File.Mode) InitError!AtomicFile {
146 const dirname = os.path.dirname(dest_path);
146 const dirname = path.dirname(dest_path);
147147 var rand_buf: [12]u8 = undefined;
148148 const dirname_component_len = if (dirname) |d| d.len + 1 else 0;
149149 const encoded_rand_len = comptime base64.Base64Encoder.calcSize(rand_buf.len);
......@@ -153,7 +153,7 @@ pub const AtomicFile = struct {
153153
154154 if (dirname) |dir| {
155155 mem.copy(u8, tmp_path_buf[0..], dir);
156 tmp_path_buf[dir.len] = os.path.sep;
156 tmp_path_buf[dir.len] = path.sep;
157157 }
158158
159159 tmp_path_buf[tmp_path_len] = 0;
......@@ -240,7 +240,7 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
240240 // march end_index backward until next path component
241241 while (true) {
242242 end_index -= 1;
243 if (os.path.isSep(resolved_path[end_index])) break;
243 if (path.isSep(resolved_path[end_index])) break;
244244 }
245245 continue;
246246 },
......@@ -250,7 +250,7 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
250250 // march end_index forward until next path component
251251 while (true) {
252252 end_index += 1;
253 if (end_index == resolved_path.len or os.path.isSep(resolved_path[end_index])) break;
253 if (end_index == resolved_path.len or path.isSep(resolved_path[end_index])) break;
254254 }
255255 }
256256}
......@@ -614,7 +614,7 @@ pub const Dir = struct {
614614 const next_index = self.handle.index + linux_entry.d_reclen;
615615 self.handle.index = next_index;
616616
617 const name = cstr.toSlice(@ptrCast([*]u8, &linux_entry.d_name));
617 const name = mem.toSlice(u8, @ptrCast([*]u8, &linux_entry.d_name));
618618
619619 // skip . and .. entries
620620 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -709,7 +709,7 @@ pub fn readLinkC(pathname: [*]const u8, buffer: *[os.PATH_MAX]u8) ![]u8 {
709709 return os.readlinkC(pathname, buffer);
710710}
711711
712pub const OpenSelfExeError = error{};
712pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError;
713713
714714pub fn openSelfExe() OpenSelfExeError!File {
715715 if (os.linux.is_the_target) {
std/fs/file.zig-24
......@@ -307,28 +307,4 @@ pub const File = struct {
307307 return self.file.getPos();
308308 }
309309 };
310
311 pub fn stdout() !File {
312 if (windows.is_the_target) {
313 const handle = try windows.GetStdHandle(windows.STD_OUTPUT_HANDLE);
314 return openHandle(handle);
315 }
316 return openHandle(os.STDOUT_FILENO);
317 }
318
319 pub fn stderr() !File {
320 if (windows.is_the_target) {
321 const handle = try windows.GetStdHandle(windows.STD_ERROR_HANDLE);
322 return openHandle(handle);
323 }
324 return openHandle(os.STDERR_FILENO);
325 }
326
327 pub fn stdin() !File {
328 if (windows.is_the_target) {
329 const handle = try windows.GetStdHandle(windows.STD_INPUT_HANDLE);
330 return openHandle(handle);
331 }
332 return openHandle(os.STDIN_FILENO);
333 }
334310};
std/fs/get_app_data_dir.zig+7-6
......@@ -2,6 +2,7 @@ const std = @import("../std.zig");
22const builtin = @import("builtin");
33const unicode = std.unicode;
44const mem = std.mem;
5const fs = std.fs;
56const os = std.os;
67
78pub const GetAppDataDirError = error{
......@@ -15,7 +16,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
1516 switch (builtin.os) {
1617 .windows => {
1718 var dir_path_ptr: [*]u16 = undefined;
18 switch (os.windows.SHGetKnownFolderPath(
19 switch (os.windows.shell32.SHGetKnownFolderPath(
1920 &os.windows.FOLDERID_LocalAppData,
2021 os.windows.KF_FLAG_CREATE,
2122 null,
......@@ -30,25 +31,25 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
3031 error.OutOfMemory => return error.OutOfMemory,
3132 };
3233 defer allocator.free(global_dir);
33 return os.path.join(allocator, [][]const u8{ global_dir, appname });
34 return fs.path.join(allocator, [][]const u8{ global_dir, appname });
3435 },
3536 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
3637 else => return error.AppDataDirUnavailable,
3738 }
3839 },
3940 .macosx => {
40 const home_dir = os.getEnvPosix("HOME") orelse {
41 const home_dir = os.getenv("HOME") orelse {
4142 // TODO look in /etc/passwd
4243 return error.AppDataDirUnavailable;
4344 };
44 return os.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname });
45 return fs.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname });
4546 },
4647 .linux, .freebsd, .netbsd => {
47 const home_dir = os.getEnvPosix("HOME") orelse {
48 const home_dir = os.getenv("HOME") orelse {
4849 // TODO look in /etc/passwd
4950 return error.AppDataDirUnavailable;
5051 };
51 return os.path.join(allocator, [][]const u8{ home_dir, ".local", "share", appname });
52 return fs.path.join(allocator, [][]const u8{ home_dir, ".local", "share", appname });
5253 },
5354 else => @compileError("Unsupported OS"),
5455 }
std/fs/path.zig+10-12
......@@ -1,16 +1,14 @@
1const std = @import("../std.zig");
21const builtin = @import("builtin");
3const Os = builtin.Os;
2const std = @import("../std.zig");
43const debug = std.debug;
54const assert = debug.assert;
65const testing = std.testing;
76const mem = std.mem;
87const fmt = std.fmt;
98const Allocator = mem.Allocator;
10const os = std.os;
119const math = std.math;
12const windows = os.windows;
13const cstr = std.cstr;
10const windows = std.os.windows;
11const fs = std.fs;
1412
1513pub const sep_windows = '\\';
1614pub const sep_posix = '/';
......@@ -392,7 +390,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
392390pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
393391 if (paths.len == 0) {
394392 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd
395 return os.getCwdAlloc(allocator);
393 return fs.getCwdAlloc(allocator);
396394 }
397395
398396 // determine which disk designator we will result with, if any
......@@ -487,7 +485,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
487485 },
488486 WindowsPath.Kind.None => {
489487 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd
490 const cwd = try os.getCwdAlloc(allocator);
488 const cwd = try fs.getCwdAlloc(allocator);
491489 defer allocator.free(cwd);
492490 const parsed_cwd = windowsParsePath(cwd);
493491 result = try allocator.alloc(u8, max_size + parsed_cwd.disk_designator.len + 1);
......@@ -503,7 +501,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
503501 } else {
504502 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd
505503 // TODO call get cwd for the result_disk_designator instead of the global one
506 const cwd = try os.getCwdAlloc(allocator);
504 const cwd = try fs.getCwdAlloc(allocator);
507505 defer allocator.free(cwd);
508506
509507 result = try allocator.alloc(u8, max_size + cwd.len + 1);
......@@ -573,7 +571,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
573571pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
574572 if (paths.len == 0) {
575573 assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd
576 return os.getCwdAlloc(allocator);
574 return fs.getCwdAlloc(allocator);
577575 }
578576
579577 var first_index: usize = 0;
......@@ -595,7 +593,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
595593 result = try allocator.alloc(u8, max_size);
596594 } else {
597595 assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd
598 const cwd = try os.getCwdAlloc(allocator);
596 const cwd = try fs.getCwdAlloc(allocator);
599597 defer allocator.free(cwd);
600598 result = try allocator.alloc(u8, max_size + cwd.len + 1);
601599 mem.copy(u8, result, cwd);
......@@ -634,7 +632,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
634632}
635633
636634test "resolve" {
637 const cwd = try os.getCwdAlloc(debug.global_allocator);
635 const cwd = try fs.getCwdAlloc(debug.global_allocator);
638636 if (windows.is_the_target) {
639637 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
640638 cwd[0] = asciiUpper(cwd[0]);
......@@ -648,7 +646,7 @@ test "resolve" {
648646
649647test "resolveWindows" {
650648 if (windows.is_the_target) {
651 const cwd = try os.getCwdAlloc(debug.global_allocator);
649 const cwd = try fs.getCwdAlloc(debug.global_allocator);
652650 const parsed_cwd = windowsParsePath(cwd);
653651 {
654652 const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
std/heap.zig+18-18
......@@ -103,7 +103,7 @@ pub const DirectAllocator = struct {
103103 return @ptrCast([*]u8, final_addr)[0..n];
104104 }
105105
106 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
106 const alloc_size = if (alignment <= mem.page_size) n else n + alignment;
107107 const addr = os.mmap(
108108 null,
109109 alloc_size,
......@@ -123,7 +123,7 @@ pub const DirectAllocator = struct {
123123 if (unused_start_len != 0) {
124124 os.munmap(addr, unused_start_len);
125125 }
126 const aligned_end_addr = std.mem.alignForward(aligned_addr + n, os.page_size);
126 const aligned_end_addr = std.mem.alignForward(aligned_addr + n, mem.page_size);
127127 const unused_end_len = addr + alloc_size - aligned_end_addr;
128128 if (unused_end_len != 0) {
129129 os.munmap(aligned_end_addr, unused_end_len);
......@@ -147,7 +147,7 @@ pub const DirectAllocator = struct {
147147 const base_addr = @ptrToInt(old_mem.ptr);
148148 const old_addr_end = base_addr + old_mem.len;
149149 const new_addr_end = base_addr + new_size;
150 const new_addr_end_rounded = mem.alignForward(new_addr_end, os.page_size);
150 const new_addr_end_rounded = mem.alignForward(new_addr_end, mem.page_size);
151151 if (old_addr_end > new_addr_end_rounded) {
152152 // For shrinking that is not releasing, we will only
153153 // decommit the pages not needed anymore.
......@@ -163,7 +163,7 @@ pub const DirectAllocator = struct {
163163 const base_addr = @ptrToInt(old_mem.ptr);
164164 const old_addr_end = base_addr + old_mem.len;
165165 const new_addr_end = base_addr + new_size;
166 const new_addr_end_rounded = mem.alignForward(new_addr_end, os.page_size);
166 const new_addr_end_rounded = mem.alignForward(new_addr_end, mem.page_size);
167167 if (old_addr_end > new_addr_end_rounded) {
168168 os.munmap(new_addr_end_rounded, old_addr_end - new_addr_end_rounded);
169169 }
......@@ -196,9 +196,9 @@ pub const DirectAllocator = struct {
196196 }
197197
198198 const old_addr_end = base_addr + old_mem.len;
199 const old_addr_end_rounded = mem.alignForward(old_addr_end, os.page_size);
199 const old_addr_end_rounded = mem.alignForward(old_addr_end, mem.page_size);
200200 const new_addr_end = base_addr + new_size;
201 const new_addr_end_rounded = mem.alignForward(new_addr_end, os.page_size);
201 const new_addr_end_rounded = mem.alignForward(new_addr_end, mem.page_size);
202202 if (new_addr_end_rounded == old_addr_end_rounded) {
203203 // The reallocation fits in the already allocated pages.
204204 return @ptrCast([*]u8, old_mem.ptr)[0..new_size];
......@@ -374,7 +374,7 @@ pub const ArenaAllocator = struct {
374374 var len = prev_len;
375375 while (true) {
376376 len += len / 2;
377 len += os.page_size - @rem(len, os.page_size);
377 len += mem.page_size - @rem(len, mem.page_size);
378378 if (len >= actual_min_size) break;
379379 }
380380 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);
......@@ -520,11 +520,11 @@ const WasmAllocator = struct {
520520 const adjusted_index = self.end_index + (adjusted_addr - addr);
521521 const new_end_index = adjusted_index + size;
522522
523 if (new_end_index > self.num_pages * os.page_size) {
524 const required_memory = new_end_index - (self.num_pages * os.page_size);
523 if (new_end_index > self.num_pages * mem.page_size) {
524 const required_memory = new_end_index - (self.num_pages * mem.page_size);
525525
526 var num_pages: usize = required_memory / os.page_size;
527 if (required_memory % os.page_size != 0) {
526 var num_pages: usize = required_memory / mem.page_size;
527 if (required_memory % mem.page_size != 0) {
528528 num_pages += 1;
529529 }
530530
......@@ -553,14 +553,14 @@ const WasmAllocator = struct {
553553
554554 // Initialize start_ptr at the first realloc
555555 if (self.num_pages == 0) {
556 self.start_ptr = @intToPtr([*]u8, @intCast(usize, @"llvm.wasm.memory.size.i32"(0)) * os.page_size);
556 self.start_ptr = @intToPtr([*]u8, @intCast(usize, @"llvm.wasm.memory.size.i32"(0)) * mem.page_size);
557557 }
558558
559559 if (is_last_item(allocator, old_mem, new_align)) {
560560 const start_index = self.end_index - old_mem.len;
561561 const new_end_index = start_index + new_size;
562562
563 if (new_end_index > self.num_pages * os.page_size) {
563 if (new_end_index > self.num_pages * mem.page_size) {
564564 _ = try alloc(allocator, new_end_index - self.end_index, new_align);
565565 }
566566 const result = self.start_ptr[start_index..new_end_index];
......@@ -876,10 +876,10 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi
876876fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
877877 //Maybe a platform's page_size is actually the same as or
878878 // very near usize?
879 if (os.page_size << 2 > maxInt(usize)) return;
879 if (mem.page_size << 2 > maxInt(usize)) return;
880880
881881 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
882 const large_align = u29(os.page_size << 2);
882 const large_align = u29(mem.page_size << 2);
883883
884884 var align_mask: usize = undefined;
885885 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask);
......@@ -906,7 +906,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi
906906 var debug_buffer: [1000]u8 = undefined;
907907 const debug_allocator = &FixedBufferAllocator.init(&debug_buffer).allocator;
908908
909 const alloc_size = os.page_size * 2 + 50;
909 const alloc_size = mem.page_size * 2 + 50;
910910 var slice = try allocator.alignedAlloc(u8, 16, alloc_size);
911911 defer allocator.free(slice);
912912
......@@ -915,7 +915,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi
915915 // which is 16 pages, hence the 32. This test may require to increase
916916 // the size of the allocations feeding the `allocator` parameter if they
917917 // fail, because of this high over-alignment we want to have.
918 while (@ptrToInt(slice.ptr) == mem.alignForward(@ptrToInt(slice.ptr), os.page_size * 32)) {
918 while (@ptrToInt(slice.ptr) == mem.alignForward(@ptrToInt(slice.ptr), mem.page_size * 32)) {
919919 try stuff_to_free.append(slice);
920920 slice = try allocator.alignedAlloc(u8, 16, alloc_size);
921921 }
......@@ -926,7 +926,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi
926926 slice[60] = 0x34;
927927
928928 // realloc to a smaller size but with a larger alignment
929 slice = try allocator.alignedRealloc(slice, os.page_size * 32, alloc_size / 2);
929 slice = try allocator.alignedRealloc(slice, mem.page_size * 32, alloc_size / 2);
930930 testing.expect(slice[0] == 0x12);
931931 testing.expect(slice[60] == 0x34);
932932}
std/io.zig+25-2
......@@ -15,8 +15,31 @@ const fmt = std.fmt;
1515const File = std.fs.File;
1616const testing = std.testing;
1717
18const is_posix = builtin.os != builtin.Os.windows;
19const is_windows = builtin.os == builtin.Os.windows;
18pub const GetStdIoError = os.windows.GetStdHandleError;
19
20pub fn getStdOut() GetStdIoError!File {
21 if (os.windows.is_the_target) {
22 const handle = try os.windows.GetStdHandle(os.windows.STD_OUTPUT_HANDLE);
23 return File.openHandle(handle);
24 }
25 return File.openHandle(os.STDOUT_FILENO);
26}
27
28pub fn getStdErr() GetStdIoError!File {
29 if (os.windows.is_the_target) {
30 const handle = try os.windows.GetStdHandle(os.windows.STD_ERROR_HANDLE);
31 return File.openHandle(handle);
32 }
33 return File.openHandle(os.STDERR_FILENO);
34}
35
36pub fn getStdIn() GetStdIoError!File {
37 if (os.windows.is_the_target) {
38 const handle = try os.windows.GetStdHandle(os.windows.STD_INPUT_HANDLE);
39 return File.openHandle(handle);
40 }
41 return File.openHandle(os.STDIN_FILENO);
42}
2043
2144pub const SeekableStream = @import("io/seekable_stream.zig").SeekableStream;
2245pub const SliceSeekableInStream = @import("io/seekable_stream.zig").SliceSeekableInStream;
std/mem.zig-18
......@@ -1462,21 +1462,3 @@ test "std.mem.alignForward" {
14621462 testing.expect(alignForward(16, 8) == 16);
14631463 testing.expect(alignForward(17, 8) == 24);
14641464}
1465
1466pub fn getBaseAddress() usize {
1467 switch (builtin.os) {
1468 .linux => {
1469 const base = std.os.system.getauxval(std.elf.AT_BASE);
1470 if (base != 0) {
1471 return base;
1472 }
1473 const phdr = std.os.system.getauxval(std.elf.AT_PHDR);
1474 return phdr - @sizeOf(std.elf.Ehdr);
1475 },
1476 .macosx, .freebsd, .netbsd => {
1477 return @ptrToInt(&std.c._mh_execute_header);
1478 },
1479 .windows => return @ptrToInt(windows.kernel32.GetModuleHandleW(null)),
1480 else => @compileError("Unsupported OS"),
1481 }
1482}
std/os.zig+53-54
......@@ -8,7 +8,7 @@
88// cross platform abstracting.
99// * When there exists a corresponding libc function and linking libc, the libc
1010// implementation is used. Exceptions are made for known buggy areas of libc.
11// On Linux libc can be side-stepped by using `std.os.linux.sys`.
11// On Linux libc can be side-stepped by using `std.os.linux` directly.
1212// * For Windows, this file represents the API that libc would provide for
1313// Windows. For thin wrappers around Windows-specific APIs, see `std.os.windows`.
1414// Note: The Zig standard library does not support POSIX thread cancellation, and
......@@ -16,7 +16,9 @@
1616
1717const std = @import("std.zig");
1818const builtin = @import("builtin");
19const assert = std.debug.assert;
1920const math = std.math;
21const mem = std.mem;
2022const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
2123
2224comptime {
......@@ -46,9 +48,14 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {
4648
4749pub use @import("os/bits.zig");
4850
49/// See also `getenv`.
51/// See also `getenv`. Populated by startup code before main().
5052pub var environ: [][*]u8 = undefined;
5153
54/// Populated by startup code before main().
55/// Not available on Windows. See `std.process.args`
56/// for obtaining the process arguments.
57pub var argv: [][*]u8 = undefined;
58
5259/// To obtain errno, call this function with the return value of the
5360/// system function call. For some systems this will obtain the value directly
5461/// from the return code; for others it will use a thread-local errno variable.
......@@ -103,7 +110,7 @@ pub fn getrandom(buf: []u8) GetRandomError!void {
103110 }
104111 }
105112 if (wasi.is_the_target) {
106 switch (os.wasi.random_get(buf.ptr, buf.len)) {
113 switch (wasi.random_get(buf.ptr, buf.len)) {
107114 0 => return,
108115 else => |err| return unexpectedErrno(err),
109116 }
......@@ -138,15 +145,15 @@ pub fn abort() noreturn {
138145 while (true) {}
139146 }
140147
141 raise(SIGABRT);
148 raise(SIGABRT) catch {};
142149
143150 // TODO the rest of the implementation of abort() from musl libc here
144151
145 raise(SIGKILL);
152 raise(SIGKILL) catch {};
146153 exit(127);
147154}
148155
149pub const RaiseError = error{};
156pub const RaiseError = error{Unexpected};
150157
151158pub fn raise(sig: u8) RaiseError!void {
152159 if (builtin.link_libc) {
......@@ -163,19 +170,19 @@ pub fn raise(sig: u8) RaiseError!void {
163170 }
164171 }
165172
166 if (windows.is_the_target) {
167 @compileError("TODO implement std.os.raise for Windows");
173 if (linux.is_the_target) {
174 var set: linux.sigset_t = undefined;
175 linux.blockAppSignals(&set);
176 const tid = linux.syscall0(linux.SYS_gettid);
177 const rc = linux.syscall2(linux.SYS_tkill, tid, sig);
178 linux.restoreSignals(&set);
179 switch (errno(rc)) {
180 0 => return,
181 else => |err| return unexpectedErrno(err),
182 }
168183 }
169184
170 var set: system.sigset_t = undefined;
171 system.blockAppSignals(&set);
172 const tid = system.syscall0(system.SYS_gettid);
173 const rc = system.syscall2(system.SYS_tkill, tid, sig);
174 system.restoreSignals(&set);
175 switch (errno(rc)) {
176 0 => return,
177 else => |err| return unexpectedErrno(err),
178 }
185 @compileError("std.os.raise unimplemented for this target");
179186}
180187
181188pub const KillError = error{
......@@ -229,13 +236,13 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
229236 }
230237
231238 if (wasi.is_the_target and !builtin.link_libc) {
232 const iovs = [1]was.iovec_t{wasi.iovec_t{
233 .buf = buf.ptr,
234 .buf_len = buf.len,
239 const iovs = [1]iovec{iovec{
240 .iov_base = buf.ptr,
241 .iov_len = buf.len,
235242 }};
236243
237244 var nread: usize = undefined;
238 switch (fd_read(fd, &iovs, iovs.len, &nread)) {
245 switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) {
239246 0 => return nread,
240247 else => |err| return unexpectedErrno(err),
241248 }
......@@ -277,7 +284,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
277284/// This function is for blocking file descriptors only. For non-blocking, see
278285/// `preadvAsync`.
279286pub fn preadv(fd: fd_t, iov: [*]const iovec, count: usize, offset: u64) ReadError!usize {
280 if (os.darwin.is_the_target) {
287 if (darwin.is_the_target) {
281288 // Darwin does not have preadv but it does have pread.
282289 var off: usize = 0;
283290 var iov_i: usize = 0;
......@@ -353,12 +360,12 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
353360 }
354361
355362 if (wasi.is_the_target and !builtin.link_libc) {
356 const ciovs = [1]wasi.ciovec_t{wasi.ciovec_t{
357 .buf = bytes.ptr,
358 .buf_len = bytes.len,
363 const ciovs = [1]iovec_const{iovec_const{
364 .iov_base = bytes.ptr,
365 .iov_len = bytes.len,
359366 }};
360367 var nwritten: usize = undefined;
361 switch (fd_write(fd, &ciovs, ciovs.len, &nwritten)) {
368 switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) {
362369 0 => return,
363370 else => |err| return unexpectedErrno(err),
364371 }
......@@ -538,29 +545,29 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
538545/// `argv[0]` is the executable path.
539546/// This function also uses the PATH environment variable to get the full path to the executable.
540547/// TODO provide execveC which does not take an allocator
541pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const BufMap) !void {
542 const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1);
548pub fn execve(allocator: *mem.Allocator, argv_slice: []const []const u8, env_map: *const std.BufMap) !void {
549 const argv_buf = try allocator.alloc(?[*]u8, argv_slice.len + 1);
543550 mem.set(?[*]u8, argv_buf, null);
544551 defer {
545552 for (argv_buf) |arg| {
546 const arg_buf = if (arg) |ptr| cstr.toSlice(ptr) else break;
553 const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break;
547554 allocator.free(arg_buf);
548555 }
549556 allocator.free(argv_buf);
550557 }
551 for (argv) |arg, i| {
558 for (argv_slice) |arg, i| {
552559 const arg_buf = try allocator.alloc(u8, arg.len + 1);
553560 @memcpy(arg_buf.ptr, arg.ptr, arg.len);
554561 arg_buf[arg.len] = 0;
555562
556563 argv_buf[i] = arg_buf.ptr;
557564 }
558 argv_buf[argv.len] = null;
565 argv_buf[argv_slice.len] = null;
559566
560567 const envp_buf = try createNullDelimitedEnvMap(allocator, env_map);
561568 defer freeNullDelimitedEnvMap(allocator, envp_buf);
562569
563 const exe_path = argv[0];
570 const exe_path = argv_slice[0];
564571 if (mem.indexOfScalar(u8, exe_path, '/') != null) {
565572 return execveErrnoToErr(errno(system.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr)));
566573 }
......@@ -593,7 +600,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B
593600 return execveErrnoToErr(err);
594601}
595602
596pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap) ![]?[*]u8 {
603pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*]u8 {
597604 const envp_count = env_map.count();
598605 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);
599606 mem.set(?[*]u8, envp_buf, null);
......@@ -616,9 +623,9 @@ pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap)
616623 return envp_buf;
617624}
618625
619pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?[*]u8) void {
626pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*]u8) void {
620627 for (envp_buf) |env| {
621 const env_buf = if (env) |ptr| ptr[0 .. cstr.len(ptr) + 1] else break;
628 const env_buf = if (env) |ptr| ptr[0 .. mem.len(u8, ptr) + 1] else break;
622629 allocator.free(env_buf);
623630 }
624631 allocator.free(envp_buf);
......@@ -633,6 +640,8 @@ pub const ExecveError = error{
633640 FileNotFound,
634641 NotDir,
635642 FileBusy,
643 ProcessFdQuotaExceeded,
644 NameTooLong,
636645
637646 Unexpected,
638647};
......@@ -703,17 +712,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
703712 }
704713
705714 const err = if (builtin.link_libc) blk: {
706 break :blk if (system.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else system._errno().*;
715 break :blk if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*;
707716 } else blk: {
708 break :blk errno(system.getcwd(out_buffer, out_buffer.len));
717 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
709718 };
710719 switch (err) {
711 0 => return mem.toSlice(u8, out_buffer),
720 0 => return mem.toSlice(u8, out_buffer.ptr),
712721 EFAULT => unreachable,
713722 EINVAL => unreachable,
714723 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
715724 ERANGE => return error.NameTooLong,
716 else => |err| return unexpectedErrno(err),
725 else => return unexpectedErrno(err),
717726 }
718727}
719728
......@@ -1711,8 +1720,8 @@ pub const FStatError = error{
17111720
17121721pub fn fstat(fd: fd_t) FStatError!Stat {
17131722 var stat: Stat = undefined;
1714 if (os.darwin.is_the_target) {
1715 switch (errno(system.@"fstat$INODE64"(fd, buf))) {
1723 if (darwin.is_the_target) {
1724 switch (errno(system.@"fstat$INODE64"(fd, &stat))) {
17161725 0 => return stat,
17171726 EBADF => unreachable, // Always a race condition.
17181727 ENOMEM => return error.SystemResources,
......@@ -1877,7 +1886,7 @@ pub const ForkError = error{
18771886pub fn fork() ForkError!pid_t {
18781887 const rc = system.fork();
18791888 switch (errno(rc)) {
1880 0 => return rc,
1889 0 => return @intCast(pid_t, rc),
18811890 EAGAIN => return error.SystemResources,
18821891 ENOMEM => return error.SystemResources,
18831892 else => |err| return unexpectedErrno(err),
......@@ -1891,6 +1900,7 @@ pub const MMapError = error{
18911900 SystemFdQuotaExceeded,
18921901 MemoryMappingNotSupported,
18931902 OutOfMemory,
1903 Unexpected,
18941904};
18951905
18961906/// Map files or devices into memory.
......@@ -1992,6 +2002,7 @@ pub fn accessC(path: [*]const u8, mode: u32) AccessError!void {
19922002pub const PipeError = error{
19932003 SystemFdQuotaExceeded,
19942004 ProcessFdQuotaExceeded,
2005 Unexpected,
19952006};
19962007
19972008/// Creates a unidirectional data channel that can be used for interprocess communication.
......@@ -2065,18 +2076,6 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
20652076 }
20662077}
20672078
2068pub fn nanosleep(req: timespec) void {
2069 var rem = req;
2070 while (true) {
2071 switch (errno(system.nanosleep(&rem, &rem))) {
2072 0 => return,
2073 EINVAL => unreachable, // Invalid parameters.
2074 EFAULT => unreachable,
2075 EINTR => continue,
2076 }
2077 }
2078}
2079
20802079pub const SeekError = error{
20812080 Unseekable,
20822081 Unexpected,
std/os/bits/linux.zig+5-5
......@@ -692,12 +692,12 @@ pub const winsize = extern struct {
692692 ws_ypixel: u16,
693693};
694694
695const NSIG = 65;
696const sigset_t = [128 / @sizeOf(usize)]usize;
697const all_mask = []u32{ 0xffffffff, 0xffffffff };
698const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
695pub const NSIG = 65;
696pub const sigset_t = [128 / @sizeOf(usize)]usize;
697pub const all_mask = []u32{ 0xffffffff, 0xffffffff };
698pub const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
699699
700const k_sigaction = extern struct {
700pub const k_sigaction = extern struct {
701701 handler: extern fn (i32) void,
702702 flags: usize,
703703 restorer: extern fn () void,
std/os/bits/wasi.zig+2-8
......@@ -13,10 +13,7 @@ pub const ADVICE_WILLNEED: advice_t = 3;
1313pub const ADVICE_DONTNEED: advice_t = 4;
1414pub const ADVICE_NOREUSE: advice_t = 5;
1515
16pub const ciovec_t = extern struct {
17 buf: [*]const u8,
18 buf_len: usize,
19};
16pub const ciovec_t = iovec_const;
2017
2118pub const clockid_t = u32;
2219pub const CLOCK_REALTIME: clockid_t = 0;
......@@ -186,10 +183,7 @@ pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
186183
187184pub const inode_t = u64;
188185
189pub const iovec_t = extern struct {
190 buf: [*]u8,
191 buf_len: usize,
192};
186pub const iovec_t = iovec;
193187
194188pub const linkcount_t = u32;
195189
std/os/linux.zig+4-3
......@@ -20,6 +20,7 @@ pub use switch (builtin.arch) {
2020 else => struct {},
2121};
2222pub use @import("bits.zig");
23pub const tls = @import("linux/tls.zig");
2324
2425/// Set by startup code, used by `getauxval`.
2526pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
......@@ -539,15 +540,15 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
539540 return 0;
540541}
541542
542fn blockAllSignals(set: *sigset_t) void {
543pub fn blockAllSignals(set: *sigset_t) void {
543544 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
544545}
545546
546fn blockAppSignals(set: *sigset_t) void {
547pub fn blockAppSignals(set: *sigset_t) void {
547548 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
548549}
549550
550fn restoreSignals(set: *sigset_t) void {
551pub fn restoreSignals(set: *sigset_t) void {
551552 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
552553}
553554
std/os/linux/vdso.zig+2-3
......@@ -1,7 +1,6 @@
11const std = @import("../../std.zig");
22const elf = std.elf;
33const linux = std.os.linux;
4const cstr = std.cstr;
54const mem = std.mem;
65const maxInt = std.math.maxInt;
76
......@@ -66,7 +65,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6665 if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
6766 if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
6867 if (0 == syms[i].st_shndx) continue;
69 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;
68 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;
7069 if (maybe_versym) |versym| {
7170 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7271 continue;
......@@ -88,5 +87,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
8887 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
8988 }
9089 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
91 return mem.eql(u8, vername, cstr.toSliceConst(strings + aux.vda_name));
90 return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name));
9291}
std/os/test.zig+7-6
......@@ -3,6 +3,7 @@ const os = std.os;
33const testing = std.testing;
44const expect = std.testing.expect;
55const io = std.io;
6const fs = std.fs;
67const mem = std.mem;
78const File = std.fs.File;
89const Thread = std.Thread;
......@@ -14,9 +15,9 @@ const AtomicRmwOp = builtin.AtomicRmwOp;
1415const AtomicOrder = builtin.AtomicOrder;
1516
1617test "makePath, put some files in it, deleteTree" {
17 try os.makePath(a, "os_test_tmp" ++ os.path.sep_str ++ "b" ++ os.path.sep_str ++ "c");
18 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "b" ++ os.path.sep_str ++ "c" ++ os.path.sep_str ++ "file.txt", "nonsense");
19 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "b" ++ os.path.sep_str ++ "file2.txt", "blah");
18 try os.makePath(a, "os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");
19 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
20 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
2021 try os.deleteTree(a, "os_test_tmp");
2122 if (os.Dir.open(a, "os_test_tmp")) |dir| {
2223 @panic("expected error");
......@@ -27,14 +28,14 @@ test "makePath, put some files in it, deleteTree" {
2728
2829test "access file" {
2930 try os.makePath(a, "os_test_tmp");
30 if (File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt")) |ok| {
31 if (File.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt")) |ok| {
3132 @panic("expected error");
3233 } else |err| {
3334 expect(err == error.FileNotFound);
3435 }
3536
36 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "file.txt", "");
37 try File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt");
37 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
38 try File.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt");
3839 try os.deleteTree(a, "os_test_tmp");
3940}
4041
std/os/windows.zig+38-1
......@@ -4,6 +4,7 @@
44// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept
55// slices as well as APIs which accept null-terminated UTF16LE byte buffers.
66
7const builtin = @import("builtin");
78const std = @import("../std.zig");
89const assert = std.debug.assert;
910const maxInt = std.math.maxInt;
......@@ -1103,6 +1104,42 @@ pub fn VirtualFree(lpAddress: ?LPVOID, dwSize: usize, dwFreeType: DWORD) void {
11031104 assert(kernel32.VirtualFree(lpAddress, dwSize, dwFreeType) != 0);
11041105}
11051106
1107pub const SetConsoleTextAttributeError = error{Unexpected};
1108
1109pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetConsoleTextAttributeError!void {
1110 if (kernel32.SetConsoleTextAttribute(hConsoleOutput, wAttributes) == 0) {
1111 switch (kernel32.GetLastError()) {
1112 else => |err| return unexpectedError(err),
1113 }
1114 }
1115}
1116
1117pub const GetEnvironmentStringsError = error{OutOfMemory};
1118
1119pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*]u16 {
1120 return kernel32.GetEnvironmentStringsW() orelse return error.OutOfMemory;
1121}
1122
1123pub fn FreeEnvironmentStringsW(penv: [*]u16) void {
1124 assert(kernel32.FreeEnvironmentStringsW(penv) != 0);
1125}
1126
1127pub const GetEnvironmentVariableError = error{
1128 EnvironmentVariableNotFound,
1129 Unexpected,
1130};
1131
1132pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) GetEnvironmentVariableError!DWORD {
1133 const rc = kernel32.GetEnvironmentVariableW(lpName, lpBuffer, nSize);
1134 if (rc == 0) {
1135 switch (kernel32.GetLastError()) {
1136 ERROR.ENVVAR_NOT_FOUND => return error.EnvironmentVariableNotFound,
1137 else => |err| return unexpectedError(err),
1138 }
1139 }
1140 return rc;
1141}
1142
11061143pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
11071144 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
11081145}
......@@ -1127,7 +1164,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
11271164 else => {},
11281165 }
11291166 }
1130 const start_index = if (mem.startsWith(u8, s, "\\\\") or !os.path.isAbsolute(s)) 0 else blk: {
1167 const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {
11311168 const prefix = []u16{ '\\', '\\', '?', '\\' };
11321169 mem.copy(u16, result[0..], prefix);
11331170 break :blk prefix.len;
std/process.zig+41-27
......@@ -1,13 +1,17 @@
1const builtin = @import("builtin");
12const std = @import("std.zig");
23const os = std.os;
34const BufMap = std.BufMap;
45const mem = std.mem;
6const math = std.math;
57const Allocator = mem.Allocator;
68const assert = std.debug.assert;
79const testing = std.testing;
810
911pub const abort = os.abort;
1012pub const exit = os.exit;
13pub const changeCurDir = os.chdir;
14pub const changeCurDirC = os.chdirC;
1115
1216/// Caller must free result when done.
1317/// TODO make this go through libc when we have it
......@@ -15,9 +19,9 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
1519 var result = BufMap.init(allocator);
1620 errdefer result.deinit();
1721
18 if (is_windows) {
19 const ptr = windows.GetEnvironmentStringsW() orelse return error.OutOfMemory;
20 defer assert(windows.FreeEnvironmentStringsW(ptr) != 0);
22 if (os.windows.is_the_target) {
23 const ptr = try os.windows.GetEnvironmentStringsW();
24 defer os.windows.FreeEnvironmentStringsW(ptr);
2125
2226 var i: usize = 0;
2327 while (true) {
......@@ -105,7 +109,7 @@ pub const GetEnvVarOwnedError = error{
105109/// Caller must free returned memory.
106110/// TODO make this go through libc when we have it
107111pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 {
108 if (is_windows) {
112 if (os.windows.is_the_target) {
109113 const key_with_null = try std.unicode.utf8ToUtf16LeWithNull(allocator, key);
110114 defer allocator.free(key_with_null);
111115
......@@ -113,19 +117,15 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
113117 defer allocator.free(buf);
114118
115119 while (true) {
116 const windows_buf_len = math.cast(windows.DWORD, buf.len) catch return error.OutOfMemory;
117 const result = windows.GetEnvironmentVariableW(key_with_null.ptr, buf.ptr, windows_buf_len);
118
119 if (result == 0) {
120 const err = windows.GetLastError();
121 return switch (err) {
122 windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound,
123 else => {
124 windows.unexpectedError(err) catch {};
125 return error.EnvironmentVariableNotFound;
126 },
127 };
128 }
120 const windows_buf_len = math.cast(os.windows.DWORD, buf.len) catch return error.OutOfMemory;
121 const result = os.windows.GetEnvironmentVariableW(
122 key_with_null.ptr,
123 buf.ptr,
124 windows_buf_len,
125 ) catch |err| switch (err) {
126 error.Unexpected => return error.EnvironmentVariableNotFound,
127 else => return err,
128 };
129129
130130 if (result > buf.len) {
131131 buf = try allocator.realloc(buf, result);
......@@ -136,11 +136,11 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
136136 error.DanglingSurrogateHalf => return error.InvalidUtf8,
137137 error.ExpectedSecondSurrogateHalf => return error.InvalidUtf8,
138138 error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8,
139 error.OutOfMemory => return error.OutOfMemory,
139 else => return err,
140140 };
141141 }
142142 } else {
143 const result = getEnvPosix(key) orelse return error.EnvironmentVariableNotFound;
143 const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound;
144144 return mem.dupe(allocator, u8, result);
145145 }
146146}
......@@ -157,16 +157,16 @@ pub const ArgIteratorPosix = struct {
157157 pub fn init() ArgIteratorPosix {
158158 return ArgIteratorPosix{
159159 .index = 0,
160 .count = raw.len,
160 .count = os.argv.len,
161161 };
162162 }
163163
164164 pub fn next(self: *ArgIteratorPosix) ?[]const u8 {
165165 if (self.index == self.count) return null;
166166
167 const s = raw[self.index];
167 const s = os.argv[self.index];
168168 self.index += 1;
169 return cstr.toSlice(s);
169 return mem.toSlice(u8, s);
170170 }
171171
172172 pub fn skip(self: *ArgIteratorPosix) bool {
......@@ -175,10 +175,6 @@ pub const ArgIteratorPosix = struct {
175175 self.index += 1;
176176 return true;
177177 }
178
179 /// This is marked as public but actually it's only meant to be used
180 /// internally by zig's startup code.
181 pub var raw: [][*]u8 = undefined;
182178};
183179
184180pub const ArgIteratorWindows = struct {
......@@ -191,7 +187,7 @@ pub const ArgIteratorWindows = struct {
191187 pub const NextError = error{OutOfMemory};
192188
193189 pub fn init() ArgIteratorWindows {
194 return initWithCmdLine(windows.GetCommandLineA());
190 return initWithCmdLine(os.windows.kernel32.GetCommandLineA());
195191 }
196192
197193 pub fn initWithCmdLine(cmd_line: [*]const u8) ArgIteratorWindows {
......@@ -581,3 +577,21 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
581577 if (amt_read < buf.len) return error.UserNotFound;
582578 }
583579}
580
581pub fn getBaseAddress() usize {
582 switch (builtin.os) {
583 .linux => {
584 const base = os.system.getauxval(std.elf.AT_BASE);
585 if (base != 0) {
586 return base;
587 }
588 const phdr = os.system.getauxval(std.elf.AT_PHDR);
589 return phdr - @sizeOf(std.elf.Ehdr);
590 },
591 .macosx, .freebsd, .netbsd => {
592 return @ptrToInt(&std.c._mh_execute_header);
593 },
594 .windows => return @ptrToInt(os.windows.kernel32.GetModuleHandleW(null)),
595 else => @compileError("Unsupported OS"),
596 }
597}
std/special/bootstrap.zig+2-2
......@@ -78,7 +78,7 @@ fn posixCallMainAndExit() noreturn {
7878 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
7979 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
8080
81 if (builtin.os == builtin.Os.linux) {
81 if (builtin.os == .linux) {
8282 // Find the beginning of the auxiliary vector
8383 const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
8484 std.os.linux.elf_aux_maybe = auxv;
......@@ -98,7 +98,7 @@ fn posixCallMainAndExit() noreturn {
9898// This is marked inline because for some reason LLVM in release mode fails to inline it,
9999// and we want fewer call frames in stack traces.
100100inline fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
101 std.os.ArgIteratorPosix.raw = argv[0..argc];
101 std.os.argv = argv[0..argc];
102102 std.os.environ = envp;
103103 return callMain();
104104}
std/special/build_runner.zig+4-4
......@@ -3,15 +3,15 @@ const std = @import("std");
33const builtin = @import("builtin");
44const io = std.io;
55const fmt = std.fmt;
6const os = std.os;
76const Builder = std.build.Builder;
87const mem = std.mem;
8const process = std.process;
99const ArrayList = std.ArrayList;
1010const warn = std.debug.warn;
1111const File = std.fs.File;
1212
1313pub fn main() !void {
14 var arg_it = os.args();
14 var arg_it = process.args();
1515
1616 // Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,
1717 // one shot program. We don't need to waste time freeing memory and finding places to squish
......@@ -139,7 +139,7 @@ pub fn main() !void {
139139 error.InvalidStepName => {
140140 return usageAndErr(&builder, true, try stderr_stream);
141141 },
142 error.UncleanExit => os.exit(1),
142 error.UncleanExit => process.exit(1),
143143 else => return err,
144144 }
145145 };
......@@ -215,7 +215,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
215215
216216fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) void {
217217 usage(builder, already_ran_build, out_stream) catch {};
218 os.exit(1);
218 process.exit(1);
219219}
220220
221221const UnwrapArgError = error{OutOfMemory};
std/thread.zig+1-1
......@@ -227,7 +227,7 @@ pub const Thread = struct {
227227 var tls_start_offset: usize = undefined;
228228 const mmap_len = blk: {
229229 // First in memory will be the stack, which grows downwards.
230 var l: usize = mem.alignForward(default_stack_size, os.page_size);
230 var l: usize = mem.alignForward(default_stack_size, mem.page_size);
231231 stack_end_offset = l;
232232 // Above the stack, so that it can be in the same mmap call, put the Thread object.
233233 l = mem.alignForward(l, @alignOf(Thread));
test/cli.zig+21-19
......@@ -1,7 +1,9 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const os = std.os;
43const testing = std.testing;
4const process = std.process;
5const fs = std.fs;
6const ChildProcess = std.ChildProcess;
57
68var a: *std.mem.Allocator = undefined;
79
......@@ -12,7 +14,7 @@ pub fn main() !void {
1214 var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator);
1315 defer arena.deinit();
1416
15 var arg_it = os.args();
17 var arg_it = process.args();
1618
1719 // skip my own exe name
1820 _ = arg_it.skip();
......@@ -27,9 +29,9 @@ pub fn main() !void {
2729 std.debug.warn("Expected second argument to be cache root directory path\n");
2830 return error.InvalidArgs;
2931 });
30 const zig_exe = try os.path.resolve(a, [][]const u8{zig_exe_rel});
32 const zig_exe = try fs.path.resolve(a, [][]const u8{zig_exe_rel});
3133
32 const dir_path = try os.path.join(a, [][]const u8{ cache_root, "clitest" });
34 const dir_path = try fs.path.join(a, [][]const u8{ cache_root, "clitest" });
3335 const TestFn = fn ([]const u8, []const u8) anyerror!void;
3436 const test_fns = []TestFn{
3537 testZigInitLib,
......@@ -37,8 +39,8 @@ pub fn main() !void {
3739 testGodboltApi,
3840 };
3941 for (test_fns) |testFn| {
40 try os.deleteTree(a, dir_path);
41 try os.makeDir(dir_path);
42 try fs.deleteTree(a, dir_path);
43 try fs.makeDir(dir_path);
4244 try testFn(zig_exe, dir_path);
4345 }
4446}
......@@ -58,15 +60,15 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void {
5860 std.debug.warn("\n");
5961}
6062
61fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult {
63fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
6264 const max_output_size = 100 * 1024;
63 const result = os.ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
65 const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
6466 std.debug.warn("The following command failed:\n");
6567 printCmd(cwd, argv);
6668 return err;
6769 };
6870 switch (result.term) {
69 os.ChildProcess.Term.Exited => |code| {
71 .Exited => |code| {
7072 if (code != 0) {
7173 std.debug.warn("The following command exited with error code {}:\n", code);
7274 printCmd(cwd, argv);
......@@ -97,10 +99,10 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
9799}
98100
99101fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
100 if (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64) return;
102 if (builtin.os != .linux or builtin.arch != .x86_64) return;
101103
102 const example_zig_path = try os.path.join(a, [][]const u8{ dir_path, "example.zig" });
103 const example_s_path = try os.path.join(a, [][]const u8{ dir_path, "example.s" });
104 const example_zig_path = try fs.path.join(a, [][]const u8{ dir_path, "example.zig" });
105 const example_s_path = try fs.path.join(a, [][]const u8{ dir_path, "example.s" });
104106
105107 try std.io.writeFile(example_zig_path,
106108 \\// Type your code here, or load an example.
......@@ -114,13 +116,13 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
114116 );
115117
116118 const args = [][]const u8{
117 zig_exe, "build-obj",
118 "--cache-dir", dir_path,
119 "--name", "example",
120 "--output-dir", dir_path,
121 "--emit", "asm",
122 "-mllvm", "--x86-asm-syntax=intel",
123 "--strip", "--release-fast",
119 zig_exe, "build-obj",
120 "--cache-dir", dir_path,
121 "--name", "example",
122 "--output-dir", dir_path,
123 "--emit", "asm",
124 "-mllvm", "--x86-asm-syntax=intel",
125 "--strip", "--release-fast",
124126 example_zig_path, "--disable-gen-h",
125127 };
126128 _ = try exec(dir_path, args);
test/tests.zig+44-46
......@@ -2,11 +2,9 @@ const std = @import("std");
22const debug = std.debug;
33const warn = debug.warn;
44const build = std.build;
5const os = std.os;
6const StdIo = os.ChildProcess.StdIo;
7const Term = os.ChildProcess.Term;
85const Buffer = std.Buffer;
96const io = std.io;
7const fs = std.fs;
108const mem = std.mem;
119const fmt = std.fmt;
1210const ArrayList = std.ArrayList;
......@@ -30,19 +28,19 @@ const TestTarget = struct {
3028
3129const test_targets = []TestTarget{
3230 TestTarget{
33 .os = builtin.Os.linux,
34 .arch = builtin.Arch.x86_64,
35 .abi = builtin.Abi.gnu,
31 .os = .linux,
32 .arch = .x86_64,
33 .abi = .gnu,
3634 },
3735 TestTarget{
38 .os = builtin.Os.macosx,
39 .arch = builtin.Arch.x86_64,
40 .abi = builtin.Abi.gnu,
36 .os = .macosx,
37 .arch = .x86_64,
38 .abi = .gnu,
4139 },
4240 TestTarget{
43 .os = builtin.Os.windows,
44 .arch = builtin.Arch.x86_64,
45 .abi = builtin.Abi.msvc,
41 .os = .windows,
42 .arch = .x86_64,
43 .abi = .msvc,
4644 },
4745};
4846
......@@ -114,7 +112,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
114112 const exe = b.addExecutable("test-cli", "test/cli.zig");
115113 const run_cmd = exe.run();
116114 run_cmd.addArgs([][]const u8{
117 os.path.realAlloc(b.allocator, b.zig_exe) catch unreachable,
115 fs.path.realAlloc(b.allocator, b.zig_exe) catch unreachable,
118116 b.pathFromRoot(b.cache_root),
119117 });
120118
......@@ -301,12 +299,12 @@ pub const CompareOutputContext = struct {
301299
302300 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
303301
304 const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
302 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
305303 defer child.deinit();
306304
307 child.stdin_behavior = StdIo.Ignore;
308 child.stdout_behavior = StdIo.Pipe;
309 child.stderr_behavior = StdIo.Pipe;
305 child.stdin_behavior = .Ignore;
306 child.stdout_behavior = .Pipe;
307 child.stderr_behavior = .Pipe;
310308 child.env_map = b.env_map;
311309
312310 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
......@@ -324,7 +322,7 @@ pub const CompareOutputContext = struct {
324322 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
325323 };
326324 switch (term) {
327 Term.Exited => |code| {
325 .Exited => |code| {
328326 if (code != 0) {
329327 warn("Process {} exited with error code {}\n", full_exe_path, code);
330328 printInvocation(args.toSliceConst());
......@@ -383,13 +381,13 @@ pub const CompareOutputContext = struct {
383381
384382 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
385383
386 const child = os.ChildProcess.init([][]const u8{full_exe_path}, b.allocator) catch unreachable;
384 const child = std.ChildProcess.init([][]const u8{full_exe_path}, b.allocator) catch unreachable;
387385 defer child.deinit();
388386
389387 child.env_map = b.env_map;
390 child.stdin_behavior = StdIo.Ignore;
391 child.stdout_behavior = StdIo.Ignore;
392 child.stderr_behavior = StdIo.Ignore;
388 child.stdin_behavior = .Ignore;
389 child.stdout_behavior = .Ignore;
390 child.stderr_behavior = .Ignore;
393391
394392 const term = child.spawnAndWait() catch |err| {
395393 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
......@@ -397,13 +395,13 @@ pub const CompareOutputContext = struct {
397395
398396 const expected_exit_code: i32 = 126;
399397 switch (term) {
400 Term.Exited => |code| {
398 .Exited => |code| {
401399 if (code != expected_exit_code) {
402400 warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code);
403401 return error.TestFailed;
404402 }
405403 },
406 Term.Signal => |sig| {
404 .Signal => |sig| {
407405 warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig);
408406 return error.TestFailed;
409407 },
......@@ -459,7 +457,7 @@ pub const CompareOutputContext = struct {
459457 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
460458 const b = self.b;
461459
462 const root_src = os.path.join(
460 const root_src = fs.path.join(
463461 b.allocator,
464462 [][]const u8{ b.cache_root, case.sources.items[0].filename },
465463 ) catch unreachable;
......@@ -475,7 +473,7 @@ pub const CompareOutputContext = struct {
475473 exe.addAssemblyFile(root_src);
476474
477475 for (case.sources.toSliceConst()) |src_file| {
478 const expanded_src_path = os.path.join(
476 const expanded_src_path = fs.path.join(
479477 b.allocator,
480478 [][]const u8{ b.cache_root, src_file.filename },
481479 ) catch unreachable;
......@@ -507,7 +505,7 @@ pub const CompareOutputContext = struct {
507505 }
508506
509507 for (case.sources.toSliceConst()) |src_file| {
510 const expanded_src_path = os.path.join(
508 const expanded_src_path = fs.path.join(
511509 b.allocator,
512510 [][]const u8{ b.cache_root, src_file.filename },
513511 ) catch unreachable;
......@@ -538,7 +536,7 @@ pub const CompareOutputContext = struct {
538536 }
539537
540538 for (case.sources.toSliceConst()) |src_file| {
541 const expanded_src_path = os.path.join(
539 const expanded_src_path = fs.path.join(
542540 b.allocator,
543541 [][]const u8{ b.cache_root, src_file.filename },
544542 ) catch unreachable;
......@@ -633,7 +631,7 @@ pub const CompileErrorContext = struct {
633631 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
634632 const b = self.context.b;
635633
636 const root_src = os.path.join(
634 const root_src = fs.path.join(
637635 b.allocator,
638636 [][]const u8{ b.cache_root, self.case.sources.items[0].filename },
639637 ) catch unreachable;
......@@ -669,13 +667,13 @@ pub const CompileErrorContext = struct {
669667 printInvocation(zig_args.toSliceConst());
670668 }
671669
672 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
670 const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
673671 defer child.deinit();
674672
675673 child.env_map = b.env_map;
676 child.stdin_behavior = StdIo.Ignore;
677 child.stdout_behavior = StdIo.Pipe;
678 child.stderr_behavior = StdIo.Pipe;
674 child.stdin_behavior = .Ignore;
675 child.stdout_behavior = .Pipe;
676 child.stderr_behavior = .Pipe;
679677
680678 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
681679
......@@ -692,7 +690,7 @@ pub const CompileErrorContext = struct {
692690 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
693691 };
694692 switch (term) {
695 Term.Exited => |code| {
693 .Exited => |code| {
696694 if (code == 0) {
697695 printInvocation(zig_args.toSliceConst());
698696 return error.CompilationIncorrectlySucceeded;
......@@ -823,7 +821,7 @@ pub const CompileErrorContext = struct {
823821 self.step.dependOn(&compile_and_cmp_errors.step);
824822
825823 for (case.sources.toSliceConst()) |src_file| {
826 const expanded_src_path = os.path.join(
824 const expanded_src_path = fs.path.join(
827825 b.allocator,
828826 [][]const u8{ b.cache_root, src_file.filename },
829827 ) catch unreachable;
......@@ -858,7 +856,7 @@ pub const BuildExamplesContext = struct {
858856 }
859857
860858 var zig_args = ArrayList([]const u8).init(b.allocator);
861 const rel_zig_exe = os.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable;
859 const rel_zig_exe = fs.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable;
862860 zig_args.append(rel_zig_exe) catch unreachable;
863861 zig_args.append("build") catch unreachable;
864862
......@@ -958,7 +956,7 @@ pub const TranslateCContext = struct {
958956 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
959957 const b = self.context.b;
960958
961 const root_src = os.path.join(
959 const root_src = fs.path.join(
962960 b.allocator,
963961 [][]const u8{ b.cache_root, self.case.sources.items[0].filename },
964962 ) catch unreachable;
......@@ -976,13 +974,13 @@ pub const TranslateCContext = struct {
976974 printInvocation(zig_args.toSliceConst());
977975 }
978976
979 const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
977 const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
980978 defer child.deinit();
981979
982980 child.env_map = b.env_map;
983 child.stdin_behavior = StdIo.Ignore;
984 child.stdout_behavior = StdIo.Pipe;
985 child.stderr_behavior = StdIo.Pipe;
981 child.stdin_behavior = .Ignore;
982 child.stdout_behavior = .Pipe;
983 child.stderr_behavior = .Pipe;
986984
987985 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
988986
......@@ -999,14 +997,14 @@ pub const TranslateCContext = struct {
999997 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
1000998 };
1001999 switch (term) {
1002 Term.Exited => |code| {
1000 .Exited => |code| {
10031001 if (code != 0) {
10041002 warn("Compilation failed with exit code {}\n", code);
10051003 printInvocation(zig_args.toSliceConst());
10061004 return error.TestFailed;
10071005 }
10081006 },
1009 Term.Signal => |code| {
1007 .Signal => |code| {
10101008 warn("Compilation failed with signal {}\n", code);
10111009 printInvocation(zig_args.toSliceConst());
10121010 return error.TestFailed;
......@@ -1131,7 +1129,7 @@ pub const TranslateCContext = struct {
11311129 self.step.dependOn(&translate_c_and_cmp.step);
11321130
11331131 for (case.sources.toSliceConst()) |src_file| {
1134 const expanded_src_path = os.path.join(
1132 const expanded_src_path = fs.path.join(
11351133 b.allocator,
11361134 [][]const u8{ b.cache_root, src_file.filename },
11371135 ) catch unreachable;
......@@ -1254,7 +1252,7 @@ pub const GenHContext = struct {
12541252
12551253 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
12561254 const b = self.b;
1257 const root_src = os.path.join(
1255 const root_src = fs.path.join(
12581256 b.allocator,
12591257 [][]const u8{ b.cache_root, case.sources.items[0].filename },
12601258 ) catch unreachable;
......@@ -1269,7 +1267,7 @@ pub const GenHContext = struct {
12691267 obj.setBuildMode(mode);
12701268
12711269 for (case.sources.toSliceConst()) |src_file| {
1272 const expanded_src_path = os.path.join(
1270 const expanded_src_path = fs.path.join(
12731271 b.allocator,
12741272 [][]const u8{ b.cache_root, src_file.filename },
12751273 ) catch unreachable;