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");...@@ -2,28 +2,28 @@ const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const Builder = std.build.Builder;3const Builder = std.build.Builder;
4const tests = @import("test/tests.zig");4const tests = @import("test/tests.zig");
5const os = std.os;
6const BufMap = std.BufMap;5const BufMap = std.BufMap;
7const warn = std.debug.warn;6const warn = std.debug.warn;
8const mem = std.mem;7const mem = std.mem;
9const ArrayList = std.ArrayList;8const ArrayList = std.ArrayList;
10const Buffer = std.Buffer;9const Buffer = std.Buffer;
11const io = std.io;10const io = std.io;
11const fs = std.fs;
1212
13pub fn build(b: *Builder) !void {13pub fn build(b: *Builder) !void {
14 const mode = b.standardReleaseOptions();14 const mode = b.standardReleaseOptions();
1515
16 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");16 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);18 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
19 const langref_out_path = os.path.join(19 const langref_out_path = fs.path.join(
20 b.allocator,20 b.allocator,
21 [][]const u8{ b.cache_root, "langref.html" },21 [][]const u8{ b.cache_root, "langref.html" },
22 ) catch unreachable;22 ) catch unreachable;
23 var docgen_cmd = docgen_exe.run();23 var docgen_cmd = docgen_exe.run();
24 docgen_cmd.addArgs([][]const u8{24 docgen_cmd.addArgs([][]const u8{
25 rel_zig_exe,25 rel_zig_exe,
26 "doc" ++ os.path.sep_str ++ "langref.html.in",26 "doc" ++ fs.path.sep_str ++ "langref.html.in",
27 langref_out_path,27 langref_out_path,
28 });28 });
29 docgen_cmd.step.dependOn(&docgen_exe.step);29 docgen_cmd.step.dependOn(&docgen_exe.step);
...@@ -137,7 +137,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -137,7 +137,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
137 for (dep.libdirs.toSliceConst()) |lib_dir| {137 for (dep.libdirs.toSliceConst()) |lib_dir| {
138 lib_exe_obj.addLibPath(lib_dir);138 lib_exe_obj.addLibPath(lib_dir);
139 }139 }
140 const lib_dir = os.path.join(140 const lib_dir = fs.path.join(
141 b.allocator,141 b.allocator,
142 [][]const u8{ dep.prefix, "lib" },142 [][]const u8{ dep.prefix, "lib" },
143 ) catch unreachable;143 ) catch unreachable;
...@@ -146,7 +146,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -146,7 +146,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
146 ([]const u8)("libncurses.a")146 ([]const u8)("libncurses.a")
147 else147 else
148 b.fmt("lib{}.a", lib);148 b.fmt("lib{}.a", lib);
149 const static_lib_name = os.path.join(149 const static_lib_name = fs.path.join(
150 b.allocator,150 b.allocator,
151 [][]const u8{ lib_dir, static_bare_name },151 [][]const u8{ lib_dir, static_bare_name },
152 ) catch unreachable;152 ) catch unreachable;
...@@ -166,7 +166,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -166,7 +166,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
166}166}
167167
168fn fileExists(filename: []const u8) !bool {168fn fileExists(filename: []const u8) !bool {
169 os.File.access(filename) catch |err| switch (err) {169 fs.File.access(filename) catch |err| switch (err) {
170 error.PermissionDenied,170 error.PermissionDenied,
171 error.FileNotFound,171 error.FileNotFound,
172 => return false,172 => return false,
...@@ -177,7 +177,7 @@ fn fileExists(filename: []const u8) !bool {...@@ -177,7 +177,7 @@ fn fileExists(filename: []const u8) !bool {
177177
178fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {178fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
179 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";179 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{
181 cmake_binary_dir,181 cmake_binary_dir,
182 "zig_cpp",182 "zig_cpp",
183 b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()),183 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 {...@@ -223,7 +223,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
223 if (mem.startsWith(u8, lib_arg, "-l")) {223 if (mem.startsWith(u8, lib_arg, "-l")) {
224 try result.system_libs.append(lib_arg[2..]);224 try result.system_libs.append(lib_arg[2..]);
225 } else {225 } else {
226 if (os.path.isAbsolute(lib_arg)) {226 if (fs.path.isAbsolute(lib_arg)) {
227 try result.libs.append(lib_arg);227 try result.libs.append(lib_arg);
228 } else {228 } else {
229 try result.system_libs.append(lib_arg);229 try result.system_libs.append(lib_arg);
...@@ -257,8 +257,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {...@@ -257,8 +257,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
257pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {257pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
258 var it = mem.tokenize(stdlib_files, ";");258 var it = mem.tokenize(stdlib_files, ";");
259 while (it.next()) |stdlib_file| {259 while (it.next()) |stdlib_file| {
260 const src_path = os.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;260 const src_path = fs.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
261 const dest_path = os.path.join(261 const dest_path = fs.path.join(
262 b.allocator,262 b.allocator,
263 [][]const u8{ "lib", "zig", "std", stdlib_file },263 [][]const u8{ "lib", "zig", "std", stdlib_file },
264 ) catch unreachable;264 ) catch unreachable;
...@@ -269,8 +269,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {...@@ -269,8 +269,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
269pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {269pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
270 var it = mem.tokenize(c_header_files, ";");270 var it = mem.tokenize(c_header_files, ";");
271 while (it.next()) |c_header_file| {271 while (it.next()) |c_header_file| {
272 const src_path = os.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;272 const src_path = fs.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
273 const dest_path = os.path.join(273 const dest_path = fs.path.join(
274 b.allocator,274 b.allocator,
275 [][]const u8{ "lib", "zig", "include", c_header_file },275 [][]const u8{ "lib", "zig", "include", c_header_file },
276 ) catch unreachable;276 ) catch unreachable;
...@@ -315,7 +315,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {...@@ -315,7 +315,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
315 }315 }
316 dependOnLib(b, exe, ctx.llvm);316 dependOnLib(b, exe, ctx.llvm);
317317
318 if (exe.target.getOs() == builtin.Os.linux) {318 if (exe.target.getOs() == .linux) {
319 try addCxxKnownPath(b, ctx, exe, "libstdc++.a",319 try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
320 \\Unable to determine path to libstdc++.a320 \\Unable to determine path to libstdc++.a
321 \\On Fedora, install libstdc++-static and try again.321 \\On Fedora, install libstdc++-static and try again.
doc/docgen.zig+30-28
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const io = std.io;3const io = std.io;
4const os = std.os;4const fs = std.fs;
5const process = std.process;
6const ChildProcess = std.ChildProcess;
5const warn = std.debug.warn;7const warn = std.debug.warn;
6const mem = std.mem;8const mem = std.mem;
7const testing = std.testing;9const testing = std.testing;
...@@ -11,7 +13,7 @@ const max_doc_file_size = 10 * 1024 * 1024;...@@ -11,7 +13,7 @@ const max_doc_file_size = 10 * 1024 * 1024;
11const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();13const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
12const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();14const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
13const tmp_dir_name = "docgen_tmp";15const 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
16pub fn main() !void {18pub fn main() !void {
17 var direct_allocator = std.heap.DirectAllocator.init();19 var direct_allocator = std.heap.DirectAllocator.init();
...@@ -22,7 +24,7 @@ pub fn main() !void {...@@ -22,7 +24,7 @@ pub fn main() !void {
2224
23 const allocator = &arena.allocator;25 const allocator = &arena.allocator;
2426
25 var args_it = os.args();27 var args_it = process.args();
2628
27 if (!args_it.skip()) @panic("expected self arg");29 if (!args_it.skip()) @panic("expected self arg");
2830
...@@ -35,10 +37,10 @@ pub fn main() !void {...@@ -35,10 +37,10 @@ pub fn main() !void {
35 const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg"));37 const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg"));
36 defer allocator.free(out_file_name);38 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);
39 defer in_file.close();41 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);
42 defer out_file.close();44 defer out_file.close();
4345
44 var file_in_stream = in_file.inStream();46 var file_in_stream = in_file.inStream();
...@@ -46,13 +48,13 @@ pub fn main() !void {...@@ -46,13 +48,13 @@ pub fn main() !void {
46 const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size);48 const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size);
4749
48 var file_out_stream = out_file.outStream();50 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
51 var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);53 var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
52 var toc = try genToc(allocator, &tokenizer);54 var toc = try genToc(allocator, &tokenizer);
5355
54 try os.makePath(allocator, tmp_dir_name);56 try fs.makePath(allocator, tmp_dir_name);
55 defer os.deleteTree(allocator, tmp_dir_name) catch {};57 defer fs.deleteTree(allocator, tmp_dir_name) catch {};
5658
57 try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream, zig_exe);59 try genHtml(allocator, &tokenizer, &toc, &buffered_out_stream.stream, zig_exe);
58 try buffered_out_stream.flush();60 try buffered_out_stream.flush();
...@@ -950,7 +952,7 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token)...@@ -950,7 +952,7 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token)
950fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {952fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
951 var code_progress_index: usize = 0;953 var code_progress_index: usize = 0;
952954
953 var env_map = try os.getEnvMap(allocator);955 var env_map = try process.getEnvMap(allocator);
954 try env_map.set("ZIG_DEBUG_COLOR", "1");956 try env_map.set("ZIG_DEBUG_COLOR", "1");
955957
956 const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe);958 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...@@ -1012,7 +1014,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1012 try tokenizeAndPrint(tokenizer, out, code.source_token);1014 try tokenizeAndPrint(tokenizer, out, code.source_token);
1013 try out.write("</pre>");1015 try out.write("</pre>");
1014 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);1016 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(
1016 allocator,1018 allocator,
1017 [][]const u8{ tmp_dir_name, name_plus_ext },1019 [][]const u8{ tmp_dir_name, name_plus_ext },
1018 );1020 );
...@@ -1021,7 +1023,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1021,7 +1023,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1021 switch (code.id) {1023 switch (code.id) {
1022 Code.Id.Exe => |expected_outcome| code_block: {1024 Code.Id.Exe => |expected_outcome| code_block: {
1023 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);1025 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(
1025 allocator,1027 allocator,
1026 [][]const u8{ tmp_dir_name, name_plus_bin_ext },1028 [][]const u8{ tmp_dir_name, name_plus_bin_ext },
1027 );1029 );
...@@ -1056,7 +1058,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1056,7 +1058,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1056 }1058 }
1057 for (code.link_objects) |link_object| {1059 for (code.link_objects) |link_object| {
1058 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);1060 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(
1060 allocator,1062 allocator,
1061 [][]const u8{ tmp_dir_name, name_with_ext },1063 [][]const u8{ tmp_dir_name, name_with_ext },
1062 );1064 );
...@@ -1076,7 +1078,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1076,7 +1078,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1076 }1078 }
1077 }1079 }
1078 if (expected_outcome == .BuildFail) {1080 if (expected_outcome == .BuildFail) {
1079 const result = try os.ChildProcess.exec(1081 const result = try ChildProcess.exec(
1080 allocator,1082 allocator,
1081 build_args.toSliceConst(),1083 build_args.toSliceConst(),
1082 null,1084 null,
...@@ -1084,7 +1086,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1084,7 +1086,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1084 max_doc_file_size,1086 max_doc_file_size,
1085 );1087 );
1086 switch (result.term) {1088 switch (result.term) {
1087 os.ChildProcess.Term.Exited => |exit_code| {1089 .Exited => |exit_code| {
1088 if (exit_code == 0) {1090 if (exit_code == 0) {
1089 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1091 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
1090 for (build_args.toSliceConst()) |arg|1092 for (build_args.toSliceConst()) |arg|
...@@ -1113,7 +1115,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1113,7 +1115,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1113 if (code.target_str) |triple| {1115 if (code.target_str) |triple| {
1114 if (mem.startsWith(u8, triple, "wasm32") or1116 if (mem.startsWith(u8, triple, "wasm32") or
1115 mem.startsWith(u8, triple, "x86_64-linux") and1117 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))
1117 {1119 {
1118 // skip execution1120 // skip execution
1119 try out.print("</code></pre>\n");1121 try out.print("</code></pre>\n");
...@@ -1124,9 +1126,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1124,9 +1126,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1124 const run_args = [][]const u8{tmp_bin_file_name};1126 const run_args = [][]const u8{tmp_bin_file_name};
11251127
1126 const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {1128 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);
1128 switch (result.term) {1130 switch (result.term) {
1129 os.ChildProcess.Term.Exited => |exit_code| {1131 .Exited => |exit_code| {
1130 if (exit_code == 0) {1132 if (exit_code == 0) {
1131 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1133 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
1132 for (run_args) |arg|1134 for (run_args) |arg|
...@@ -1216,9 +1218,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1216,9 +1218,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1216 try out.print(" --release-small");1218 try out.print(" --release-small");
1217 },1219 },
1218 }1220 }
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);
1220 switch (result.term) {1222 switch (result.term) {
1221 os.ChildProcess.Term.Exited => |exit_code| {1223 .Exited => |exit_code| {
1222 if (exit_code == 0) {1224 if (exit_code == 0) {
1223 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1225 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
1224 for (test_args.toSliceConst()) |arg|1226 for (test_args.toSliceConst()) |arg|
...@@ -1274,9 +1276,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1274,9 +1276,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1274 },1276 },
1275 }1277 }
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);
1278 switch (result.term) {1280 switch (result.term) {
1279 os.ChildProcess.Term.Exited => |exit_code| {1281 .Exited => |exit_code| {
1280 if (exit_code == 0) {1282 if (exit_code == 0) {
1281 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1283 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
1282 for (test_args.toSliceConst()) |arg|1284 for (test_args.toSliceConst()) |arg|
...@@ -1310,7 +1312,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1310,7 +1312,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1310 },1312 },
1311 Code.Id.Obj => |maybe_error_match| {1313 Code.Id.Obj => |maybe_error_match| {
1312 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);1314 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(
1314 allocator,1316 allocator,
1315 [][]const u8{ tmp_dir_name, name_plus_obj_ext },1317 [][]const u8{ tmp_dir_name, name_plus_obj_ext },
1316 );1318 );
...@@ -1318,7 +1320,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1318,7 +1320,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1318 defer build_args.deinit();1320 defer build_args.deinit();
13191321
1320 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);1322 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(
1322 allocator,1324 allocator,
1323 [][]const u8{ tmp_dir_name, name_plus_h_ext },1325 [][]const u8{ tmp_dir_name, name_plus_h_ext },
1324 );1326 );
...@@ -1367,9 +1369,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1367,9 +1369,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1367 }1369 }
13681370
1369 if (maybe_error_match) |error_match| {1371 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);
1371 switch (result.term) {1373 switch (result.term) {
1372 os.ChildProcess.Term.Exited => |exit_code| {1374 .Exited => |exit_code| {
1373 if (exit_code == 0) {1375 if (exit_code == 0) {
1374 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1376 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);
1375 for (build_args.toSliceConst()) |arg|1377 for (build_args.toSliceConst()) |arg|
...@@ -1448,10 +1450,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1448,10 +1450,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1448 }1450 }
1449}1451}
14501452
1451fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !os.ChildProcess.ExecResult {1453fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
1452 const result = try os.ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);1454 const result = try ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);
1453 switch (result.term) {1455 switch (result.term) {
1454 os.ChildProcess.Term.Exited => |exit_code| {1456 .Exited => |exit_code| {
1455 if (exit_code != 0) {1457 if (exit_code != 0) {
1456 warn("{}\nThe following command exited with code {}:\n", result.stderr, exit_code);1458 warn("{}\nThe following command exited with code {}:\n", result.stderr, exit_code);
1457 for (args) |arg|1459 for (args) |arg|
doc/langref.html.in+1-1
...@@ -195,7 +195,7 @@ const std = @import("std");...@@ -195,7 +195,7 @@ const std = @import("std");
195195
196pub fn main() !void {196pub fn main() !void {
197 // If this program is run without stdout attached, exit with an error.197 // 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();
199 // If this program encounters pipe failure when printing to stdout, exit199 // If this program encounters pipe failure when printing to stdout, exit
200 // with an error.200 // with an error.
201 try stdout_file.write("Hello, world!\n");201 try stdout_file.write("Hello, world!\n");
src-self-hosted/compilation.zig+11-12
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const os = std.os;
3const io = std.io;2const io = std.io;
4const mem = std.mem;3const mem = std.mem;
5const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
...@@ -54,7 +53,7 @@ pub const ZigCompiler = struct {...@@ -54,7 +53,7 @@ pub const ZigCompiler = struct {
54 };53 };
5554
56 var seed_bytes: [@sizeOf(u64)]u8 = undefined;55 var seed_bytes: [@sizeOf(u64)]u8 = undefined;
57 try std.os.getRandomBytes(seed_bytes[0..]);56 try std.crypto.randomBytes(seed_bytes[0..]);
58 const seed = mem.readIntNative(u64, &seed_bytes);57 const seed = mem.readIntNative(u64, &seed_bytes);
5958
60 return ZigCompiler{59 return ZigCompiler{
...@@ -487,7 +486,7 @@ pub const Compilation = struct {...@@ -487,7 +486,7 @@ pub const Compilation = struct {
487 comp.name = try Buffer.init(comp.arena(), name);486 comp.name = try Buffer.init(comp.arena(), name);
488 comp.llvm_triple = try target.getTriple(comp.arena());487 comp.llvm_triple = try target.getTriple(comp.arena());
489 comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple);488 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
492 const opt_level = switch (build_mode) {491 const opt_level = switch (build_mode) {
493 builtin.Mode.Debug => llvm.CodeGenLevelNone,492 builtin.Mode.Debug => llvm.CodeGenLevelNone,
...@@ -529,8 +528,8 @@ pub const Compilation = struct {...@@ -529,8 +528,8 @@ pub const Compilation = struct {
529 defer comp.events.destroy();528 defer comp.events.destroy();
530529
531 if (root_src_path) |root_src| {530 if (root_src_path) |root_src| {
532 const dirname = std.os.path.dirname(root_src) orelse ".";531 const dirname = std.fs.path.dirname(root_src) orelse ".";
533 const basename = std.os.path.basename(root_src);532 const basename = std.fs.path.basename(root_src);
534533
535 comp.root_package = try Package.create(comp.arena(), dirname, basename);534 comp.root_package = try Package.create(comp.arena(), dirname, basename);
536 comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");535 comp.std_package = try Package.create(comp.arena(), comp.zig_std_dir, "std.zig");
...@@ -558,7 +557,7 @@ pub const Compilation = struct {...@@ -558,7 +557,7 @@ pub const Compilation = struct {
558557
559 if (comp.tmp_dir.getOrNull()) |tmp_dir_result| if (tmp_dir_result.*) |tmp_dir| {558 if (comp.tmp_dir.getOrNull()) |tmp_dir_result| if (tmp_dir_result.*) |tmp_dir| {
560 // TODO evented I/O?559 // TODO evented I/O?
561 os.deleteTree(comp.arena(), tmp_dir) catch {};560 std.fs.deleteTree(comp.arena(), tmp_dir) catch {};
562 } else |_| {};561 } else |_| {};
563 }562 }
564563
...@@ -970,8 +969,8 @@ pub const Compilation = struct {...@@ -970,8 +969,8 @@ pub const Compilation = struct {
970 async fn initialCompile(self: *Compilation) !void {969 async fn initialCompile(self: *Compilation) !void {
971 if (self.root_src_path) |root_src_path| {970 if (self.root_src_path) |root_src_path| {
972 const root_scope = blk: {971 const root_scope = blk: {
973 // TODO async/await os.path.real972 // TODO async/await std.fs.realpath
974 const root_src_real_path = os.path.realAlloc(self.gpa(), root_src_path) catch |err| {973 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
975 try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));974 try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));
976 return;975 return;
977 };976 };
...@@ -1196,7 +1195,7 @@ pub const Compilation = struct {...@@ -1196,7 +1195,7 @@ pub const Compilation = struct {
1196 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);1195 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
1197 defer self.gpa().free(file_name);1196 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..] });
1200 errdefer self.gpa().free(full_path);1199 errdefer self.gpa().free(full_path);
12011200
1202 return Buffer.fromOwnedSlice(self.gpa(), full_path);1201 return Buffer.fromOwnedSlice(self.gpa(), full_path);
...@@ -1217,8 +1216,8 @@ pub const Compilation = struct {...@@ -1217,8 +1216,8 @@ pub const Compilation = struct {
1217 const zig_dir_path = try getZigDir(self.gpa());1216 const zig_dir_path = try getZigDir(self.gpa());
1218 defer self.gpa().free(zig_dir_path);1217 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..] });1219 const tmp_dir = try std.fs.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] });
1221 try os.makePath(self.gpa(), tmp_dir);1220 try std.fs.makePath(self.gpa(), tmp_dir);
1222 return tmp_dir;1221 return tmp_dir;
1223 }1222 }
12241223
...@@ -1384,7 +1383,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {...@@ -1384,7 +1383,7 @@ async fn addFnToLinkSet(comp: *Compilation, fn_val: *Value.Fn) void {
1384}1383}
13851384
1386fn getZigDir(allocator: *mem.Allocator) ![]u8 {1385fn getZigDir(allocator: *mem.Allocator) ![]u8 {
1387 return os.getAppDataDir(allocator, "zig");1386 return std.fs.getAppDataDir(allocator, "zig");
1388}1387}
13891388
1390async fn analyzeFnType(1389async fn analyzeFnType(
src-self-hosted/errmsg.zig+5-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const mem = std.mem;2const mem = std.mem;
3const os = std.os;3const fs = std.fs;
4const process = std.process;
4const Token = std.zig.Token;5const Token = std.zig.Token;
5const ast = std.zig.ast;6const ast = std.zig.ast;
6const TokenIndex = std.zig.ast.TokenIndex;7const TokenIndex = std.zig.ast.TokenIndex;
...@@ -239,10 +240,10 @@ pub const Msg = struct {...@@ -239,10 +240,10 @@ pub const Msg = struct {
239 const allocator = msg.getAllocator();240 const allocator = msg.getAllocator();
240 const tree = msg.getTree();241 const tree = msg.getTree();
241242
242 const cwd = try os.getCwdAlloc(allocator);243 const cwd = try process.getCwdAlloc(allocator);
243 defer allocator.free(cwd);244 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);
246 defer allocator.free(relpath);247 defer allocator.free(relpath);
247248
248 const path = if (relpath.len < msg.realpath.len) relpath else msg.realpath;249 const path = if (relpath.len < msg.realpath.len) relpath else msg.realpath;
...@@ -276,7 +277,7 @@ pub const Msg = struct {...@@ -276,7 +277,7 @@ pub const Msg = struct {
276 try stream.write("\n");277 try stream.write("\n");
277 }278 }
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 {
280 const color_on = switch (color) {281 const color_on = switch (color) {
281 Color.Auto => file.isTty(),282 Color.Auto => file.isTty(),
282 Color.On => true,283 Color.On => true,
src-self-hosted/introspect.zig+6-6
...@@ -2,19 +2,19 @@...@@ -2,19 +2,19 @@
22
3const std = @import("std");3const std = @import("std");
4const mem = std.mem;4const mem = std.mem;
5const os = std.os;5const fs = std.fs;
66
7const warn = std.debug.warn;7const warn = std.debug.warn;
88
9/// Caller must free result9/// Caller must free result
10pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {10pub 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" });
12 errdefer allocator.free(test_zig_dir);12 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" });
15 defer allocator.free(test_index_file);15 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);
18 file.close();18 file.close();
1919
20 return test_zig_dir;20 return test_zig_dir;
...@@ -22,12 +22,12 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![...@@ -22,12 +22,12 @@ pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![
2222
23/// Caller must free result23/// Caller must free result
24pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {24pub fn findZigLibDir(allocator: *mem.Allocator) ![]u8 {
25 const self_exe_path = try os.selfExeDirPathAlloc(allocator);25 const self_exe_path = try fs.selfExeDirPathAlloc(allocator);
26 defer allocator.free(self_exe_path);26 defer allocator.free(self_exe_path);
2727
28 var cur_path: []const u8 = self_exe_path;28 var cur_path: []const u8 = self_exe_path;
29 while (true) {29 while (true) {
30 const test_dir = os.path.dirname(cur_path) orelse ".";30 const test_dir = fs.path.dirname(cur_path) orelse ".";
3131
32 if (mem.eql(u8, test_dir, cur_path)) {32 if (mem.eql(u8, test_dir, cur_path)) {
33 break;33 break;
src-self-hosted/libc_installation.zig+18-17
...@@ -3,6 +3,7 @@ const builtin = @import("builtin");...@@ -3,6 +3,7 @@ const builtin = @import("builtin");
3const event = std.event;3const event = std.event;
4const Target = @import("target.zig").Target;4const Target = @import("target.zig").Target;
5const c = @import("c.zig");5const c = @import("c.zig");
6const fs = std.fs;
67
7/// See the render function implementation for documentation of the fields.8/// See the render function implementation for documentation of the fields.
8pub const LibCInstallation = struct {9pub const LibCInstallation = struct {
...@@ -30,7 +31,7 @@ pub const LibCInstallation = struct {...@@ -30,7 +31,7 @@ pub const LibCInstallation = struct {
30 self: *LibCInstallation,31 self: *LibCInstallation,
31 allocator: *std.mem.Allocator,32 allocator: *std.mem.Allocator,
32 libc_file: []const u8,33 libc_file: []const u8,
33 stderr: *std.io.OutStream(std.os.File.WriteError),34 stderr: *std.io.OutStream(fs.File.WriteError),
34 ) !void {35 ) !void {
35 self.initEmpty();36 self.initEmpty();
3637
...@@ -100,7 +101,7 @@ pub const LibCInstallation = struct {...@@ -100,7 +101,7 @@ pub const LibCInstallation = struct {
100 }101 }
101 }102 }
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 {
104 @setEvalBranchQuota(4000);105 @setEvalBranchQuota(4000);
105 try out.print(106 try out.print(
106 \\# The directory that contains `stdlib.h`.107 \\# The directory that contains `stdlib.h`.
...@@ -148,7 +149,7 @@ pub const LibCInstallation = struct {...@@ -148,7 +149,7 @@ pub const LibCInstallation = struct {
148 errdefer if (windows_sdk) |sdk| c.zig_free_windows_sdk(@ptrCast(?[*]c.ZigWindowsSDK, sdk));149 errdefer if (windows_sdk) |sdk| c.zig_free_windows_sdk(@ptrCast(?[*]c.ZigWindowsSDK, sdk));
149150
150 switch (builtin.os) {151 switch (builtin.os) {
151 builtin.Os.windows => {152 .windows => {
152 var sdk: *c.ZigWindowsSDK = undefined;153 var sdk: *c.ZigWindowsSDK = undefined;
153 switch (c.zig_find_windows_sdk(@ptrCast(?[*]?[*]c.ZigWindowsSDK, &sdk))) {154 switch (c.zig_find_windows_sdk(@ptrCast(?[*]?[*]c.ZigWindowsSDK, &sdk))) {
154 c.ZigFindWindowsSdkError.None => {155 c.ZigFindWindowsSdkError.None => {
...@@ -166,13 +167,13 @@ pub const LibCInstallation = struct {...@@ -166,13 +167,13 @@ pub const LibCInstallation = struct {
166 c.ZigFindWindowsSdkError.PathTooLong => return error.NotFound,167 c.ZigFindWindowsSdkError.PathTooLong => return error.NotFound,
167 }168 }
168 },169 },
169 builtin.Os.linux => {170 .linux => {
170 try group.call(findNativeIncludeDirLinux, self, loop);171 try group.call(findNativeIncludeDirLinux, self, loop);
171 try group.call(findNativeLibDirLinux, self, loop);172 try group.call(findNativeLibDirLinux, self, loop);
172 try group.call(findNativeStaticLibDir, self, loop);173 try group.call(findNativeStaticLibDir, self, loop);
173 try group.call(findNativeDynamicLinker, self, loop);174 try group.call(findNativeDynamicLinker, self, loop);
174 },175 },
175 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {176 .macosx, .freebsd, .netbsd => {
176 self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include");177 self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include");
177 },178 },
178 else => @compileError("unimplemented: find libc for this OS"),179 else => @compileError("unimplemented: find libc for this OS"),
...@@ -181,7 +182,7 @@ pub const LibCInstallation = struct {...@@ -181,7 +182,7 @@ pub const LibCInstallation = struct {
181 }182 }
182183
183 async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void {184 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";
185 const argv = []const []const u8{186 const argv = []const []const u8{
186 cc_exe,187 cc_exe,
187 "-E",188 "-E",
...@@ -190,7 +191,7 @@ pub const LibCInstallation = struct {...@@ -190,7 +191,7 @@ pub const LibCInstallation = struct {
190 "/dev/null",191 "/dev/null",
191 };192 };
192 // TODO make this use event loop193 // 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);
194 const exec_result = if (std.debug.runtime_safety) blk: {195 const exec_result = if (std.debug.runtime_safety) blk: {
195 break :blk errorable_result catch unreachable;196 break :blk errorable_result catch unreachable;
196 } else blk: {197 } else blk: {
...@@ -205,7 +206,7 @@ pub const LibCInstallation = struct {...@@ -205,7 +206,7 @@ pub const LibCInstallation = struct {
205 }206 }
206207
207 switch (exec_result.term) {208 switch (exec_result.term) {
208 std.os.ChildProcess.Term.Exited => |code| {209 std.ChildProcess.Term.Exited => |code| {
209 if (code != 0) return error.CCompilerExitCode;210 if (code != 0) return error.CCompilerExitCode;
210 },211 },
211 else => {212 else => {
...@@ -230,7 +231,7 @@ pub const LibCInstallation = struct {...@@ -230,7 +231,7 @@ pub const LibCInstallation = struct {
230 while (path_i < search_paths.len) : (path_i += 1) {231 while (path_i < search_paths.len) : (path_i += 1) {
231 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);232 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
232 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");233 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" });
234 defer loop.allocator.free(stdlib_path);235 defer loop.allocator.free(stdlib_path);
235236
236 if (try fileExists(stdlib_path)) {237 if (try fileExists(stdlib_path)) {
...@@ -254,7 +255,7 @@ pub const LibCInstallation = struct {...@@ -254,7 +255,7 @@ pub const LibCInstallation = struct {
254 const stream = &std.io.BufferOutStream.init(&result_buf).stream;255 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
255 try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);256 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(
258 loop.allocator,259 loop.allocator,
259 [][]const u8{ result_buf.toSliceConst(), "stdlib.h" },260 [][]const u8{ result_buf.toSliceConst(), "stdlib.h" },
260 );261 );
...@@ -286,7 +287,7 @@ pub const LibCInstallation = struct {...@@ -286,7 +287,7 @@ pub const LibCInstallation = struct {
286 builtin.Arch.aarch64 => try stream.write("arm"),287 builtin.Arch.aarch64 => try stream.write("arm"),
287 else => return error.UnsupportedArchitecture,288 else => return error.UnsupportedArchitecture,
288 }289 }
289 const ucrt_lib_path = try std.os.path.join(290 const ucrt_lib_path = try fs.path.join(
290 loop.allocator,291 loop.allocator,
291 [][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },292 [][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },
292 );293 );
...@@ -364,7 +365,7 @@ pub const LibCInstallation = struct {...@@ -364,7 +365,7 @@ pub const LibCInstallation = struct {
364 builtin.Arch.aarch64 => try stream.write("arm\\"),365 builtin.Arch.aarch64 => try stream.write("arm\\"),
365 else => return error.UnsupportedArchitecture,366 else => return error.UnsupportedArchitecture,
366 }367 }
367 const kernel32_path = try std.os.path.join(368 const kernel32_path = try fs.path.join(
368 loop.allocator,369 loop.allocator,
369 [][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },370 [][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },
370 );371 );
...@@ -391,14 +392,14 @@ pub const LibCInstallation = struct {...@@ -391,14 +392,14 @@ pub const LibCInstallation = struct {
391392
392/// caller owns returned memory393/// caller owns returned memory
393async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bool) ![]u8 {394async 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";
395 const arg1 = try std.fmt.allocPrint(loop.allocator, "-print-file-name={}", o_file);396 const arg1 = try std.fmt.allocPrint(loop.allocator, "-print-file-name={}", o_file);
396 defer loop.allocator.free(arg1);397 defer loop.allocator.free(arg1);
397 const argv = []const []const u8{ cc_exe, arg1 };398 const argv = []const []const u8{ cc_exe, arg1 };
398399
399 // TODO This simulates evented I/O for the child process exec400 // TODO This simulates evented I/O for the child process exec
400 await (async loop.yield() catch unreachable);401 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);
402 const exec_result = if (std.debug.runtime_safety) blk: {403 const exec_result = if (std.debug.runtime_safety) blk: {
403 break :blk errorable_result catch unreachable;404 break :blk errorable_result catch unreachable;
404 } else blk: {405 } else blk: {
...@@ -412,7 +413,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo...@@ -412,7 +413,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
412 loop.allocator.free(exec_result.stderr);413 loop.allocator.free(exec_result.stderr);
413 }414 }
414 switch (exec_result.term) {415 switch (exec_result.term) {
415 std.os.ChildProcess.Term.Exited => |code| {416 .Exited => |code| {
416 if (code != 0) return error.CCompilerExitCode;417 if (code != 0) return error.CCompilerExitCode;
417 },418 },
418 else => {419 else => {
...@@ -421,7 +422,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo...@@ -421,7 +422,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
421 }422 }
422 var it = std.mem.tokenize(exec_result.stdout, "\n\r");423 var it = std.mem.tokenize(exec_result.stdout, "\n\r");
423 const line = it.next() orelse return error.LibCRuntimeNotFound;424 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
426 if (want_dirname) {427 if (want_dirname) {
427 return std.mem.dupe(loop.allocator, u8, dirname);428 return std.mem.dupe(loop.allocator, u8, dirname);
...@@ -459,7 +460,7 @@ fn fillSearch(search_buf: *[2]Search, sdk: *c.ZigWindowsSDK) []Search {...@@ -459,7 +460,7 @@ fn fillSearch(search_buf: *[2]Search, sdk: *c.ZigWindowsSDK) []Search {
459}460}
460461
461fn fileExists(path: []const u8) !bool {462fn fileExists(path: []const u8) !bool {
462 if (std.os.File.access(path)) |_| {463 if (fs.File.access(path)) |_| {
463 return true;464 return true;
464 } else |err| switch (err) {465 } else |err| switch (err) {
465 error.FileNotFound, error.PermissionDenied => return false,466 error.FileNotFound, error.PermissionDenied => return false,
src-self-hosted/link.zig+3-3
...@@ -302,7 +302,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -302,7 +302,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
302 try ctx.args.append(c"--allow-shlib-undefined");302 try ctx.args.append(c"--allow-shlib-undefined");
303 }303 }
304304
305 if (ctx.comp.target.getOs() == builtin.Os.zen) {305 if (ctx.comp.target.getOs() == .zen) {
306 try ctx.args.append(c"-e");306 try ctx.args.append(c"-e");
307 try ctx.args.append(c"_start");307 try ctx.args.append(c"_start");
308308
...@@ -311,7 +311,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -311,7 +311,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
311}311}
312312
313fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {313fn 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 });
315 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);315 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
316 try ctx.args.append(full_path_with_null.ptr);316 try ctx.args.append(full_path_with_null.ptr);
317}317}
...@@ -668,7 +668,7 @@ const DarwinPlatform = struct {...@@ -668,7 +668,7 @@ const DarwinPlatform = struct {
668 break :blk ver;668 break :blk ver;
669 },669 },
670 Compilation.DarwinVersionMin.None => blk: {670 Compilation.DarwinVersionMin.None => blk: {
671 assert(comp.target.getOs() == builtin.Os.macosx);671 assert(comp.target.getOs() == .macosx);
672 result.kind = Kind.MacOS;672 result.kind = Kind.MacOS;
673 break :blk "10.10";673 break :blk "10.10";
674 },674 },
src-self-hosted/main.zig+41-39
...@@ -4,7 +4,9 @@ const builtin = @import("builtin");...@@ -4,7 +4,9 @@ const builtin = @import("builtin");
4const event = std.event;4const event = std.event;
5const os = std.os;5const os = std.os;
6const io = std.io;6const io = std.io;
7const fs = std.fs;
7const mem = std.mem;8const mem = std.mem;
9const process = std.process;
8const Allocator = mem.Allocator;10const Allocator = mem.Allocator;
9const ArrayList = std.ArrayList;11const ArrayList = std.ArrayList;
10const Buffer = std.Buffer;12const Buffer = std.Buffer;
...@@ -20,9 +22,9 @@ const Target = @import("target.zig").Target;...@@ -20,9 +22,9 @@ const Target = @import("target.zig").Target;
20const errmsg = @import("errmsg.zig");22const errmsg = @import("errmsg.zig");
21const LibCInstallation = @import("libc_installation.zig").LibCInstallation;23const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
2224
23var stderr_file: os.File = undefined;25var stderr_file: fs.File = undefined;
24var stderr: *io.OutStream(os.File.WriteError) = undefined;26var stderr: *io.OutStream(fs.File.WriteError) = undefined;
25var stdout: *io.OutStream(os.File.WriteError) = undefined;27var stdout: *io.OutStream(fs.File.WriteError) = undefined;
2628
27pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB29pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB
2830
...@@ -62,14 +64,14 @@ pub fn main() !void {...@@ -62,14 +64,14 @@ pub fn main() !void {
62 var stderr_out_stream = stderr_file.outStream();64 var stderr_out_stream = stderr_file.outStream();
63 stderr = &stderr_out_stream.stream;65 stderr = &stderr_out_stream.stream;
6466
65 const args = try os.argsAlloc(allocator);67 const args = try process.argsAlloc(allocator);
66 // TODO I'm getting unreachable code here, which shouldn't happen68 // TODO I'm getting unreachable code here, which shouldn't happen
67 //defer os.argsFree(allocator, args);69 //defer process.argsFree(allocator, args);
6870
69 if (args.len <= 1) {71 if (args.len <= 1) {
70 try stderr.write("expected command argument\n\n");72 try stderr.write("expected command argument\n\n");
71 try stderr.write(usage);73 try stderr.write(usage);
72 os.exit(1);74 process.exit(1);
73 }75 }
7476
75 const commands = []Command{77 const commands = []Command{
...@@ -125,7 +127,7 @@ pub fn main() !void {...@@ -125,7 +127,7 @@ pub fn main() !void {
125127
126 try stderr.print("unknown command: {}\n\n", args[1]);128 try stderr.print("unknown command: {}\n\n", args[1]);
127 try stderr.write(usage);129 try stderr.write(usage);
128 os.exit(1);130 process.exit(1);
129}131}
130132
131const usage_build_generic =133const usage_build_generic =
...@@ -256,7 +258,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -256,7 +258,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
256258
257 if (flags.present("help")) {259 if (flags.present("help")) {
258 try stdout.write(usage_build_generic);260 try stdout.write(usage_build_generic);
259 os.exit(0);261 process.exit(0);
260 }262 }
261263
262 const build_mode = blk: {264 const build_mode = blk: {
...@@ -324,14 +326,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -324,14 +326,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
324 cur_pkg = parent;326 cur_pkg = parent;
325 } else {327 } else {
326 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");328 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");
327 os.exit(1);329 process.exit(1);
328 }330 }
329 }331 }
330 }332 }
331333
332 if (cur_pkg.parent != null) {334 if (cur_pkg.parent != null) {
333 try stderr.print("unmatched --pkg-begin\n");335 try stderr.print("unmatched --pkg-begin\n");
334 os.exit(1);336 process.exit(1);
335 }337 }
336338
337 const provided_name = flags.single("name");339 const provided_name = flags.single("name");
...@@ -340,18 +342,18 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -340,18 +342,18 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
340 1 => flags.positionals.at(0),342 1 => flags.positionals.at(0),
341 else => {343 else => {
342 try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));344 try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));
343 os.exit(1);345 process.exit(1);
344 },346 },
345 };347 };
346348
347 const root_name = if (provided_name) |n| n else blk: {349 const root_name = if (provided_name) |n| n else blk: {
348 if (root_source_file) |file| {350 if (root_source_file) |file| {
349 const basename = os.path.basename(file);351 const basename = fs.path.basename(file);
350 var it = mem.separate(basename, ".");352 var it = mem.separate(basename, ".");
351 break :blk it.next() orelse basename;353 break :blk it.next() orelse basename;
352 } else {354 } else {
353 try stderr.write("--name [name] not provided and unable to infer\n");355 try stderr.write("--name [name] not provided and unable to infer\n");
354 os.exit(1);356 process.exit(1);
355 }357 }
356 };358 };
357359
...@@ -361,12 +363,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -361,12 +363,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
361 const link_objects = flags.many("object");363 const link_objects = flags.many("object");
362 if (root_source_file == null and link_objects.len == 0 and assembly_files.len == 0) {364 if (root_source_file == null and link_objects.len == 0 and assembly_files.len == 0) {
363 try stderr.write("Expected source file argument or at least one --object or --assembly argument\n");365 try stderr.write("Expected source file argument or at least one --object or --assembly argument\n");
364 os.exit(1);366 process.exit(1);
365 }367 }
366368
367 if (out_type == Compilation.Kind.Obj and link_objects.len != 0) {369 if (out_type == Compilation.Kind.Obj and link_objects.len != 0) {
368 try stderr.write("When building an object file, --object arguments are invalid\n");370 try stderr.write("When building an object file, --object arguments are invalid\n");
369 os.exit(1);371 process.exit(1);
370 }372 }
371373
372 var clang_argv_buf = ArrayList([]const u8).init(allocator);374 var clang_argv_buf = ArrayList([]const u8).init(allocator);
...@@ -379,7 +381,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -379,7 +381,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
379 }381 }
380 try ZigCompiler.setLlvmArgv(allocator, mllvm_flags);382 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);
383 defer allocator.free(zig_lib_dir);385 defer allocator.free(zig_lib_dir);
384386
385 var override_libc: LibCInstallation = undefined;387 var override_libc: LibCInstallation = undefined;
...@@ -448,7 +450,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -448,7 +450,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
448450
449 if (flags.single("mmacosx-version-min") != null and flags.single("mios-version-min") != null) {451 if (flags.single("mmacosx-version-min") != null and flags.single("mios-version-min") != null) {
450 try stderr.write("-mmacosx-version-min and -mios-version-min options not allowed together\n");452 try stderr.write("-mmacosx-version-min and -mios-version-min options not allowed together\n");
451 os.exit(1);453 process.exit(1);
452 }454 }
453455
454 if (flags.single("mmacosx-version-min")) |ver| {456 if (flags.single("mmacosx-version-min")) |ver| {
...@@ -478,16 +480,16 @@ async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {...@@ -478,16 +480,16 @@ async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
478480
479 switch (build_event) {481 switch (build_event) {
480 Compilation.Event.Ok => {482 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);
482 },484 },
483 Compilation.Event.Error => |err| {485 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);
485 },487 },
486 Compilation.Event.Fail => |msgs| {488 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);
488 for (msgs) |msg| {490 for (msgs) |msg| {
489 defer msg.destroy();491 defer msg.destroy();
490 msg.printToFile(stderr_file, color) catch os.exit(1);492 msg.printToFile(stderr_file, color) catch process.exit(1);
491 }493 }
492 },494 },
493 }495 }
...@@ -550,8 +552,8 @@ fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_fil...@@ -550,8 +552,8 @@ fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_fil
550 "Try running `zig libc` to see an example for the native target.\n",552 "Try running `zig libc` to see an example for the native target.\n",
551 libc_paths_file,553 libc_paths_file,
552 @errorName(err),554 @errorName(err),
553 ) catch os.exit(1);555 ) catch process.exit(1);
554 os.exit(1);556 process.exit(1);
555 };557 };
556}558}
557559
...@@ -565,7 +567,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -565,7 +567,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
565 },567 },
566 else => {568 else => {
567 try stderr.print("unexpected extra parameter: {}\n", args[1]);569 try stderr.print("unexpected extra parameter: {}\n", args[1]);
568 os.exit(1);570 process.exit(1);
569 },571 },
570 }572 }
571573
...@@ -584,10 +586,10 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -584,10 +586,10 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
584586
585async fn findLibCAsync(zig_compiler: *ZigCompiler) void {587async fn findLibCAsync(zig_compiler: *ZigCompiler) void {
586 const libc = (await (async zig_compiler.getNativeLibC() catch unreachable)) catch |err| {588 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);589 stderr.print("unable to find libc: {}\n", @errorName(err)) catch process.exit(1);
588 os.exit(1);590 process.exit(1);
589 };591 };
590 libc.render(stdout) catch os.exit(1);592 libc.render(stdout) catch process.exit(1);
591}593}
592594
593fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {595fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
...@@ -596,7 +598,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -596,7 +598,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
596598
597 if (flags.present("help")) {599 if (flags.present("help")) {
598 try stdout.write(usage_fmt);600 try stdout.write(usage_fmt);
599 os.exit(0);601 process.exit(0);
600 }602 }
601603
602 const color = blk: {604 const color = blk: {
...@@ -616,7 +618,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -616,7 +618,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
616 if (flags.present("stdin")) {618 if (flags.present("stdin")) {
617 if (flags.positionals.len != 0) {619 if (flags.positionals.len != 0) {
618 try stderr.write("cannot use --stdin with positional arguments\n");620 try stderr.write("cannot use --stdin with positional arguments\n");
619 os.exit(1);621 process.exit(1);
620 }622 }
621623
622 var stdin_file = try io.getStdIn();624 var stdin_file = try io.getStdIn();
...@@ -627,7 +629,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -627,7 +629,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
627629
628 const tree = std.zig.parse(allocator, source_code) catch |err| {630 const tree = std.zig.parse(allocator, source_code) catch |err| {
629 try stderr.print("error parsing stdin: {}\n", err);631 try stderr.print("error parsing stdin: {}\n", err);
630 os.exit(1);632 process.exit(1);
631 };633 };
632 defer tree.deinit();634 defer tree.deinit();
633635
...@@ -639,12 +641,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -639,12 +641,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
639 try msg.printToFile(stderr_file, color);641 try msg.printToFile(stderr_file, color);
640 }642 }
641 if (tree.errors.len != 0) {643 if (tree.errors.len != 0) {
642 os.exit(1);644 process.exit(1);
643 }645 }
644 if (flags.present("check")) {646 if (flags.present("check")) {
645 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);647 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
646 const code = if (anything_changed) u8(1) else u8(0);648 const code = if (anything_changed) u8(1) else u8(0);
647 os.exit(code);649 process.exit(code);
648 }650 }
649651
650 _ = try std.zig.render(allocator, stdout, tree);652 _ = try std.zig.render(allocator, stdout, tree);
...@@ -653,7 +655,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -653,7 +655,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
653655
654 if (flags.positionals.len == 0) {656 if (flags.positionals.len == 0) {
655 try stderr.write("expected at least one source file argument\n");657 try stderr.write("expected at least one source file argument\n");
656 os.exit(1);658 process.exit(1);
657 }659 }
658660
659 var loop: event.Loop = undefined;661 var loop: event.Loop = undefined;
...@@ -700,7 +702,7 @@ const FmtError = error{...@@ -700,7 +702,7 @@ const FmtError = error{
700 ReadOnlyFileSystem,702 ReadOnlyFileSystem,
701 LinkQuotaExceeded,703 LinkQuotaExceeded,
702 FileBusy,704 FileBusy,
703} || os.File.OpenError;705} || fs.File.OpenError;
704706
705async fn asyncFmtMain(707async fn asyncFmtMain(
706 loop: *event.Loop,708 loop: *event.Loop,
...@@ -725,7 +727,7 @@ async fn asyncFmtMain(...@@ -725,7 +727,7 @@ async fn asyncFmtMain(
725 }727 }
726 try await (async group.wait() catch unreachable);728 try await (async group.wait() catch unreachable);
727 if (fmt.any_error) {729 if (fmt.any_error) {
728 os.exit(1);730 process.exit(1);
729 }731 }
730}732}
731733
...@@ -747,13 +749,13 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -747,13 +749,13 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
747 )) catch |err| switch (err) {749 )) catch |err| switch (err) {
748 error.IsDir, error.AccessDenied => {750 error.IsDir, error.AccessDenied => {
749 // TODO make event based (and dir.next())751 // 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);
751 defer dir.close();753 defer dir.close();
752754
753 var group = event.Group(FmtError!void).init(fmt.loop);755 var group = event.Group(FmtError!void).init(fmt.loop);
754 while (try dir.next()) |entry| {756 while (try dir.next()) |entry| {
755 if (entry.kind == std.os.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {757 if (entry.kind == fs.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 });758 const full_path = try fs.path.join(fmt.loop.allocator, [][]const u8{ file_path, entry.name });
757 try group.call(fmtPath, fmt, full_path, check_mode);759 try group.call(fmtPath, fmt, full_path, check_mode);
758 }760 }
759 }761 }
...@@ -891,7 +893,7 @@ const usage_internal =...@@ -891,7 +893,7 @@ const usage_internal =
891fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {893fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
892 if (args.len == 0) {894 if (args.len == 0) {
893 try stderr.write(usage_internal);895 try stderr.write(usage_internal);
894 os.exit(1);896 process.exit(1);
895 }897 }
896898
897 const sub_commands = []Command{Command{899 const sub_commands = []Command{Command{
src-self-hosted/stage1.zig+29-30
...@@ -1,8 +1,24 @@...@@ -1,8 +1,24 @@
1// This is Zig code that is used by both stage1 and stage2.1// This is Zig code that is used by both stage1 and stage2.
2// The prototypes in src/userland.h must match these definitions.2// The prototypes in src/userland.h must match these definitions.
33
4const std = @import("std");
5const builtin = @import("builtin");4const 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
7// ABI warning23// ABI warning
8export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {24export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {
...@@ -157,7 +173,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -157,7 +173,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
157173
158 if (flags.present("help")) {174 if (flags.present("help")) {
159 try stdout.write(self_hosted_main.usage_fmt);175 try stdout.write(self_hosted_main.usage_fmt);
160 os.exit(0);176 process.exit(0);
161 }177 }
162178
163 const color = blk: {179 const color = blk: {
...@@ -177,7 +193,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -177,7 +193,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
177 if (flags.present("stdin")) {193 if (flags.present("stdin")) {
178 if (flags.positionals.len != 0) {194 if (flags.positionals.len != 0) {
179 try stderr.write("cannot use --stdin with positional arguments\n");195 try stderr.write("cannot use --stdin with positional arguments\n");
180 os.exit(1);196 process.exit(1);
181 }197 }
182198
183 var stdin_file = try io.getStdIn();199 var stdin_file = try io.getStdIn();
...@@ -188,7 +204,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -188,7 +204,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
188204
189 const tree = std.zig.parse(allocator, source_code) catch |err| {205 const tree = std.zig.parse(allocator, source_code) catch |err| {
190 try stderr.print("error parsing stdin: {}\n", err);206 try stderr.print("error parsing stdin: {}\n", err);
191 os.exit(1);207 process.exit(1);
192 };208 };
193 defer tree.deinit();209 defer tree.deinit();
194210
...@@ -197,12 +213,12 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -197,12 +213,12 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
197 try printErrMsgToFile(allocator, parse_error, tree, "<stdin>", stderr_file, color);213 try printErrMsgToFile(allocator, parse_error, tree, "<stdin>", stderr_file, color);
198 }214 }
199 if (tree.errors.len != 0) {215 if (tree.errors.len != 0) {
200 os.exit(1);216 process.exit(1);
201 }217 }
202 if (flags.present("check")) {218 if (flags.present("check")) {
203 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);219 const anything_changed = try std.zig.render(allocator, io.null_out_stream, tree);
204 const code = if (anything_changed) u8(1) else u8(0);220 const code = if (anything_changed) u8(1) else u8(0);
205 os.exit(code);221 process.exit(code);
206 }222 }
207223
208 _ = try std.zig.render(allocator, stdout, tree);224 _ = try std.zig.render(allocator, stdout, tree);
...@@ -211,7 +227,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -211,7 +227,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
211227
212 if (flags.positionals.len == 0) {228 if (flags.positionals.len == 0) {
213 try stderr.write("expected at least one source file argument\n");229 try stderr.write("expected at least one source file argument\n");
214 os.exit(1);230 process.exit(1);
215 }231 }
216232
217 var fmt = Fmt{233 var fmt = Fmt{
...@@ -227,7 +243,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {...@@ -227,7 +243,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
227 try fmtPath(&fmt, file_path, check_mode);243 try fmtPath(&fmt, file_path, check_mode);
228 }244 }
229 if (fmt.any_error) {245 if (fmt.any_error) {
230 os.exit(1);246 process.exit(1);
231 }247 }
232}248}
233249
...@@ -250,7 +266,7 @@ const FmtError = error{...@@ -250,7 +266,7 @@ const FmtError = error{
250 ReadOnlyFileSystem,266 ReadOnlyFileSystem,
251 LinkQuotaExceeded,267 LinkQuotaExceeded,
252 FileBusy,268 FileBusy,
253} || os.File.OpenError;269} || fs.File.OpenError;
254270
255fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {271fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {
256 const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref);272 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...@@ -261,12 +277,12 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
261 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {277 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
262 error.IsDir, error.AccessDenied => {278 error.IsDir, error.AccessDenied => {
263 // TODO make event based (and dir.next())279 // 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);
265 defer dir.close();281 defer dir.close();
266282
267 while (try dir.next()) |entry| {283 while (try dir.next()) |entry| {
268 if (entry.kind == std.os.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {284 if (entry.kind == fs.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 });285 const full_path = try fs.path.join(fmt.allocator, [][]const u8{ file_path, entry.name });
270 try fmtPath(fmt, full_path, check_mode);286 try fmtPath(fmt, full_path, check_mode);
271 }287 }
272 }288 }
...@@ -329,7 +345,7 @@ fn printErrMsgToFile(...@@ -329,7 +345,7 @@ fn printErrMsgToFile(
329 parse_error: *const ast.Error,345 parse_error: *const ast.Error,
330 tree: *ast.Tree,346 tree: *ast.Tree,
331 path: []const u8,347 path: []const u8,
332 file: os.File,348 file: fs.File,
333 color: errmsg.Color,349 color: errmsg.Color,
334) !void {350) !void {
335 const color_on = switch (color) {351 const color_on = switch (color) {
...@@ -377,20 +393,3 @@ fn printErrMsgToFile(...@@ -377,20 +393,3 @@ fn printErrMsgToFile(
377 try stream.writeByteNTimes('~', last_token.end - first_token.start);393 try stream.writeByteNTimes('~', last_token.end - first_token.start);
378 try stream.write("\n");394 try stream.write("\n");
379}395}
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 {...@@ -55,12 +55,12 @@ pub const TestContext = struct {
55 self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);55 self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);
56 errdefer allocator.free(self.zig_lib_dir);56 errdefer allocator.free(self.zig_lib_dir);
5757
58 try std.os.makePath(allocator, tmp_dir_name);58 try std.fs.makePath(allocator, tmp_dir_name);
59 errdefer std.os.deleteTree(allocator, tmp_dir_name) catch {};59 errdefer std.fs.deleteTree(allocator, tmp_dir_name) catch {};
60 }60 }
6161
62 fn deinit(self: *TestContext) void {62 fn deinit(self: *TestContext) void {
63 std.os.deleteTree(allocator, tmp_dir_name) catch {};63 std.fs.deleteTree(allocator, tmp_dir_name) catch {};
64 allocator.free(self.zig_lib_dir);64 allocator.free(self.zig_lib_dir);
65 self.zig_compiler.deinit();65 self.zig_compiler.deinit();
66 self.loop.deinit();66 self.loop.deinit();
...@@ -87,10 +87,10 @@ pub const TestContext = struct {...@@ -87,10 +87,10 @@ pub const TestContext = struct {
87 ) !void {87 ) !void {
88 var file_index_buf: [20]u8 = undefined;88 var file_index_buf: [20]u8 = undefined;
89 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr());89 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| {92 if (std.fs.path.dirname(file1_path)) |dirname| {
93 try std.os.makePath(allocator, dirname);93 try std.fs.makePath(allocator, dirname);
94 }94 }
9595
96 // TODO async I/O96 // TODO async I/O
...@@ -120,11 +120,11 @@ pub const TestContext = struct {...@@ -120,11 +120,11 @@ pub const TestContext = struct {
120 ) !void {120 ) !void {
121 var file_index_buf: [20]u8 = undefined;121 var file_index_buf: [20]u8 = undefined;
122 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.incr());122 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
125 const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, Target(Target.Native).exeFileExt());125 const output_file = try std.fmt.allocPrint(allocator, "{}-out{}", file1_path, Target(Target.Native).exeFileExt());
126 if (std.os.path.dirname(file1_path)) |dirname| {126 if (std.fs.path.dirname(file1_path)) |dirname| {
127 try std.os.makePath(allocator, dirname);127 try std.fs.makePath(allocator, dirname);
128 }128 }
129129
130 // TODO async I/O130 // TODO async I/O
...@@ -164,9 +164,9 @@ pub const TestContext = struct {...@@ -164,9 +164,9 @@ pub const TestContext = struct {
164 Compilation.Event.Ok => {164 Compilation.Event.Ok => {
165 const argv = []const []const u8{exe_file_2};165 const argv = []const []const u8{exe_file_2};
166 // TODO use event loop166 // 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);
168 switch (child.term) {168 switch (child.term) {
169 std.os.ChildProcess.Term.Exited => |code| {169 .Exited => |code| {
170 if (code != 0) {170 if (code != 0) {
171 return error.BadReturnCode;171 return error.BadReturnCode;
172 }172 }
std/buffer.zig+1-3
...@@ -139,15 +139,13 @@ pub const Buffer = struct {...@@ -139,15 +139,13 @@ pub const Buffer = struct {
139};139};
140140
141test "simple Buffer" {141test "simple Buffer" {
142 const cstr = @import("cstr.zig");
143
144 var buf = try Buffer.init(debug.global_allocator, "");142 var buf = try Buffer.init(debug.global_allocator, "");
145 testing.expect(buf.len() == 0);143 testing.expect(buf.len() == 0);
146 try buf.append("hello");144 try buf.append("hello");
147 try buf.append(" ");145 try buf.append(" ");
148 try buf.append("world");146 try buf.append("world");
149 testing.expect(buf.eql("hello world"));147 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
152 var buf2 = try Buffer.initFromBuffer(buf);150 var buf2 = try Buffer.initFromBuffer(buf);
153 testing.expect(buf.eql(buf2.toSliceConst()));151 testing.expect(buf.eql(buf2.toSliceConst()));
std/build.zig+82-83
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const io = std.io;3const io = std.io;
4const fs = std.fs;
4const mem = std.mem;5const mem = std.mem;
5const debug = std.debug;6const debug = std.debug;
6const assert = debug.assert;7const assert = debug.assert;
...@@ -8,9 +9,7 @@ const warn = std.debug.warn;...@@ -8,9 +9,7 @@ const warn = std.debug.warn;
8const ArrayList = std.ArrayList;9const ArrayList = std.ArrayList;
9const HashMap = std.HashMap;10const HashMap = std.HashMap;
10const Allocator = mem.Allocator;11const Allocator = mem.Allocator;
11const os = std.os;12const process = std.process;
12const StdIo = os.ChildProcess.StdIo;
13const Term = os.ChildProcess.Term;
14const BufSet = std.BufSet;13const BufSet = std.BufSet;
15const BufMap = std.BufMap;14const BufMap = std.BufMap;
16const fmt_lib = std.fmt;15const fmt_lib = std.fmt;
...@@ -96,11 +95,11 @@ pub const Builder = struct {...@@ -96,11 +95,11 @@ pub const Builder = struct {
9695
97 pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {96 pub fn init(allocator: *Allocator, zig_exe: []const u8, build_root: []const u8, cache_root: []const u8) Builder {
98 const env_map = allocator.create(BufMap) catch unreachable;97 const env_map = allocator.create(BufMap) catch unreachable;
99 env_map.* = os.getEnvMap(allocator) catch unreachable;98 env_map.* = process.getEnvMap(allocator) catch unreachable;
100 var self = Builder{99 var self = Builder{
101 .zig_exe = zig_exe,100 .zig_exe = zig_exe,
102 .build_root = build_root,101 .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,
104 .verbose = false,103 .verbose = false,
105 .verbose_tokenize = false,104 .verbose_tokenize = false,
106 .verbose_ast = false,105 .verbose_ast = false,
...@@ -154,8 +153,8 @@ pub const Builder = struct {...@@ -154,8 +153,8 @@ pub const Builder = struct {
154153
155 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {154 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
156 self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default155 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;156 self.lib_dir = fs.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;157 self.exe_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "bin" }) catch unreachable;
159 }158 }
160159
161 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {160 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
...@@ -287,7 +286,7 @@ pub const Builder = struct {...@@ -287,7 +286,7 @@ pub const Builder = struct {
287 if (self.verbose) {286 if (self.verbose) {
288 warn("rm {}\n", installed_file);287 warn("rm {}\n", installed_file);
289 }288 }
290 os.deleteFile(installed_file) catch {};289 fs.deleteFile(installed_file) catch {};
291 }290 }
292291
293 // TODO remove empty directories292 // TODO remove empty directories
...@@ -326,7 +325,7 @@ pub const Builder = struct {...@@ -326,7 +325,7 @@ pub const Builder = struct {
326325
327 fn detectNativeSystemPaths(self: *Builder) void {326 fn detectNativeSystemPaths(self: *Builder) void {
328 var is_nixos = false;327 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| {
330 is_nixos = true;329 is_nixos = true;
331 var it = mem.tokenize(nix_cflags_compile, " ");330 var it = mem.tokenize(nix_cflags_compile, " ");
332 while (true) {331 while (true) {
...@@ -345,7 +344,7 @@ pub const Builder = struct {...@@ -345,7 +344,7 @@ pub const Builder = struct {
345 } else |err| {344 } else |err| {
346 assert(err == error.EnvironmentVariableNotFound);345 assert(err == error.EnvironmentVariableNotFound);
347 }346 }
348 if (os.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {347 if (process.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {
349 is_nixos = true;348 is_nixos = true;
350 var it = mem.tokenize(nix_ldflags, " ");349 var it = mem.tokenize(nix_ldflags, " ");
351 while (true) {350 while (true) {
...@@ -369,7 +368,7 @@ pub const Builder = struct {...@@ -369,7 +368,7 @@ pub const Builder = struct {
369 }368 }
370 if (is_nixos) return;369 if (is_nixos) return;
371 switch (builtin.os) {370 switch (builtin.os) {
372 builtin.Os.windows => {},371 .windows => {},
373 else => {372 else => {
374 const triple = (CrossTarget{373 const triple = (CrossTarget{
375 .arch = builtin.arch,374 .arch = builtin.arch,
...@@ -602,7 +601,7 @@ pub const Builder = struct {...@@ -602,7 +601,7 @@ pub const Builder = struct {
602 printCmd(cwd, argv);601 printCmd(cwd, argv);
603 }602 }
604603
605 const child = os.ChildProcess.init(argv, self.allocator) catch unreachable;604 const child = std.ChildProcess.init(argv, self.allocator) catch unreachable;
606 defer child.deinit();605 defer child.deinit();
607606
608 child.cwd = cwd;607 child.cwd = cwd;
...@@ -614,7 +613,7 @@ pub const Builder = struct {...@@ -614,7 +613,7 @@ pub const Builder = struct {
614 };613 };
615614
616 switch (term) {615 switch (term) {
617 Term.Exited => |code| {616 .Exited => |code| {
618 if (code != 0) {617 if (code != 0) {
619 warn("The following command exited with error code {}:\n", code);618 warn("The following command exited with error code {}:\n", code);
620 printCmd(cwd, argv);619 printCmd(cwd, argv);
...@@ -631,7 +630,7 @@ pub const Builder = struct {...@@ -631,7 +630,7 @@ pub const Builder = struct {
631 }630 }
632631
633 pub fn makePath(self: *Builder, path: []const u8) !void {632 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| {
635 warn("Unable to create path {}: {}\n", path, @errorName(err));634 warn("Unable to create path {}: {}\n", path, @errorName(err));
636 return err;635 return err;
637 };636 };
...@@ -652,7 +651,7 @@ pub const Builder = struct {...@@ -652,7 +651,7 @@ pub const Builder = struct {
652651
653 ///::dest_rel_path is relative to prefix path or it can be an absolute path652 ///::dest_rel_path is relative to prefix path or it can be an absolute path
654 pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {653 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(
656 self.allocator,655 self.allocator,
657 [][]const u8{ self.prefix, dest_rel_path },656 [][]const u8{ self.prefix, dest_rel_path },
658 ) catch unreachable;657 ) catch unreachable;
...@@ -677,20 +676,20 @@ pub const Builder = struct {...@@ -677,20 +676,20 @@ pub const Builder = struct {
677 warn("cp {} {}\n", source_path, dest_path);676 warn("cp {} {}\n", source_path, dest_path);
678 }677 }
679678
680 const dirname = os.path.dirname(dest_path) orelse ".";679 const dirname = fs.path.dirname(dest_path) orelse ".";
681 const abs_source_path = self.pathFromRoot(source_path);680 const abs_source_path = self.pathFromRoot(source_path);
682 os.makePath(self.allocator, dirname) catch |err| {681 fs.makePath(self.allocator, dirname) catch |err| {
683 warn("Unable to create path {}: {}\n", dirname, @errorName(err));682 warn("Unable to create path {}: {}\n", dirname, @errorName(err));
684 return err;683 return err;
685 };684 };
686 os.copyFileMode(abs_source_path, dest_path, mode) catch |err| {685 fs.copyFileMode(abs_source_path, dest_path, mode) catch |err| {
687 warn("Unable to copy {} to {}: {}\n", abs_source_path, dest_path, @errorName(err));686 warn("Unable to copy {} to {}: {}\n", abs_source_path, dest_path, @errorName(err));
688 return err;687 return err;
689 };688 };
690 }689 }
691690
692 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {691 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;
694 }693 }
695694
696 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {695 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
...@@ -702,11 +701,11 @@ pub const Builder = struct {...@@ -702,11 +701,11 @@ pub const Builder = struct {
702 const exe_extension = (Target{ .Native = {} }).exeFileExt();701 const exe_extension = (Target{ .Native = {} }).exeFileExt();
703 for (self.search_prefixes.toSliceConst()) |search_prefix| {702 for (self.search_prefixes.toSliceConst()) |search_prefix| {
704 for (names) |name| {703 for (names) |name| {
705 if (os.path.isAbsolute(name)) {704 if (fs.path.isAbsolute(name)) {
706 return name;705 return name;
707 }706 }
708 const full_path = try os.path.join(self.allocator, [][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });707 const full_path = try fs.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| {708 if (fs.path.real(self.allocator, full_path)) |real_path| {
710 return real_path;709 return real_path;
711 } else |_| {710 } else |_| {
712 continue;711 continue;
...@@ -715,13 +714,13 @@ pub const Builder = struct {...@@ -715,13 +714,13 @@ pub const Builder = struct {
715 }714 }
716 if (self.env_map.get("PATH")) |PATH| {715 if (self.env_map.get("PATH")) |PATH| {
717 for (names) |name| {716 for (names) |name| {
718 if (os.path.isAbsolute(name)) {717 if (fs.path.isAbsolute(name)) {
719 return name;718 return name;
720 }719 }
721 var it = mem.tokenize(PATH, []u8{os.path.delimiter});720 var it = mem.tokenize(PATH, []u8{fs.path.delimiter});
722 while (it.next()) |path| {721 while (it.next()) |path| {
723 const full_path = try os.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });722 const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
724 if (os.path.real(self.allocator, full_path)) |real_path| {723 if (fs.path.real(self.allocator, full_path)) |real_path| {
725 return real_path;724 return real_path;
726 } else |_| {725 } else |_| {
727 continue;726 continue;
...@@ -730,12 +729,12 @@ pub const Builder = struct {...@@ -730,12 +729,12 @@ pub const Builder = struct {
730 }729 }
731 }730 }
732 for (names) |name| {731 for (names) |name| {
733 if (os.path.isAbsolute(name)) {732 if (fs.path.isAbsolute(name)) {
734 return name;733 return name;
735 }734 }
736 for (paths) |path| {735 for (paths) |path| {
737 const full_path = try os.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });736 const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
738 if (os.path.real(self.allocator, full_path)) |real_path| {737 if (fs.path.real(self.allocator, full_path)) |real_path| {
739 return real_path;738 return real_path;
740 } else |_| {739 } else |_| {
741 continue;740 continue;
...@@ -749,12 +748,12 @@ pub const Builder = struct {...@@ -749,12 +748,12 @@ pub const Builder = struct {
749 assert(argv.len != 0);748 assert(argv.len != 0);
750749
751 const max_output_size = 100 * 1024;750 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);
753 defer child.deinit();752 defer child.deinit();
754753
755 child.stdin_behavior = os.ChildProcess.StdIo.Ignore;754 child.stdin_behavior = .Ignore;
756 child.stdout_behavior = os.ChildProcess.StdIo.Pipe;755 child.stdout_behavior = .Pipe;
757 child.stderr_behavior = os.ChildProcess.StdIo.Inherit;756 child.stderr_behavior = .Inherit;
758757
759 try child.spawn();758 try child.spawn();
760759
...@@ -766,7 +765,7 @@ pub const Builder = struct {...@@ -766,7 +765,7 @@ pub const Builder = struct {
766765
767 const term = child.wait() catch |err| std.debug.panic("unable to spawn {}: {}", argv[0], err);766 const term = child.wait() catch |err| std.debug.panic("unable to spawn {}: {}", argv[0], err);
768 switch (term) {767 switch (term) {
769 os.ChildProcess.Term.Exited => |code| {768 .Exited => |code| {
770 if (code != 0) {769 if (code != 0) {
771 warn("The following command exited with error code {}:\n", code);770 warn("The following command exited with error code {}:\n", code);
772 printCmd(null, argv);771 printCmd(null, argv);
...@@ -846,7 +845,7 @@ pub const Target = union(enum) {...@@ -846,7 +845,7 @@ pub const Target = union(enum) {
846 }845 }
847 }846 }
848847
849 pub fn oFileExt(self: *const Target) []const u8 {848 pub fn oFileExt(self: Target) []const u8 {
850 const abi = switch (self.*) {849 const abi = switch (self.*) {
851 Target.Native => builtin.abi,850 Target.Native => builtin.abi,
852 Target.Cross => |t| t.abi,851 Target.Cross => |t| t.abi,
...@@ -857,49 +856,49 @@ pub const Target = union(enum) {...@@ -857,49 +856,49 @@ pub const Target = union(enum) {
857 };856 };
858 }857 }
859858
860 pub fn exeFileExt(self: *const Target) []const u8 {859 pub fn exeFileExt(self: Target) []const u8 {
861 return switch (self.getOs()) {860 return switch (self.getOs()) {
862 builtin.Os.windows => ".exe",861 .windows => ".exe",
863 else => "",862 else => "",
864 };863 };
865 }864 }
866865
867 pub fn libFileExt(self: *const Target) []const u8 {866 pub fn libFileExt(self: Target) []const u8 {
868 return switch (self.getOs()) {867 return switch (self.getOs()) {
869 builtin.Os.windows => ".lib",868 .windows => ".lib",
870 else => ".a",869 else => ".a",
871 };870 };
872 }871 }
873872
874 pub fn getOs(self: *const Target) builtin.Os {873 pub fn getOs(self: Target) builtin.Os {
875 return switch (self.*) {874 return switch (self) {
876 Target.Native => builtin.os,875 Target.Native => builtin.os,
877 Target.Cross => |t| t.os,876 Target.Cross => |t| t.os,
878 };877 };
879 }878 }
880879
881 pub fn isDarwin(self: *const Target) bool {880 pub fn isDarwin(self: Target) bool {
882 return switch (self.getOs()) {881 return switch (self.getOs()) {
883 builtin.Os.ios, builtin.Os.macosx => true,882 .ios, .macosx, .watchos, .tvos => true,
884 else => false,883 else => false,
885 };884 };
886 }885 }
887886
888 pub fn isWindows(self: *const Target) bool {887 pub fn isWindows(self: Target) bool {
889 return switch (self.getOs()) {888 return switch (self.getOs()) {
890 builtin.Os.windows => true,889 .windows => true,
891 else => false,890 else => false,
892 };891 };
893 }892 }
894893
895 pub fn isFreeBSD(self: *const Target) bool {894 pub fn isFreeBSD(self: Target) bool {
896 return switch (self.getOs()) {895 return switch (self.getOs()) {
897 builtin.Os.freebsd => true,896 .freebsd => true,
898 else => false,897 else => false,
899 };898 };
900 }899 }
901900
902 pub fn wantSharedLibSymLinks(self: *const Target) bool {901 pub fn wantSharedLibSymLinks(self: Target) bool {
903 return !self.isWindows();902 return !self.isWindows();
904 }903 }
905};904};
...@@ -1065,19 +1064,19 @@ pub const LibExeObjStep = struct {...@@ -1065,19 +1064,19 @@ pub const LibExeObjStep = struct {
10651064
1066 fn computeOutFileNames(self: *LibExeObjStep) void {1065 fn computeOutFileNames(self: *LibExeObjStep) void {
1067 switch (self.kind) {1066 switch (self.kind) {
1068 Kind.Obj => {1067 .Obj => {
1069 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());1068 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
1070 },1069 },
1071 Kind.Exe => {1070 .Exe => {
1072 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());1071 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
1073 },1072 },
1074 Kind.Test => {1073 .Test => {
1075 self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());1074 self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());
1076 },1075 },
1077 Kind.Lib => {1076 .Lib => {
1078 if (!self.is_dynamic) {1077 if (!self.is_dynamic) {
1079 switch (self.target.getOs()) {1078 switch (self.target.getOs()) {
1080 builtin.Os.windows => {1079 .windows => {
1081 self.out_filename = self.builder.fmt("{}.lib", self.name);1080 self.out_filename = self.builder.fmt("{}.lib", self.name);
1082 },1081 },
1083 else => {1082 else => {
...@@ -1087,13 +1086,13 @@ pub const LibExeObjStep = struct {...@@ -1087,13 +1086,13 @@ pub const LibExeObjStep = struct {
1087 self.out_lib_filename = self.out_filename;1086 self.out_lib_filename = self.out_filename;
1088 } else {1087 } else {
1089 switch (self.target.getOs()) {1088 switch (self.target.getOs()) {
1090 builtin.Os.ios, builtin.Os.macosx => {1089 .ios, .macosx => {
1091 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);1090 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);
1092 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);1091 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);
1093 self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);1092 self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);
1094 self.out_lib_filename = self.out_filename;1093 self.out_lib_filename = self.out_filename;
1095 },1094 },
1096 builtin.Os.windows => {1095 .windows => {
1097 self.out_filename = self.builder.fmt("{}.dll", self.name);1096 self.out_filename = self.builder.fmt("{}.dll", self.name);
1098 self.out_lib_filename = self.builder.fmt("{}.lib", self.name);1097 self.out_lib_filename = self.builder.fmt("{}.lib", self.name);
1099 },1098 },
...@@ -1228,7 +1227,7 @@ pub const LibExeObjStep = struct {...@@ -1228,7 +1227,7 @@ pub const LibExeObjStep = struct {
1228 /// the make step, from a step that has declared a dependency on this one.1227 /// the make step, from a step that has declared a dependency on this one.
1229 /// To run an executable built with zig build, use `run`, or create an install step and invoke it.1228 /// To run an executable built with zig build, use `run`, or create an install step and invoke it.
1230 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {1229 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1231 return os.path.join(1230 return fs.path.join(
1232 self.builder.allocator,1231 self.builder.allocator,
1233 [][]const u8{ self.output_dir.?, self.out_filename },1232 [][]const u8{ self.output_dir.?, self.out_filename },
1234 ) catch unreachable;1233 ) catch unreachable;
...@@ -1238,7 +1237,7 @@ pub const LibExeObjStep = struct {...@@ -1238,7 +1237,7 @@ pub const LibExeObjStep = struct {
1238 /// the make step, from a step that has declared a dependency on this one.1237 /// the make step, from a step that has declared a dependency on this one.
1239 pub fn getOutputLibPath(self: *LibExeObjStep) []const u8 {1238 pub fn getOutputLibPath(self: *LibExeObjStep) []const u8 {
1240 assert(self.kind == Kind.Lib);1239 assert(self.kind == Kind.Lib);
1241 return os.path.join(1240 return fs.path.join(
1242 self.builder.allocator,1241 self.builder.allocator,
1243 [][]const u8{ self.output_dir.?, self.out_lib_filename },1242 [][]const u8{ self.output_dir.?, self.out_lib_filename },
1244 ) catch unreachable;1243 ) catch unreachable;
...@@ -1249,7 +1248,7 @@ pub const LibExeObjStep = struct {...@@ -1249,7 +1248,7 @@ pub const LibExeObjStep = struct {
1249 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {1248 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
1250 assert(self.kind != Kind.Exe);1249 assert(self.kind != Kind.Exe);
1251 assert(!self.disable_gen_h);1250 assert(!self.disable_gen_h);
1252 return os.path.join(1251 return fs.path.join(
1253 self.builder.allocator,1252 self.builder.allocator,
1254 [][]const u8{ self.output_dir.?, self.out_h_filename },1253 [][]const u8{ self.output_dir.?, self.out_h_filename },
1255 ) catch unreachable;1254 ) catch unreachable;
...@@ -1365,7 +1364,7 @@ pub const LibExeObjStep = struct {...@@ -1365,7 +1364,7 @@ pub const LibExeObjStep = struct {
1365 try zig_args.append("--library");1364 try zig_args.append("--library");
1366 try zig_args.append(full_path_lib);1365 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| {
1369 try zig_args.append("-rpath");1368 try zig_args.append("-rpath");
1370 try zig_args.append(dirname);1369 try zig_args.append(dirname);
1371 }1370 }
...@@ -1391,7 +1390,7 @@ pub const LibExeObjStep = struct {...@@ -1391,7 +1390,7 @@ pub const LibExeObjStep = struct {
1391 }1390 }
13921391
1393 if (self.build_options_contents.len() > 0) {1392 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(
1395 builder.allocator,1394 builder.allocator,
1396 [][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },1395 [][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
1397 );1396 );
...@@ -1503,7 +1502,7 @@ pub const LibExeObjStep = struct {...@@ -1503,7 +1502,7 @@ pub const LibExeObjStep = struct {
1503 IncludeDir.OtherStep => |other| {1502 IncludeDir.OtherStep => |other| {
1504 const h_path = other.getOutputHPath();1503 const h_path = other.getOutputHPath();
1505 try zig_args.append("-isystem");1504 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).?);
1507 },1506 },
1508 }1507 }
1509 }1508 }
...@@ -1576,7 +1575,7 @@ pub const LibExeObjStep = struct {...@@ -1576,7 +1575,7 @@ pub const LibExeObjStep = struct {
15761575
1577 const output_path_nl = try builder.exec(zig_args.toSliceConst());1576 const output_path_nl = try builder.exec(zig_args.toSliceConst());
1578 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");1577 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).?;
1580 }1579 }
15811580
1582 if (self.kind == Kind.Lib and self.is_dynamic and self.target.wantSharedLibSymLinks()) {1581 if (self.kind == Kind.Lib and self.is_dynamic and self.target.wantSharedLibSymLinks()) {
...@@ -1637,20 +1636,20 @@ pub const RunStep = struct {...@@ -1637,20 +1636,20 @@ pub const RunStep = struct {
1637 }1636 }
16381637
1639 pub fn addPathDir(self: *RunStep, search_path: []const u8) void {1638 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";
1641 const env_map = self.getEnvMap();1640 const env_map = self.getEnvMap();
1642 const prev_path = env_map.get(PATH) orelse {1641 const prev_path = env_map.get(PATH) orelse {
1643 env_map.set(PATH, search_path) catch unreachable;1642 env_map.set(PATH, search_path) catch unreachable;
1644 return;1643 return;
1645 };1644 };
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);
1647 env_map.set(PATH, new_path) catch unreachable;1646 env_map.set(PATH, new_path) catch unreachable;
1648 }1647 }
16491648
1650 pub fn getEnvMap(self: *RunStep) *BufMap {1649 pub fn getEnvMap(self: *RunStep) *BufMap {
1651 return self.env_map orelse {1650 return self.env_map orelse {
1652 const env_map = self.builder.allocator.create(BufMap) catch unreachable;1651 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;
1654 self.env_map = env_map;1653 self.env_map = env_map;
1655 return env_map;1654 return env_map;
1656 };1655 };
...@@ -1688,7 +1687,7 @@ pub const RunStep = struct {...@@ -1688,7 +1687,7 @@ pub const RunStep = struct {
1688 switch (link_object) {1687 switch (link_object) {
1689 LibExeObjStep.LinkObject.OtherStep => |other| {1688 LibExeObjStep.LinkObject.OtherStep => |other| {
1690 if (other.target.isWindows() and other.isDynamicLibrary()) {1689 if (other.target.isWindows() and other.isDynamicLibrary()) {
1691 self.addPathDir(os.path.dirname(other.getOutputPath()).?);1690 self.addPathDir(fs.path.dirname(other.getOutputPath()).?);
1692 self.addPathForDynLibs(other);1691 self.addPathForDynLibs(other);
1693 }1692 }
1694 },1693 },
...@@ -1718,7 +1717,7 @@ const InstallArtifactStep = struct {...@@ -1718,7 +1717,7 @@ const InstallArtifactStep = struct {
1718 .builder = builder,1717 .builder = builder,
1719 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),1718 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
1720 .artifact = artifact,1719 .artifact = artifact,
1721 .dest_file = os.path.join(1720 .dest_file = fs.path.join(
1722 builder.allocator,1721 builder.allocator,
1723 [][]const u8{ dest_dir, artifact.out_filename },1722 [][]const u8{ dest_dir, artifact.out_filename },
1724 ) catch unreachable,1723 ) catch unreachable,
...@@ -1726,11 +1725,11 @@ const InstallArtifactStep = struct {...@@ -1726,11 +1725,11 @@ const InstallArtifactStep = struct {
1726 self.step.dependOn(&artifact.step);1725 self.step.dependOn(&artifact.step);
1727 builder.pushInstalledFile(self.dest_file);1726 builder.pushInstalledFile(self.dest_file);
1728 if (self.artifact.kind == LibExeObjStep.Kind.Lib and self.artifact.is_dynamic) {1727 if (self.artifact.kind == LibExeObjStep.Kind.Lib and self.artifact.is_dynamic) {
1729 builder.pushInstalledFile(os.path.join(1728 builder.pushInstalledFile(fs.path.join(
1730 builder.allocator,1729 builder.allocator,
1731 [][]const u8{ builder.lib_dir, artifact.major_only_filename },1730 [][]const u8{ builder.lib_dir, artifact.major_only_filename },
1732 ) catch unreachable);1731 ) catch unreachable);
1733 builder.pushInstalledFile(os.path.join(1732 builder.pushInstalledFile(fs.path.join(
1734 builder.allocator,1733 builder.allocator,
1735 [][]const u8{ builder.lib_dir, artifact.name_only_filename },1734 [][]const u8{ builder.lib_dir, artifact.name_only_filename },
1736 ) catch unreachable);1735 ) catch unreachable);
...@@ -1743,12 +1742,12 @@ const InstallArtifactStep = struct {...@@ -1743,12 +1742,12 @@ const InstallArtifactStep = struct {
1743 const builder = self.builder;1742 const builder = self.builder;
17441743
1745 const mode = switch (builtin.os) {1744 const mode = switch (builtin.os) {
1746 builtin.Os.windows => {},1745 .windows => {},
1747 else => switch (self.artifact.kind) {1746 else => switch (self.artifact.kind) {
1748 LibExeObjStep.Kind.Obj => unreachable,1747 .Obj => unreachable,
1749 LibExeObjStep.Kind.Test => unreachable,1748 .Test => unreachable,
1750 LibExeObjStep.Kind.Exe => u32(0o755),1749 .Exe => u32(0o755),
1751 LibExeObjStep.Kind.Lib => if (!self.artifact.is_dynamic) u32(0o666) else u32(0o755),1750 .Lib => if (!self.artifact.is_dynamic) u32(0o666) else u32(0o755),
1752 },1751 },
1753 };1752 };
1754 try builder.copyFileMode(self.artifact.getOutputPath(), self.dest_file, mode);1753 try builder.copyFileMode(self.artifact.getOutputPath(), self.dest_file, mode);
...@@ -1797,8 +1796,8 @@ pub const WriteFileStep = struct {...@@ -1797,8 +1796,8 @@ pub const WriteFileStep = struct {
1797 fn make(step: *Step) !void {1796 fn make(step: *Step) !void {
1798 const self = @fieldParentPtr(WriteFileStep, "step", step);1797 const self = @fieldParentPtr(WriteFileStep, "step", step);
1799 const full_path = self.builder.pathFromRoot(self.file_path);1798 const full_path = self.builder.pathFromRoot(self.file_path);
1800 const full_path_dir = os.path.dirname(full_path) orelse ".";1799 const full_path_dir = fs.path.dirname(full_path) orelse ".";
1801 os.makePath(self.builder.allocator, full_path_dir) catch |err| {1800 fs.makePath(self.builder.allocator, full_path_dir) catch |err| {
1802 warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));1801 warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));
1803 return err;1802 return err;
1804 };1803 };
...@@ -1845,7 +1844,7 @@ pub const RemoveDirStep = struct {...@@ -1845,7 +1844,7 @@ pub const RemoveDirStep = struct {
1845 const self = @fieldParentPtr(RemoveDirStep, "step", step);1844 const self = @fieldParentPtr(RemoveDirStep, "step", step);
18461845
1847 const full_path = self.builder.pathFromRoot(self.dir_path);1846 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| {
1849 warn("Unable to remove {}: {}\n", full_path, @errorName(err));1848 warn("Unable to remove {}: {}\n", full_path, @errorName(err));
1850 return err;1849 return err;
1851 };1850 };
...@@ -1887,23 +1886,23 @@ pub const Step = struct {...@@ -1887,23 +1886,23 @@ pub const Step = struct {
1887};1886};
18881887
1889fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {1888fn 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 ".";1889 const out_dir = fs.path.dirname(output_path) orelse ".";
1891 const out_basename = os.path.basename(output_path);1890 const out_basename = fs.path.basename(output_path);
1892 // sym link for libfoo.so.1 to libfoo.so.1.2.31891 // 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(
1894 allocator,1893 allocator,
1895 [][]const u8{ out_dir, filename_major_only },1894 [][]const u8{ out_dir, filename_major_only },
1896 ) catch unreachable;1895 ) catch unreachable;
1897 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {1896 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
1898 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);1897 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
1899 return err;1898 return err;
1900 };1899 };
1901 // sym link for libfoo.so to libfoo.so.11900 // 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(
1903 allocator,1902 allocator,
1904 [][]const u8{ out_dir, filename_name_only },1903 [][]const u8{ out_dir, filename_name_only },
1905 ) catch unreachable;1904 ) 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| {
1907 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);1906 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
1908 return err;1907 return err;
1909 };1908 };
std/child_process.zig+23-25
...@@ -2,7 +2,9 @@ const std = @import("std.zig");...@@ -2,7 +2,9 @@ const std = @import("std.zig");
2const cstr = std.cstr;2const cstr = std.cstr;
3const unicode = std.unicode;3const unicode = std.unicode;
4const io = std.io;4const io = std.io;
5const fs = std.fs;
5const os = std.os;6const os = std.os;
7const process = std.process;
6const File = std.fs.File;8const File = std.fs.File;
7const windows = os.windows;9const windows = os.windows;
8const mem = std.mem;10const mem = std.mem;
...@@ -14,12 +16,10 @@ const Os = builtin.Os;...@@ -14,12 +16,10 @@ const Os = builtin.Os;
14const LinkedList = std.LinkedList;16const LinkedList = std.LinkedList;
15const maxInt = std.math.maxInt;17const maxInt = std.math.maxInt;
1618
17const is_windows = builtin.os == .windows;
18
19pub const ChildProcess = struct {19pub const ChildProcess = struct {
20 pub pid: if (is_windows) void else i32,20 pub pid: if (os.windows.is_the_target) void else i32,
21 pub handle: if (is_windows) windows.HANDLE else void,21 pub handle: if (os.windows.is_the_target) windows.HANDLE else void,
22 pub thread_handle: if (is_windows) windows.HANDLE else void,22 pub thread_handle: if (os.windows.is_the_target) windows.HANDLE else void,
2323
24 pub allocator: *mem.Allocator,24 pub allocator: *mem.Allocator,
2525
...@@ -39,16 +39,16 @@ pub const ChildProcess = struct {...@@ -39,16 +39,16 @@ pub const ChildProcess = struct {
39 pub stderr_behavior: StdIo,39 pub stderr_behavior: StdIo,
4040
41 /// Set to change the user id when spawning the child process.41 /// 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
44 /// Set to change the group id when spawning the child process.44 /// 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
47 /// Set to change the current working directory when spawning the child process.47 /// Set to change the current working directory when spawning the child process.
48 pub cwd: ?[]const u8,48 pub cwd: ?[]const u8,
4949
50 err_pipe: if (is_windows) void else [2]i32,50 err_pipe: if (os.windows.is_the_target) void else [2]i32,
51 llnode: if (is_windows) void else LinkedList(*ChildProcess).Node,51 llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node,
5252
53 pub const SpawnError = error{53 pub const SpawnError = error{
54 ProcessFdQuotaExceeded,54 ProcessFdQuotaExceeded,
...@@ -98,10 +98,8 @@ pub const ChildProcess = struct {...@@ -98,10 +98,8 @@ pub const ChildProcess = struct {
98 .term = null,98 .term = null,
99 .env_map = null,99 .env_map = null,
100 .cwd = null,100 .cwd = null,
101 .uid = if (is_windows) {} else101 .uid = if (os.windows.is_the_target) {} else null,
102 null,102 .gid = if (os.windows.is_the_target) {} else null,
103 .gid = if (is_windows) {} else
104 null,
105 .stdin = null,103 .stdin = null,
106 .stdout = null,104 .stdout = null,
107 .stderr = null,105 .stderr = null,
...@@ -121,7 +119,7 @@ pub const ChildProcess = struct {...@@ -121,7 +119,7 @@ pub const ChildProcess = struct {
121119
122 /// On success must call `kill` or `wait`.120 /// On success must call `kill` or `wait`.
123 pub fn spawn(self: *ChildProcess) !void {121 pub fn spawn(self: *ChildProcess) !void {
124 if (is_windows) {122 if (os.windows.is_the_target) {
125 return self.spawnWindows();123 return self.spawnWindows();
126 } else {124 } else {
127 return self.spawnPosix();125 return self.spawnPosix();
...@@ -135,7 +133,7 @@ pub const ChildProcess = struct {...@@ -135,7 +133,7 @@ pub const ChildProcess = struct {
135133
136 /// Forcibly terminates child process and then cleans up all resources.134 /// Forcibly terminates child process and then cleans up all resources.
137 pub fn kill(self: *ChildProcess) !Term {135 pub fn kill(self: *ChildProcess) !Term {
138 if (is_windows) {136 if (os.windows.is_the_target) {
139 return self.killWindows(1);137 return self.killWindows(1);
140 } else {138 } else {
141 return self.killPosix();139 return self.killPosix();
...@@ -165,7 +163,7 @@ pub const ChildProcess = struct {...@@ -165,7 +163,7 @@ pub const ChildProcess = struct {
165163
166 /// Blocks until child process terminates and then cleans up all resources.164 /// Blocks until child process terminates and then cleans up all resources.
167 pub fn wait(self: *ChildProcess) !Term {165 pub fn wait(self: *ChildProcess) !Term {
168 if (is_windows) {166 if (os.windows.is_the_target) {
169 return self.waitWindows();167 return self.waitWindows();
170 } else {168 } else {
171 return self.waitPosix();169 return self.waitPosix();
...@@ -339,7 +337,7 @@ pub const ChildProcess = struct {...@@ -339,7 +337,7 @@ pub const ChildProcess = struct {
339 break :x env_map;337 break :x env_map;
340 } else x: {338 } else x: {
341 we_own_env_map = true;339 we_own_env_map = true;
342 env_map_owned = try os.getEnvMap(self.allocator);340 env_map_owned = try process.getEnvMap(self.allocator);
343 break :x &env_map_owned;341 break :x &env_map_owned;
344 };342 };
345 defer {343 defer {
...@@ -372,15 +370,15 @@ pub const ChildProcess = struct {...@@ -372,15 +370,15 @@ pub const ChildProcess = struct {
372 }370 }
373371
374 if (self.cwd) |cwd| {372 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);
376 }374 }
377375
378 if (self.gid) |gid| {376 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);
380 }378 }
381379
382 if (self.uid) |uid| {380 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);
384 }382 }
385383
386 os.execve(self.allocator, self.argv, env_map) catch |err| forkChildErrReport(err_pipe[1], err);384 os.execve(self.allocator, self.argv, env_map) catch |err| forkChildErrReport(err_pipe[1], err);
...@@ -541,7 +539,7 @@ pub const ChildProcess = struct {...@@ -541,7 +539,7 @@ pub const ChildProcess = struct {
541 // to match posix semantics539 // to match posix semantics
542 const app_name = x: {540 const app_name = x: {
543 if (self.cwd) |cwd| {541 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] });
545 defer self.allocator.free(resolved);543 defer self.allocator.free(resolved);
546 break :x try cstr.addNullByte(self.allocator, resolved);544 break :x try cstr.addNullByte(self.allocator, resolved);
547 } else {545 } else {
...@@ -559,12 +557,12 @@ pub const ChildProcess = struct {...@@ -559,12 +557,12 @@ pub const ChildProcess = struct {
559 windowsCreateProcess(app_name_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {557 windowsCreateProcess(app_name_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
560 if (no_path_err != error.FileNotFound) return no_path_err;558 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");
563 defer self.allocator.free(PATH);561 defer self.allocator.free(PATH);
564562
565 var it = mem.tokenize(PATH, ";");563 var it = mem.tokenize(PATH, ";");
566 while (it.next()) |search_path| {564 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 });
568 defer self.allocator.free(joined_path);566 defer self.allocator.free(joined_path);
569567
570 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);568 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);
...@@ -616,10 +614,10 @@ pub const ChildProcess = struct {...@@ -616,10 +614,10 @@ pub const ChildProcess = struct {
616614
617 fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) !void {615 fn setUpChildIo(stdio: StdIo, pipe_fd: i32, std_fileno: i32, dev_null_fd: i32) !void {
618 switch (stdio) {616 switch (stdio) {
619 StdIo.Pipe => try os.posixDup2(pipe_fd, std_fileno),617 StdIo.Pipe => try os.dup2(pipe_fd, std_fileno),
620 StdIo.Close => os.close(std_fileno),618 StdIo.Close => os.close(std_fileno),
621 StdIo.Inherit => {},619 StdIo.Inherit => {},
622 StdIo.Ignore => try os.posixDup2(dev_null_fd, std_fileno),620 StdIo.Ignore => try os.dup2(dev_null_fd, std_fileno),
623 }621 }
624 }622 }
625};623};
std/cstr.zig-15
...@@ -9,11 +9,6 @@ pub const line_sep = switch (builtin.os) {...@@ -9,11 +9,6 @@ pub const line_sep = switch (builtin.os) {
9 else => "\n",9 else => "\n",
10};10};
1111
12/// Deprecated, use mem.len
13pub fn len(ptr: [*]const u8) usize {
14 return mem.len(u8, ptr);
15}
16
17pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {12pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {
18 var index: usize = 0;13 var index: usize = 0;
19 while (a[index] == b[index] and a[index] != 0) : (index += 1) {}14 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 {...@@ -26,16 +21,6 @@ pub fn cmp(a: [*]const u8, b: [*]const u8) i8 {
26 }21 }
27}22}
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
39test "cstr fns" {24test "cstr fns" {
40 comptime testCStrFnsImpl();25 comptime testCStrFnsImpl();
41 testCStrFnsImpl();26 testCStrFnsImpl();
std/debug.zig+70-70
...@@ -3,16 +3,18 @@ const math = std.math;...@@ -3,16 +3,18 @@ const math = std.math;
3const mem = std.mem;3const mem = std.mem;
4const io = std.io;4const io = std.io;
5const os = std.os;5const os = std.os;
6const fs = std.fs;
7const process = std.process;
6const elf = std.elf;8const elf = std.elf;
7const DW = std.dwarf;9const DW = std.dwarf;
8const macho = std.macho;10const macho = std.macho;
9const coff = std.coff;11const coff = std.coff;
10const pdb = std.pdb;12const pdb = std.pdb;
11const windows = os.windows;
12const ArrayList = std.ArrayList;13const ArrayList = std.ArrayList;
13const builtin = @import("builtin");14const builtin = @import("builtin");
14const maxInt = std.math.maxInt;15const maxInt = std.math.maxInt;
15const File = std.fs.File;16const File = std.fs.File;
17const windows = std.os.windows;
1618
17const leb = @import("debug/leb128.zig");19const leb = @import("debug/leb128.zig");
1820
...@@ -20,8 +22,8 @@ pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAlloc...@@ -20,8 +22,8 @@ pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAlloc
20pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator;22pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator;
2123
22pub const runtime_safety = switch (builtin.mode) {24pub const runtime_safety = switch (builtin.mode) {
23 builtin.Mode.Debug, builtin.Mode.ReleaseSafe => true,25 .Debug, .ReleaseSafe => true,
24 builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => false,26 .ReleaseFast, .ReleaseSmall => false,
25};27};
2628
27const Module = struct {29const Module = struct {
...@@ -76,7 +78,7 @@ pub fn getSelfDebugInfo() !*DebugInfo {...@@ -76,7 +78,7 @@ pub fn getSelfDebugInfo() !*DebugInfo {
76fn wantTtyColor() bool {78fn wantTtyColor() bool {
77 var bytes: [128]u8 = undefined;79 var bytes: [128]u8 = undefined;
78 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;80 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();
80}82}
8183
82/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.84/// 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 {...@@ -100,47 +102,44 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
100/// chopping off the irrelevant frames and shifting so that the returned addresses pointer102/// chopping off the irrelevant frames and shifting so that the returned addresses pointer
101/// equals the passed in addresses pointer.103/// equals the passed in addresses pointer.
102pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {104pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {
103 switch (builtin.os) {105 if (windows.is_the_target) {
104 builtin.Os.windows => {106 const addrs = stack_trace.instruction_addresses;
105 const addrs = stack_trace.instruction_addresses;107 const u32_addrs_len = @intCast(u32, addrs.len);
106 const u32_addrs_len = @intCast(u32, addrs.len);108 const first_addr = first_address orelse {
107 const first_addr = first_address orelse {109 stack_trace.index = windows.ntdll.RtlCaptureStackBackTrace(
108 stack_trace.index = windows.RtlCaptureStackBackTrace(110 0,
109 0,111 u32_addrs_len,
110 u32_addrs_len,112 @ptrCast(**c_void, addrs.ptr),
111 @ptrCast(**c_void, addrs.ptr),113 null,
112 null,114 );
113 );115 return;
114 return;116 };
115 };117 var addr_buf_stack: [32]usize = undefined;
116 var addr_buf_stack: [32]usize = undefined;118 const addr_buf = if (addr_buf_stack.len > addrs.len) addr_buf_stack[0..] else addrs;
117 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);
118 const n = windows.RtlCaptureStackBackTrace(0, u32_addrs_len, @ptrCast(**c_void, addr_buf.ptr), null);120 const first_index = for (addr_buf[0..n]) |addr, i| {
119 const first_index = for (addr_buf[0..n]) |addr, i| {121 if (addr == first_addr) {
120 if (addr == first_addr) {122 break i;
121 break i;123 }
122 }124 } else {
123 } else {125 stack_trace.index = 0;
124 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;
125 return;139 return;
126 };140 };
127 const slice = addr_buf[first_index..n];141 }
128 // We use a for loop here because slice and addrs may alias.142 stack_trace.index = stack_trace.instruction_addresses.len;
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 },
144 }143 }
145}144}
146145
...@@ -260,9 +259,8 @@ pub const StackIterator = struct {...@@ -260,9 +259,8 @@ pub const StackIterator = struct {
260};259};
261260
262pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color: bool, start_addr: ?usize) !void {261pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color: bool, start_addr: ?usize) !void {
263 switch (builtin.os) {262 if (windows.is_the_target) {
264 builtin.Os.windows => return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr),263 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr);
265 else => {},
266 }264 }
267 var it = StackIterator.init(start_addr);265 var it = StackIterator.init(start_addr);
268 while (it.next()) |return_address| {266 while (it.next()) |return_address| {
...@@ -277,7 +275,7 @@ pub fn writeCurrentStackTraceWindows(...@@ -277,7 +275,7 @@ pub fn writeCurrentStackTraceWindows(
277 start_addr: ?usize,275 start_addr: ?usize,
278) !void {276) !void {
279 var addr_buf: [1024]usize = undefined;277 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);
281 const addrs = addr_buf[0..n];279 const addrs = addr_buf[0..n];
282 var start_i: usize = if (start_addr) |saddr| blk: {280 var start_i: usize = if (start_addr) |saddr| blk: {
283 for (addrs) |addr, i| {281 for (addrs) |addr, i| {
...@@ -291,17 +289,18 @@ pub fn writeCurrentStackTraceWindows(...@@ -291,17 +289,18 @@ pub fn writeCurrentStackTraceWindows(
291}289}
292290
293pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {291pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
294 switch (builtin.os) {292 if (windows.is_the_target) {
295 builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),293 return printSourceAtAddressWindows(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,
299 }294 }
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);
300}299}
301300
302fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_address: usize, tty_color: bool) !void {301fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_address: usize, tty_color: bool) !void {
303 const allocator = getDebugInfoAllocator();302 const allocator = getDebugInfoAllocator();
304 const base_address = os.getBaseAddress();303 const base_address = process.getBaseAddress();
305 const relative_address = relocated_address - base_address;304 const relative_address = relocated_address - base_address;
306305
307 var coff_section: *coff.Section = undefined;306 var coff_section: *coff.Section = undefined;
...@@ -331,7 +330,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -331,7 +330,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
331330
332 const mod = &di.modules[mod_index];331 const mod = &di.modules[mod_index];
333 try populateModule(di, mod);332 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
336 var symbol_i: usize = 0;335 var symbol_i: usize = 0;
337 const symbol_name = while (symbol_i != mod.symbols.len) {336 const symbol_name = while (symbol_i != mod.symbols.len) {
...@@ -634,7 +633,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach...@@ -634,7 +633,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach
634}633}
635634
636fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {635fn 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();
638 const adjusted_addr = 0x100000000 + (address - base_addr);637 const adjusted_addr = 0x100000000 + (address - base_addr);
639638
640 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {639 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
...@@ -649,7 +648,7 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt...@@ -649,7 +648,7 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
649 const symbol_name = mem.toSliceConst(u8, di.strings.ptr + symbol.nlist.n_strx);648 const symbol_name = mem.toSliceConst(u8, di.strings.ptr + symbol.nlist.n_strx);
650 const compile_unit_name = if (symbol.ofile) |ofile| blk: {649 const compile_unit_name = if (symbol.ofile) |ofile| blk: {
651 const ofile_path = mem.toSliceConst(u8, di.strings.ptr + ofile.n_strx);650 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);
653 } else "???";652 } else "???";
654 if (getLineNumberInfoMacOs(di, symbol.*, adjusted_addr)) |line_info| {653 if (getLineNumberInfoMacOs(di, symbol.*, adjusted_addr)) |line_info| {
655 defer line_info.deinit();654 defer line_info.deinit();
...@@ -716,7 +715,7 @@ pub fn printSourceAtAddressDwarf(...@@ -716,7 +715,7 @@ pub fn printSourceAtAddressDwarf(
716 }715 }
717}716}
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 {
720 return printSourceAtAddressDwarf(debug_info, out_stream, address, tty_color, printLineFromFileAnyOs);719 return printSourceAtAddressDwarf(debug_info, out_stream, address, tty_color, printLineFromFileAnyOs);
721}720}
722721
...@@ -776,16 +775,17 @@ pub const OpenSelfDebugInfoError = error{...@@ -776,16 +775,17 @@ pub const OpenSelfDebugInfoError = error{
776};775};
777776
778pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {777pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
779 switch (builtin.os) {778 if (windows.is_the_target) {
780 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return openSelfDebugInfoLinux(allocator),779 return openSelfDebugInfoWindows(allocator);
781 builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),780 }
782 builtin.Os.windows => return openSelfDebugInfoWindows(allocator),781 if (os.darwin.is_the_target) {
783 else => return error.UnsupportedOperatingSystem,782 return openSelfDebugInfoMacOs(allocator);
784 }783 }
784 return openSelfDebugInfoPosix(allocator);
785}785}
786786
787fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {787fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
788 const self_file = try os.openSelfExe();788 const self_file = try fs.openSelfExe();
789 defer self_file.close();789 defer self_file.close();
790790
791 const coff_obj = try allocator.create(coff.Coff);791 const coff_obj = try allocator.create(coff.Coff);
...@@ -812,7 +812,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {...@@ -812,7 +812,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
812 const len = try di.coff.getPdbPath(path_buf[0..]);812 const len = try di.coff.getPdbPath(path_buf[0..]);
813 const raw_path = path_buf[0..len];813 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
817 try di.pdb.openFile(di.coff, path);817 try di.pdb.openFile(di.coff, path);
818818
...@@ -1002,13 +1002,13 @@ pub fn openElfDebugInfo(...@@ -1002,13 +1002,13 @@ pub fn openElfDebugInfo(
1002 return di;1002 return di;
1003}1003}
10041004
1005fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DwarfInfo {1005fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
1006 const S = struct {1006 const S = struct {
1007 var self_exe_file: File = undefined;1007 var self_exe_file: File = undefined;
1008 var self_exe_mmap_seekable: io.SliceSeekableInStream = undefined;1008 var self_exe_mmap_seekable: io.SliceSeekableInStream = undefined;
1009 };1009 };
10101010
1011 S.self_exe_file = try os.openSelfExe();1011 S.self_exe_file = try fs.openSelfExe();
1012 errdefer S.self_exe_file.close();1012 errdefer S.self_exe_file.close();
10131013
1014 const self_exe_mmap_len = try S.self_exe_file.getEndPos();1014 const self_exe_mmap_len = try S.self_exe_file.getEndPos();
...@@ -1195,7 +1195,7 @@ pub const DwarfInfo = struct {...@@ -1195,7 +1195,7 @@ pub const DwarfInfo = struct {
1195};1195};
11961196
1197pub const DebugInfo = switch (builtin.os) {1197pub const DebugInfo = switch (builtin.os) {
1198 builtin.Os.macosx, builtin.Os.ios => struct {1198 .macosx, .ios, .watchos, .tvos => struct {
1199 symbols: []const MachoSymbol,1199 symbols: []const MachoSymbol,
1200 strings: []const u8,1200 strings: []const u8,
1201 ofiles: OFileTable,1201 ofiles: OFileTable,
...@@ -1211,13 +1211,13 @@ pub const DebugInfo = switch (builtin.os) {...@@ -1211,13 +1211,13 @@ pub const DebugInfo = switch (builtin.os) {
1211 return self.ofiles.allocator;1211 return self.ofiles.allocator;
1212 }1212 }
1213 },1213 },
1214 builtin.Os.uefi, builtin.Os.windows => struct {1214 .uefi, .windows => struct {
1215 pdb: pdb.Pdb,1215 pdb: pdb.Pdb,
1216 coff: *coff.Coff,1216 coff: *coff.Coff,
1217 sect_contribs: []pdb.SectionContribEntry,1217 sect_contribs: []pdb.SectionContribEntry,
1218 modules: []Module,1218 modules: []Module,
1219 },1219 },
1220 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => DwarfInfo,1220 .linux, .freebsd, .netbsd => DwarfInfo,
1221 else => @compileError("Unsupported OS"),1221 else => @compileError("Unsupported OS"),
1222};1222};
12231223
...@@ -1411,7 +1411,7 @@ const LineNumberProgram = struct {...@@ -1411,7 +1411,7 @@ const LineNumberProgram = struct {
1411 return error.InvalidDebugInfo;1411 return error.InvalidDebugInfo;
1412 } else1412 } else
1413 self.include_dirs[file_entry.dir_index];1413 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 });
1415 errdefer self.file_entries.allocator.free(file_name);1415 errdefer self.file_entries.allocator.free(file_name);
1416 return LineInfo{1416 return LineInfo{
1417 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,1417 .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");...@@ -2,7 +2,6 @@ const builtin = @import("builtin");
22
3const std = @import("std.zig");3const std = @import("std.zig");
4const mem = std.mem;4const mem = std.mem;
5const cstr = std.cstr;
6const os = std.os;5const os = std.os;
7const assert = std.debug.assert;6const assert = std.debug.assert;
8const testing = std.testing;7const testing = std.testing;
...@@ -223,7 +222,7 @@ pub const ElfLib = struct {...@@ -223,7 +222,7 @@ pub const ElfLib = struct {
223 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;222 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
224 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;223 if (0 == (u32(1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
225 if (0 == self.syms[i].st_shndx) continue;224 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;
227 if (maybe_versym) |versym| {226 if (maybe_versym) |versym| {
228 if (!checkver(self.verdef.?, versym[i], vername, self.strings))227 if (!checkver(self.verdef.?, versym[i], vername, self.strings))
229 continue;228 continue;
...@@ -246,7 +245,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [...@@ -246,7 +245,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
246 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);245 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
247 }246 }
248 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);247 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));
250}249}
251250
252pub const WindowsDynLib = struct {251pub const WindowsDynLib = struct {
std/event/fs.zig+6-6
...@@ -879,7 +879,7 @@ pub fn Watch(comptime V: type) type {...@@ -879,7 +879,7 @@ pub fn Watch(comptime V: type) type {
879 }879 }
880880
881 async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V {881 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});
883 var resolved_path_consumed = false;883 var resolved_path_consumed = false;
884 defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path);884 defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path);
885885
...@@ -967,12 +967,12 @@ pub fn Watch(comptime V: type) type {...@@ -967,12 +967,12 @@ pub fn Watch(comptime V: type) type {
967 async fn addFileLinux(self: *Self, file_path: []const u8, value: V) !?V {967 async fn addFileLinux(self: *Self, file_path: []const u8, value: V) !?V {
968 const value_copy = value;968 const value_copy = value;
969969
970 const dirname = os.path.dirname(file_path) orelse ".";970 const dirname = std.fs.path.dirname(file_path) orelse ".";
971 const dirname_with_null = try std.cstr.addNullByte(self.channel.loop.allocator, dirname);971 const dirname_with_null = try std.cstr.addNullByte(self.channel.loop.allocator, dirname);
972 var dirname_with_null_consumed = false;972 var dirname_with_null_consumed = false;
973 defer if (!dirname_with_null_consumed) self.channel.loop.allocator.free(dirname_with_null);973 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);
976 const basename_with_null = try std.cstr.addNullByte(self.channel.loop.allocator, basename);976 const basename_with_null = try std.cstr.addNullByte(self.channel.loop.allocator, basename);
977 var basename_with_null_consumed = false;977 var basename_with_null_consumed = false;
978 defer if (!basename_with_null_consumed) self.channel.loop.allocator.free(basename_with_null);978 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 {...@@ -1013,7 +1013,7 @@ pub fn Watch(comptime V: type) type {
1013 const value_copy = value;1013 const value_copy = value;
1014 // TODO we might need to convert dirname and basename to canonical file paths ("short"?)1014 // 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 ".");
1017 var dirname_consumed = false;1017 var dirname_consumed = false;
1018 defer if (!dirname_consumed) self.channel.loop.allocator.free(dirname);1018 defer if (!dirname_consumed) self.channel.loop.allocator.free(dirname);
10191019
...@@ -1021,7 +1021,7 @@ pub fn Watch(comptime V: type) type {...@@ -1021,7 +1021,7 @@ pub fn Watch(comptime V: type) type {
1021 defer self.channel.loop.allocator.free(dirname_utf16le);1021 defer self.channel.loop.allocator.free(dirname_utf16le);
10221022
1023 // TODO https://github.com/ziglang/zig/issues/2651023 // 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);
1025 const basename_utf16le_null = try std.unicode.utf8ToUtf16LeWithNull(self.channel.loop.allocator, basename);1025 const basename_utf16le_null = try std.unicode.utf8ToUtf16LeWithNull(self.channel.loop.allocator, basename);
1026 var basename_utf16le_null_consumed = false;1026 var basename_utf16le_null_consumed = false;
1027 defer if (!basename_utf16le_null_consumed) self.channel.loop.allocator.free(basename_utf16le_null);1027 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 {...@@ -1334,7 +1334,7 @@ async fn testFsWatchCantFail(loop: *Loop, result: *(anyerror!void)) void {
1334}1334}
13351335
1336async fn testFsWatch(loop: *Loop) !void {1336async 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" });
1338 defer loop.allocator.free(file_path);1338 defer loop.allocator.free(file_path);
13391339
1340 const contents =1340 const contents =
std/fmt.zig+1-1
...@@ -226,7 +226,7 @@ pub fn formatType(...@@ -226,7 +226,7 @@ pub fn formatType(
226 builtin.TypeInfo.Pointer.Size.Many => {226 builtin.TypeInfo.Pointer.Size.Many => {
227 if (ptr_info.child == u8) {227 if (ptr_info.child == u8) {
228 if (fmt.len > 0 and fmt[0] == 's') {228 if (fmt.len > 0 and fmt[0] == 's') {
229 const len = std.cstr.len(value);229 const len = mem.len(u8, value);
230 return formatText(value[0..len], fmt, context, Errors, output);230 return formatText(value[0..len], fmt, context, Errors, output);
231 }231 }
232 }232 }
std/fs.zig+10-10
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const builtin = @import("builtin");
1const std = @import("std.zig");2const std = @import("std.zig");
2const os = std.os;3const os = std.os;
3const mem = std.mem;4const mem = std.mem;
5const Allocator = std.mem.Allocator;
46
5pub const path = @import("fs/path.zig");7pub const path = @import("fs/path.zig");
6pub const File = @import("fs/file.zig").File;8pub const File = @import("fs/file.zig").File;
...@@ -12,8 +14,6 @@ pub const deleteFileC = os.unlinkC;...@@ -12,8 +14,6 @@ pub const deleteFileC = os.unlinkC;
12pub const rename = os.rename;14pub const rename = os.rename;
13pub const renameC = os.renameC;15pub const renameC = os.renameC;
14pub const renameW = os.renameW;16pub const renameW = os.renameW;
15pub const changeCurDir = os.chdir;
16pub const changeCurDirC = os.chdirC;
17pub const realpath = os.realpath;17pub const realpath = os.realpath;
18pub const realpathC = os.realpathC;18pub const realpathC = os.realpathC;
19pub const realpathW = os.realpathW;19pub const realpathW = os.realpathW;
...@@ -65,13 +65,13 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:...@@ -65,13 +65,13 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
65 else => return err, // TODO zig should know this set does not include PathAlreadyExists65 else => return err, // TODO zig should know this set does not include PathAlreadyExists
66 }66 }
6767
68 const dirname = os.path.dirname(new_path) orelse ".";68 const dirname = path.dirname(new_path) orelse ".";
6969
70 var rand_buf: [12]u8 = undefined;70 var rand_buf: [12]u8 = undefined;
71 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64.Base64Encoder.calcSize(rand_buf.len));71 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64.Base64Encoder.calcSize(rand_buf.len));
72 defer allocator.free(tmp_path);72 defer allocator.free(tmp_path);
73 mem.copy(u8, tmp_path[0..], dirname);73 mem.copy(u8, tmp_path[0..], dirname);
74 tmp_path[dirname.len] = os.path.sep;74 tmp_path[dirname.len] = path.sep;
75 while (true) {75 while (true) {
76 try getRandomBytes(rand_buf[0..]);76 try getRandomBytes(rand_buf[0..]);
77 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);77 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
...@@ -143,7 +143,7 @@ pub const AtomicFile = struct {...@@ -143,7 +143,7 @@ pub const AtomicFile = struct {
143 /// TODO once we have null terminated pointers, use the143 /// TODO once we have null terminated pointers, use the
144 /// openWriteNoClobberN function144 /// openWriteNoClobberN function
145 pub fn init(dest_path: []const u8, mode: File.Mode) InitError!AtomicFile {145 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);
147 var rand_buf: [12]u8 = undefined;147 var rand_buf: [12]u8 = undefined;
148 const dirname_component_len = if (dirname) |d| d.len + 1 else 0;148 const dirname_component_len = if (dirname) |d| d.len + 1 else 0;
149 const encoded_rand_len = comptime base64.Base64Encoder.calcSize(rand_buf.len);149 const encoded_rand_len = comptime base64.Base64Encoder.calcSize(rand_buf.len);
...@@ -153,7 +153,7 @@ pub const AtomicFile = struct {...@@ -153,7 +153,7 @@ pub const AtomicFile = struct {
153153
154 if (dirname) |dir| {154 if (dirname) |dir| {
155 mem.copy(u8, tmp_path_buf[0..], dir);155 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;
157 }157 }
158158
159 tmp_path_buf[tmp_path_len] = 0;159 tmp_path_buf[tmp_path_len] = 0;
...@@ -240,7 +240,7 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {...@@ -240,7 +240,7 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
240 // march end_index backward until next path component240 // march end_index backward until next path component
241 while (true) {241 while (true) {
242 end_index -= 1;242 end_index -= 1;
243 if (os.path.isSep(resolved_path[end_index])) break;243 if (path.isSep(resolved_path[end_index])) break;
244 }244 }
245 continue;245 continue;
246 },246 },
...@@ -250,7 +250,7 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {...@@ -250,7 +250,7 @@ pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
250 // march end_index forward until next path component250 // march end_index forward until next path component
251 while (true) {251 while (true) {
252 end_index += 1;252 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;
254 }254 }
255 }255 }
256}256}
...@@ -614,7 +614,7 @@ pub const Dir = struct {...@@ -614,7 +614,7 @@ pub const Dir = struct {
614 const next_index = self.handle.index + linux_entry.d_reclen;614 const next_index = self.handle.index + linux_entry.d_reclen;
615 self.handle.index = next_index;615 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
619 // skip . and .. entries619 // skip . and .. entries
620 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {620 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 {...@@ -709,7 +709,7 @@ pub fn readLinkC(pathname: [*]const u8, buffer: *[os.PATH_MAX]u8) ![]u8 {
709 return os.readlinkC(pathname, buffer);709 return os.readlinkC(pathname, buffer);
710}710}
711711
712pub const OpenSelfExeError = error{};712pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError;
713713
714pub fn openSelfExe() OpenSelfExeError!File {714pub fn openSelfExe() OpenSelfExeError!File {
715 if (os.linux.is_the_target) {715 if (os.linux.is_the_target) {
std/fs/file.zig-24
...@@ -307,28 +307,4 @@ pub const File = struct {...@@ -307,28 +307,4 @@ pub const File = struct {
307 return self.file.getPos();307 return self.file.getPos();
308 }308 }
309 };309 };
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 }
334};310};
std/fs/get_app_data_dir.zig+7-6
...@@ -2,6 +2,7 @@ const std = @import("../std.zig");...@@ -2,6 +2,7 @@ const std = @import("../std.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const unicode = std.unicode;3const unicode = std.unicode;
4const mem = std.mem;4const mem = std.mem;
5const fs = std.fs;
5const os = std.os;6const os = std.os;
67
7pub const GetAppDataDirError = error{8pub const GetAppDataDirError = error{
...@@ -15,7 +16,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -15,7 +16,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
15 switch (builtin.os) {16 switch (builtin.os) {
16 .windows => {17 .windows => {
17 var dir_path_ptr: [*]u16 = undefined;18 var dir_path_ptr: [*]u16 = undefined;
18 switch (os.windows.SHGetKnownFolderPath(19 switch (os.windows.shell32.SHGetKnownFolderPath(
19 &os.windows.FOLDERID_LocalAppData,20 &os.windows.FOLDERID_LocalAppData,
20 os.windows.KF_FLAG_CREATE,21 os.windows.KF_FLAG_CREATE,
21 null,22 null,
...@@ -30,25 +31,25 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -30,25 +31,25 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
30 error.OutOfMemory => return error.OutOfMemory,31 error.OutOfMemory => return error.OutOfMemory,
31 };32 };
32 defer allocator.free(global_dir);33 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 });
34 },35 },
35 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,36 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
36 else => return error.AppDataDirUnavailable,37 else => return error.AppDataDirUnavailable,
37 }38 }
38 },39 },
39 .macosx => {40 .macosx => {
40 const home_dir = os.getEnvPosix("HOME") orelse {41 const home_dir = os.getenv("HOME") orelse {
41 // TODO look in /etc/passwd42 // TODO look in /etc/passwd
42 return error.AppDataDirUnavailable;43 return error.AppDataDirUnavailable;
43 };44 };
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 });
45 },46 },
46 .linux, .freebsd, .netbsd => {47 .linux, .freebsd, .netbsd => {
47 const home_dir = os.getEnvPosix("HOME") orelse {48 const home_dir = os.getenv("HOME") orelse {
48 // TODO look in /etc/passwd49 // TODO look in /etc/passwd
49 return error.AppDataDirUnavailable;50 return error.AppDataDirUnavailable;
50 };51 };
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 });
52 },53 },
53 else => @compileError("Unsupported OS"),54 else => @compileError("Unsupported OS"),
54 }55 }
std/fs/path.zig+10-12
...@@ -1,16 +1,14 @@...@@ -1,16 +1,14 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const Os = builtin.Os;2const std = @import("../std.zig");
4const debug = std.debug;3const debug = std.debug;
5const assert = debug.assert;4const assert = debug.assert;
6const testing = std.testing;5const testing = std.testing;
7const mem = std.mem;6const mem = std.mem;
8const fmt = std.fmt;7const fmt = std.fmt;
9const Allocator = mem.Allocator;8const Allocator = mem.Allocator;
10const os = std.os;
11const math = std.math;9const math = std.math;
12const windows = os.windows;10const windows = std.os.windows;
13const cstr = std.cstr;11const fs = std.fs;
1412
15pub const sep_windows = '\\';13pub const sep_windows = '\\';
16pub const sep_posix = '/';14pub const sep_posix = '/';
...@@ -392,7 +390,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -392,7 +390,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
392pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {390pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
393 if (paths.len == 0) {391 if (paths.len == 0) {
394 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd392 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd
395 return os.getCwdAlloc(allocator);393 return fs.getCwdAlloc(allocator);
396 }394 }
397395
398 // determine which disk designator we will result with, if any396 // determine which disk designator we will result with, if any
...@@ -487,7 +485,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -487,7 +485,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
487 },485 },
488 WindowsPath.Kind.None => {486 WindowsPath.Kind.None => {
489 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd487 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);
491 defer allocator.free(cwd);489 defer allocator.free(cwd);
492 const parsed_cwd = windowsParsePath(cwd);490 const parsed_cwd = windowsParsePath(cwd);
493 result = try allocator.alloc(u8, max_size + parsed_cwd.disk_designator.len + 1);491 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 {...@@ -503,7 +501,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
503 } else {501 } else {
504 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd502 assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd
505 // TODO call get cwd for the result_disk_designator instead of the global one503 // 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);
507 defer allocator.free(cwd);505 defer allocator.free(cwd);
508506
509 result = try allocator.alloc(u8, max_size + cwd.len + 1);507 result = try allocator.alloc(u8, max_size + cwd.len + 1);
...@@ -573,7 +571,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -573,7 +571,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
573pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {571pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
574 if (paths.len == 0) {572 if (paths.len == 0) {
575 assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd573 assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd
576 return os.getCwdAlloc(allocator);574 return fs.getCwdAlloc(allocator);
577 }575 }
578576
579 var first_index: usize = 0;577 var first_index: usize = 0;
...@@ -595,7 +593,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -595,7 +593,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
595 result = try allocator.alloc(u8, max_size);593 result = try allocator.alloc(u8, max_size);
596 } else {594 } else {
597 assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd595 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);
599 defer allocator.free(cwd);597 defer allocator.free(cwd);
600 result = try allocator.alloc(u8, max_size + cwd.len + 1);598 result = try allocator.alloc(u8, max_size + cwd.len + 1);
601 mem.copy(u8, result, cwd);599 mem.copy(u8, result, cwd);
...@@ -634,7 +632,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -634,7 +632,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
634}632}
635633
636test "resolve" {634test "resolve" {
637 const cwd = try os.getCwdAlloc(debug.global_allocator);635 const cwd = try fs.getCwdAlloc(debug.global_allocator);
638 if (windows.is_the_target) {636 if (windows.is_the_target) {
639 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {637 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
640 cwd[0] = asciiUpper(cwd[0]);638 cwd[0] = asciiUpper(cwd[0]);
...@@ -648,7 +646,7 @@ test "resolve" {...@@ -648,7 +646,7 @@ test "resolve" {
648646
649test "resolveWindows" {647test "resolveWindows" {
650 if (windows.is_the_target) {648 if (windows.is_the_target) {
651 const cwd = try os.getCwdAlloc(debug.global_allocator);649 const cwd = try fs.getCwdAlloc(debug.global_allocator);
652 const parsed_cwd = windowsParsePath(cwd);650 const parsed_cwd = windowsParsePath(cwd);
653 {651 {
654 const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });652 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 {...@@ -103,7 +103,7 @@ pub const DirectAllocator = struct {
103 return @ptrCast([*]u8, final_addr)[0..n];103 return @ptrCast([*]u8, final_addr)[0..n];
104 }104 }
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;
107 const addr = os.mmap(107 const addr = os.mmap(
108 null,108 null,
109 alloc_size,109 alloc_size,
...@@ -123,7 +123,7 @@ pub const DirectAllocator = struct {...@@ -123,7 +123,7 @@ pub const DirectAllocator = struct {
123 if (unused_start_len != 0) {123 if (unused_start_len != 0) {
124 os.munmap(addr, unused_start_len);124 os.munmap(addr, unused_start_len);
125 }125 }
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);
127 const unused_end_len = addr + alloc_size - aligned_end_addr;127 const unused_end_len = addr + alloc_size - aligned_end_addr;
128 if (unused_end_len != 0) {128 if (unused_end_len != 0) {
129 os.munmap(aligned_end_addr, unused_end_len);129 os.munmap(aligned_end_addr, unused_end_len);
...@@ -147,7 +147,7 @@ pub const DirectAllocator = struct {...@@ -147,7 +147,7 @@ pub const DirectAllocator = struct {
147 const base_addr = @ptrToInt(old_mem.ptr);147 const base_addr = @ptrToInt(old_mem.ptr);
148 const old_addr_end = base_addr + old_mem.len;148 const old_addr_end = base_addr + old_mem.len;
149 const new_addr_end = base_addr + new_size;149 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);
151 if (old_addr_end > new_addr_end_rounded) {151 if (old_addr_end > new_addr_end_rounded) {
152 // For shrinking that is not releasing, we will only152 // For shrinking that is not releasing, we will only
153 // decommit the pages not needed anymore.153 // decommit the pages not needed anymore.
...@@ -163,7 +163,7 @@ pub const DirectAllocator = struct {...@@ -163,7 +163,7 @@ pub const DirectAllocator = struct {
163 const base_addr = @ptrToInt(old_mem.ptr);163 const base_addr = @ptrToInt(old_mem.ptr);
164 const old_addr_end = base_addr + old_mem.len;164 const old_addr_end = base_addr + old_mem.len;
165 const new_addr_end = base_addr + new_size;165 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);
167 if (old_addr_end > new_addr_end_rounded) {167 if (old_addr_end > new_addr_end_rounded) {
168 os.munmap(new_addr_end_rounded, old_addr_end - new_addr_end_rounded);168 os.munmap(new_addr_end_rounded, old_addr_end - new_addr_end_rounded);
169 }169 }
...@@ -196,9 +196,9 @@ pub const DirectAllocator = struct {...@@ -196,9 +196,9 @@ pub const DirectAllocator = struct {
196 }196 }
197197
198 const old_addr_end = base_addr + old_mem.len;198 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);
200 const new_addr_end = base_addr + new_size;200 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);
202 if (new_addr_end_rounded == old_addr_end_rounded) {202 if (new_addr_end_rounded == old_addr_end_rounded) {
203 // The reallocation fits in the already allocated pages.203 // The reallocation fits in the already allocated pages.
204 return @ptrCast([*]u8, old_mem.ptr)[0..new_size];204 return @ptrCast([*]u8, old_mem.ptr)[0..new_size];
...@@ -374,7 +374,7 @@ pub const ArenaAllocator = struct {...@@ -374,7 +374,7 @@ pub const ArenaAllocator = struct {
374 var len = prev_len;374 var len = prev_len;
375 while (true) {375 while (true) {
376 len += len / 2;376 len += len / 2;
377 len += os.page_size - @rem(len, os.page_size);377 len += mem.page_size - @rem(len, mem.page_size);
378 if (len >= actual_min_size) break;378 if (len >= actual_min_size) break;
379 }379 }
380 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);380 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);
...@@ -520,11 +520,11 @@ const WasmAllocator = struct {...@@ -520,11 +520,11 @@ const WasmAllocator = struct {
520 const adjusted_index = self.end_index + (adjusted_addr - addr);520 const adjusted_index = self.end_index + (adjusted_addr - addr);
521 const new_end_index = adjusted_index + size;521 const new_end_index = adjusted_index + size;
522522
523 if (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 * os.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;526 var num_pages: usize = required_memory / mem.page_size;
527 if (required_memory % os.page_size != 0) {527 if (required_memory % mem.page_size != 0) {
528 num_pages += 1;528 num_pages += 1;
529 }529 }
530530
...@@ -553,14 +553,14 @@ const WasmAllocator = struct {...@@ -553,14 +553,14 @@ const WasmAllocator = struct {
553553
554 // Initialize start_ptr at the first realloc554 // Initialize start_ptr at the first realloc
555 if (self.num_pages == 0) {555 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);
557 }557 }
558558
559 if (is_last_item(allocator, old_mem, new_align)) {559 if (is_last_item(allocator, old_mem, new_align)) {
560 const start_index = self.end_index - old_mem.len;560 const start_index = self.end_index - old_mem.len;
561 const new_end_index = start_index + new_size;561 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) {
564 _ = try alloc(allocator, new_end_index - self.end_index, new_align);564 _ = try alloc(allocator, new_end_index - self.end_index, new_align);
565 }565 }
566 const result = self.start_ptr[start_index..new_end_index];566 const result = self.start_ptr[start_index..new_end_index];
...@@ -876,10 +876,10 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi...@@ -876,10 +876,10 @@ fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !voi
876fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {876fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
877 //Maybe a platform's page_size is actually the same as or877 //Maybe a platform's page_size is actually the same as or
878 // very near usize?878 // very near usize?
879 if (os.page_size << 2 > maxInt(usize)) return;879 if (mem.page_size << 2 > maxInt(usize)) return;
880880
881 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));881 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
884 var align_mask: usize = undefined;884 var align_mask: usize = undefined;
885 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask);885 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(u29, large_align)), &align_mask);
...@@ -906,7 +906,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi...@@ -906,7 +906,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi
906 var debug_buffer: [1000]u8 = undefined;906 var debug_buffer: [1000]u8 = undefined;
907 const debug_allocator = &FixedBufferAllocator.init(&debug_buffer).allocator;907 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;
910 var slice = try allocator.alignedAlloc(u8, 16, alloc_size);910 var slice = try allocator.alignedAlloc(u8, 16, alloc_size);
911 defer allocator.free(slice);911 defer allocator.free(slice);
912912
...@@ -915,7 +915,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi...@@ -915,7 +915,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi
915 // which is 16 pages, hence the 32. This test may require to increase915 // which is 16 pages, hence the 32. This test may require to increase
916 // the size of the allocations feeding the `allocator` parameter if they916 // the size of the allocations feeding the `allocator` parameter if they
917 // fail, because of this high over-alignment we want to have.917 // 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)) {
919 try stuff_to_free.append(slice);919 try stuff_to_free.append(slice);
920 slice = try allocator.alignedAlloc(u8, 16, alloc_size);920 slice = try allocator.alignedAlloc(u8, 16, alloc_size);
921 }921 }
...@@ -926,7 +926,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi...@@ -926,7 +926,7 @@ fn testAllocatorAlignedShrink(allocator: *mem.Allocator) mem.Allocator.Error!voi
926 slice[60] = 0x34;926 slice[60] = 0x34;
927927
928 // realloc to a smaller size but with a larger alignment928 // 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);
930 testing.expect(slice[0] == 0x12);930 testing.expect(slice[0] == 0x12);
931 testing.expect(slice[60] == 0x34);931 testing.expect(slice[60] == 0x34);
932}932}
std/io.zig+25-2
...@@ -15,8 +15,31 @@ const fmt = std.fmt;...@@ -15,8 +15,31 @@ const fmt = std.fmt;
15const File = std.fs.File;15const File = std.fs.File;
16const testing = std.testing;16const testing = std.testing;
1717
18const is_posix = builtin.os != builtin.Os.windows;18pub const GetStdIoError = os.windows.GetStdHandleError;
19const is_windows = builtin.os == builtin.Os.windows;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
21pub const SeekableStream = @import("io/seekable_stream.zig").SeekableStream;44pub const SeekableStream = @import("io/seekable_stream.zig").SeekableStream;
22pub const SliceSeekableInStream = @import("io/seekable_stream.zig").SliceSeekableInStream;45pub const SliceSeekableInStream = @import("io/seekable_stream.zig").SliceSeekableInStream;
std/mem.zig-18
...@@ -1462,21 +1462,3 @@ test "std.mem.alignForward" {...@@ -1462,21 +1462,3 @@ test "std.mem.alignForward" {
1462 testing.expect(alignForward(16, 8) == 16);1462 testing.expect(alignForward(16, 8) == 16);
1463 testing.expect(alignForward(17, 8) == 24);1463 testing.expect(alignForward(17, 8) == 24);
1464}1464}
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 @@...@@ -8,7 +8,7 @@
8// cross platform abstracting.8// cross platform abstracting.
9// * When there exists a corresponding libc function and linking libc, the libc9// * When there exists a corresponding libc function and linking libc, the libc
10// implementation is used. Exceptions are made for known buggy areas of libc.10// 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.
12// * For Windows, this file represents the API that libc would provide for12// * For Windows, this file represents the API that libc would provide for
13// Windows. For thin wrappers around Windows-specific APIs, see `std.os.windows`.13// Windows. For thin wrappers around Windows-specific APIs, see `std.os.windows`.
14// Note: The Zig standard library does not support POSIX thread cancellation, and14// Note: The Zig standard library does not support POSIX thread cancellation, and
...@@ -16,7 +16,9 @@...@@ -16,7 +16,9 @@
1616
17const std = @import("std.zig");17const std = @import("std.zig");
18const builtin = @import("builtin");18const builtin = @import("builtin");
19const assert = std.debug.assert;
19const math = std.math;20const math = std.math;
21const mem = std.mem;
20const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;22const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
2123
22comptime {24comptime {
...@@ -46,9 +48,14 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {...@@ -46,9 +48,14 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {
4648
47pub use @import("os/bits.zig");49pub use @import("os/bits.zig");
4850
49/// See also `getenv`.51/// See also `getenv`. Populated by startup code before main().
50pub var environ: [][*]u8 = undefined;52pub 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
52/// To obtain errno, call this function with the return value of the59/// To obtain errno, call this function with the return value of the
53/// system function call. For some systems this will obtain the value directly60/// system function call. For some systems this will obtain the value directly
54/// from the return code; for others it will use a thread-local errno variable.61/// 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 {...@@ -103,7 +110,7 @@ pub fn getrandom(buf: []u8) GetRandomError!void {
103 }110 }
104 }111 }
105 if (wasi.is_the_target) {112 if (wasi.is_the_target) {
106 switch (os.wasi.random_get(buf.ptr, buf.len)) {113 switch (wasi.random_get(buf.ptr, buf.len)) {
107 0 => return,114 0 => return,
108 else => |err| return unexpectedErrno(err),115 else => |err| return unexpectedErrno(err),
109 }116 }
...@@ -138,15 +145,15 @@ pub fn abort() noreturn {...@@ -138,15 +145,15 @@ pub fn abort() noreturn {
138 while (true) {}145 while (true) {}
139 }146 }
140147
141 raise(SIGABRT);148 raise(SIGABRT) catch {};
142149
143 // TODO the rest of the implementation of abort() from musl libc here150 // TODO the rest of the implementation of abort() from musl libc here
144151
145 raise(SIGKILL);152 raise(SIGKILL) catch {};
146 exit(127);153 exit(127);
147}154}
148155
149pub const RaiseError = error{};156pub const RaiseError = error{Unexpected};
150157
151pub fn raise(sig: u8) RaiseError!void {158pub fn raise(sig: u8) RaiseError!void {
152 if (builtin.link_libc) {159 if (builtin.link_libc) {
...@@ -163,19 +170,19 @@ pub fn raise(sig: u8) RaiseError!void {...@@ -163,19 +170,19 @@ pub fn raise(sig: u8) RaiseError!void {
163 }170 }
164 }171 }
165172
166 if (windows.is_the_target) {173 if (linux.is_the_target) {
167 @compileError("TODO implement std.os.raise for Windows");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 }
168 }183 }
169184
170 var set: system.sigset_t = undefined;185 @compileError("std.os.raise unimplemented for this target");
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 }
179}186}
180187
181pub const KillError = error{188pub const KillError = error{
...@@ -229,13 +236,13 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -229,13 +236,13 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
229 }236 }
230237
231 if (wasi.is_the_target and !builtin.link_libc) {238 if (wasi.is_the_target and !builtin.link_libc) {
232 const iovs = [1]was.iovec_t{wasi.iovec_t{239 const iovs = [1]iovec{iovec{
233 .buf = buf.ptr,240 .iov_base = buf.ptr,
234 .buf_len = buf.len,241 .iov_len = buf.len,
235 }};242 }};
236243
237 var nread: usize = undefined;244 var nread: usize = undefined;
238 switch (fd_read(fd, &iovs, iovs.len, &nread)) {245 switch (wasi.fd_read(fd, &iovs, iovs.len, &nread)) {
239 0 => return nread,246 0 => return nread,
240 else => |err| return unexpectedErrno(err),247 else => |err| return unexpectedErrno(err),
241 }248 }
...@@ -277,7 +284,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -277,7 +284,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
277/// This function is for blocking file descriptors only. For non-blocking, see284/// This function is for blocking file descriptors only. For non-blocking, see
278/// `preadvAsync`.285/// `preadvAsync`.
279pub fn preadv(fd: fd_t, iov: [*]const iovec, count: usize, offset: u64) ReadError!usize {286pub 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) {
281 // Darwin does not have preadv but it does have pread.288 // Darwin does not have preadv but it does have pread.
282 var off: usize = 0;289 var off: usize = 0;
283 var iov_i: usize = 0;290 var iov_i: usize = 0;
...@@ -353,12 +360,12 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {...@@ -353,12 +360,12 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
353 }360 }
354361
355 if (wasi.is_the_target and !builtin.link_libc) {362 if (wasi.is_the_target and !builtin.link_libc) {
356 const ciovs = [1]wasi.ciovec_t{wasi.ciovec_t{363 const ciovs = [1]iovec_const{iovec_const{
357 .buf = bytes.ptr,364 .iov_base = bytes.ptr,
358 .buf_len = bytes.len,365 .iov_len = bytes.len,
359 }};366 }};
360 var nwritten: usize = undefined;367 var nwritten: usize = undefined;
361 switch (fd_write(fd, &ciovs, ciovs.len, &nwritten)) {368 switch (wasi.fd_write(fd, &ciovs, ciovs.len, &nwritten)) {
362 0 => return,369 0 => return,
363 else => |err| return unexpectedErrno(err),370 else => |err| return unexpectedErrno(err),
364 }371 }
...@@ -538,29 +545,29 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {...@@ -538,29 +545,29 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
538/// `argv[0]` is the executable path.545/// `argv[0]` is the executable path.
539/// This function also uses the PATH environment variable to get the full path to the executable.546/// This function also uses the PATH environment variable to get the full path to the executable.
540/// TODO provide execveC which does not take an allocator547/// TODO provide execveC which does not take an allocator
541pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const BufMap) !void {548pub fn execve(allocator: *mem.Allocator, argv_slice: []const []const u8, env_map: *const std.BufMap) !void {
542 const argv_buf = try allocator.alloc(?[*]u8, argv.len + 1);549 const argv_buf = try allocator.alloc(?[*]u8, argv_slice.len + 1);
543 mem.set(?[*]u8, argv_buf, null);550 mem.set(?[*]u8, argv_buf, null);
544 defer {551 defer {
545 for (argv_buf) |arg| {552 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;
547 allocator.free(arg_buf);554 allocator.free(arg_buf);
548 }555 }
549 allocator.free(argv_buf);556 allocator.free(argv_buf);
550 }557 }
551 for (argv) |arg, i| {558 for (argv_slice) |arg, i| {
552 const arg_buf = try allocator.alloc(u8, arg.len + 1);559 const arg_buf = try allocator.alloc(u8, arg.len + 1);
553 @memcpy(arg_buf.ptr, arg.ptr, arg.len);560 @memcpy(arg_buf.ptr, arg.ptr, arg.len);
554 arg_buf[arg.len] = 0;561 arg_buf[arg.len] = 0;
555562
556 argv_buf[i] = arg_buf.ptr;563 argv_buf[i] = arg_buf.ptr;
557 }564 }
558 argv_buf[argv.len] = null;565 argv_buf[argv_slice.len] = null;
559566
560 const envp_buf = try createNullDelimitedEnvMap(allocator, env_map);567 const envp_buf = try createNullDelimitedEnvMap(allocator, env_map);
561 defer freeNullDelimitedEnvMap(allocator, envp_buf);568 defer freeNullDelimitedEnvMap(allocator, envp_buf);
562569
563 const exe_path = argv[0];570 const exe_path = argv_slice[0];
564 if (mem.indexOfScalar(u8, exe_path, '/') != null) {571 if (mem.indexOfScalar(u8, exe_path, '/') != null) {
565 return execveErrnoToErr(errno(system.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr)));572 return execveErrnoToErr(errno(system.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr)));
566 }573 }
...@@ -593,7 +600,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B...@@ -593,7 +600,7 @@ pub fn execve(allocator: *Allocator, argv: []const []const u8, env_map: *const B
593 return execveErrnoToErr(err);600 return execveErrnoToErr(err);
594}601}
595602
596pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap) ![]?[*]u8 {603pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*]u8 {
597 const envp_count = env_map.count();604 const envp_count = env_map.count();
598 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);605 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);
599 mem.set(?[*]u8, envp_buf, null);606 mem.set(?[*]u8, envp_buf, null);
...@@ -616,9 +623,9 @@ pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap)...@@ -616,9 +623,9 @@ pub fn createNullDelimitedEnvMap(allocator: *Allocator, env_map: *const BufMap)
616 return envp_buf;623 return envp_buf;
617}624}
618625
619pub fn freeNullDelimitedEnvMap(allocator: *Allocator, envp_buf: []?[*]u8) void {626pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*]u8) void {
620 for (envp_buf) |env| {627 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;
622 allocator.free(env_buf);629 allocator.free(env_buf);
623 }630 }
624 allocator.free(envp_buf);631 allocator.free(envp_buf);
...@@ -633,6 +640,8 @@ pub const ExecveError = error{...@@ -633,6 +640,8 @@ pub const ExecveError = error{
633 FileNotFound,640 FileNotFound,
634 NotDir,641 NotDir,
635 FileBusy,642 FileBusy,
643 ProcessFdQuotaExceeded,
644 NameTooLong,
636645
637 Unexpected,646 Unexpected,
638};647};
...@@ -703,17 +712,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -703,17 +712,17 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
703 }712 }
704713
705 const err = if (builtin.link_libc) blk: {714 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().*;
707 } else blk: {716 } 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));
709 };718 };
710 switch (err) {719 switch (err) {
711 0 => return mem.toSlice(u8, out_buffer),720 0 => return mem.toSlice(u8, out_buffer.ptr),
712 EFAULT => unreachable,721 EFAULT => unreachable,
713 EINVAL => unreachable,722 EINVAL => unreachable,
714 ENOENT => return error.CurrentWorkingDirectoryUnlinked,723 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
715 ERANGE => return error.NameTooLong,724 ERANGE => return error.NameTooLong,
716 else => |err| return unexpectedErrno(err),725 else => return unexpectedErrno(err),
717 }726 }
718}727}
719728
...@@ -1711,8 +1720,8 @@ pub const FStatError = error{...@@ -1711,8 +1720,8 @@ pub const FStatError = error{
17111720
1712pub fn fstat(fd: fd_t) FStatError!Stat {1721pub fn fstat(fd: fd_t) FStatError!Stat {
1713 var stat: Stat = undefined;1722 var stat: Stat = undefined;
1714 if (os.darwin.is_the_target) {1723 if (darwin.is_the_target) {
1715 switch (errno(system.@"fstat$INODE64"(fd, buf))) {1724 switch (errno(system.@"fstat$INODE64"(fd, &stat))) {
1716 0 => return stat,1725 0 => return stat,
1717 EBADF => unreachable, // Always a race condition.1726 EBADF => unreachable, // Always a race condition.
1718 ENOMEM => return error.SystemResources,1727 ENOMEM => return error.SystemResources,
...@@ -1877,7 +1886,7 @@ pub const ForkError = error{...@@ -1877,7 +1886,7 @@ pub const ForkError = error{
1877pub fn fork() ForkError!pid_t {1886pub fn fork() ForkError!pid_t {
1878 const rc = system.fork();1887 const rc = system.fork();
1879 switch (errno(rc)) {1888 switch (errno(rc)) {
1880 0 => return rc,1889 0 => return @intCast(pid_t, rc),
1881 EAGAIN => return error.SystemResources,1890 EAGAIN => return error.SystemResources,
1882 ENOMEM => return error.SystemResources,1891 ENOMEM => return error.SystemResources,
1883 else => |err| return unexpectedErrno(err),1892 else => |err| return unexpectedErrno(err),
...@@ -1891,6 +1900,7 @@ pub const MMapError = error{...@@ -1891,6 +1900,7 @@ pub const MMapError = error{
1891 SystemFdQuotaExceeded,1900 SystemFdQuotaExceeded,
1892 MemoryMappingNotSupported,1901 MemoryMappingNotSupported,
1893 OutOfMemory,1902 OutOfMemory,
1903 Unexpected,
1894};1904};
18951905
1896/// Map files or devices into memory.1906/// Map files or devices into memory.
...@@ -1992,6 +2002,7 @@ pub fn accessC(path: [*]const u8, mode: u32) AccessError!void {...@@ -1992,6 +2002,7 @@ pub fn accessC(path: [*]const u8, mode: u32) AccessError!void {
1992pub const PipeError = error{2002pub const PipeError = error{
1993 SystemFdQuotaExceeded,2003 SystemFdQuotaExceeded,
1994 ProcessFdQuotaExceeded,2004 ProcessFdQuotaExceeded,
2005 Unexpected,
1995};2006};
19962007
1997/// Creates a unidirectional data channel that can be used for interprocess communication.2008/// Creates a unidirectional data channel that can be used for interprocess communication.
...@@ -2065,18 +2076,6 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {...@@ -2065,18 +2076,6 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
2065 }2076 }
2066}2077}
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
2080pub const SeekError = error{2079pub const SeekError = error{
2081 Unseekable,2080 Unseekable,
2082 Unexpected,2081 Unexpected,
std/os/bits/linux.zig+5-5
...@@ -692,12 +692,12 @@ pub const winsize = extern struct {...@@ -692,12 +692,12 @@ pub const winsize = extern struct {
692 ws_ypixel: u16,692 ws_ypixel: u16,
693};693};
694694
695const NSIG = 65;695pub const NSIG = 65;
696const sigset_t = [128 / @sizeOf(usize)]usize;696pub const sigset_t = [128 / @sizeOf(usize)]usize;
697const all_mask = []u32{ 0xffffffff, 0xffffffff };697pub const all_mask = []u32{ 0xffffffff, 0xffffffff };
698const app_mask = []u32{ 0xfffffffc, 0x7fffffff };698pub const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
699699
700const k_sigaction = extern struct {700pub const k_sigaction = extern struct {
701 handler: extern fn (i32) void,701 handler: extern fn (i32) void,
702 flags: usize,702 flags: usize,
703 restorer: extern fn () void,703 restorer: extern fn () void,
std/os/bits/wasi.zig+2-8
...@@ -13,10 +13,7 @@ pub const ADVICE_WILLNEED: advice_t = 3;...@@ -13,10 +13,7 @@ pub const ADVICE_WILLNEED: advice_t = 3;
13pub const ADVICE_DONTNEED: advice_t = 4;13pub const ADVICE_DONTNEED: advice_t = 4;
14pub const ADVICE_NOREUSE: advice_t = 5;14pub const ADVICE_NOREUSE: advice_t = 5;
1515
16pub const ciovec_t = extern struct {16pub const ciovec_t = iovec_const;
17 buf: [*]const u8,
18 buf_len: usize,
19};
2017
21pub const clockid_t = u32;18pub const clockid_t = u32;
22pub const CLOCK_REALTIME: clockid_t = 0;19pub const CLOCK_REALTIME: clockid_t = 0;
...@@ -186,10 +183,7 @@ pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;...@@ -186,10 +183,7 @@ pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
186183
187pub const inode_t = u64;184pub const inode_t = u64;
188185
189pub const iovec_t = extern struct {186pub const iovec_t = iovec;
190 buf: [*]u8,
191 buf_len: usize,
192};
193187
194pub const linkcount_t = u32;188pub const linkcount_t = u32;
195189
std/os/linux.zig+4-3
...@@ -20,6 +20,7 @@ pub use switch (builtin.arch) {...@@ -20,6 +20,7 @@ pub use switch (builtin.arch) {
20 else => struct {},20 else => struct {},
21};21};
22pub use @import("bits.zig");22pub use @import("bits.zig");
23pub const tls = @import("linux/tls.zig");
2324
24/// Set by startup code, used by `getauxval`.25/// Set by startup code, used by `getauxval`.
25pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;26pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
...@@ -539,15 +540,15 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti...@@ -539,15 +540,15 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
539 return 0;540 return 0;
540}541}
541542
542fn blockAllSignals(set: *sigset_t) void {543pub fn blockAllSignals(set: *sigset_t) void {
543 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);544 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
544}545}
545546
546fn blockAppSignals(set: *sigset_t) void {547pub fn blockAppSignals(set: *sigset_t) void {
547 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);548 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
548}549}
549550
550fn restoreSignals(set: *sigset_t) void {551pub fn restoreSignals(set: *sigset_t) void {
551 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);552 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
552}553}
553554
std/os/linux/vdso.zig+2-3
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const elf = std.elf;2const elf = std.elf;
3const linux = std.os.linux;3const linux = std.os.linux;
4const cstr = std.cstr;
5const mem = std.mem;4const mem = std.mem;
6const maxInt = std.math.maxInt;5const maxInt = std.math.maxInt;
76
...@@ -66,7 +65,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -66,7 +65,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
66 if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;65 if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
67 if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;66 if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
68 if (0 == syms[i].st_shndx) continue;67 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;
70 if (maybe_versym) |versym| {69 if (maybe_versym) |versym| {
71 if (!checkver(maybe_verdef.?, versym[i], vername, strings))70 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
72 continue;71 continue;
...@@ -88,5 +87,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [...@@ -88,5 +87,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
88 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);87 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
89 }88 }
90 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);89 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));
92}91}
std/os/test.zig+7-6
...@@ -3,6 +3,7 @@ const os = std.os;...@@ -3,6 +3,7 @@ const os = std.os;
3const testing = std.testing;3const testing = std.testing;
4const expect = std.testing.expect;4const expect = std.testing.expect;
5const io = std.io;5const io = std.io;
6const fs = std.fs;
6const mem = std.mem;7const mem = std.mem;
7const File = std.fs.File;8const File = std.fs.File;
8const Thread = std.Thread;9const Thread = std.Thread;
...@@ -14,9 +15,9 @@ const AtomicRmwOp = builtin.AtomicRmwOp;...@@ -14,9 +15,9 @@ const AtomicRmwOp = builtin.AtomicRmwOp;
14const AtomicOrder = builtin.AtomicOrder;15const AtomicOrder = builtin.AtomicOrder;
1516
16test "makePath, put some files in it, deleteTree" {17test "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 os.makePath(a, "os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.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" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.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");20 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
20 try os.deleteTree(a, "os_test_tmp");21 try os.deleteTree(a, "os_test_tmp");
21 if (os.Dir.open(a, "os_test_tmp")) |dir| {22 if (os.Dir.open(a, "os_test_tmp")) |dir| {
22 @panic("expected error");23 @panic("expected error");
...@@ -27,14 +28,14 @@ test "makePath, put some files in it, deleteTree" {...@@ -27,14 +28,14 @@ test "makePath, put some files in it, deleteTree" {
2728
28test "access file" {29test "access file" {
29 try os.makePath(a, "os_test_tmp");30 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| {
31 @panic("expected error");32 @panic("expected error");
32 } else |err| {33 } else |err| {
33 expect(err == error.FileNotFound);34 expect(err == error.FileNotFound);
34 }35 }
3536
36 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "file.txt", "");37 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
37 try File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt");38 try File.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt");
38 try os.deleteTree(a, "os_test_tmp");39 try os.deleteTree(a, "os_test_tmp");
39}40}
4041
std/os/windows.zig+38-1
...@@ -4,6 +4,7 @@...@@ -4,6 +4,7 @@
4// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept4// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept
5// slices as well as APIs which accept null-terminated UTF16LE byte buffers.5// slices as well as APIs which accept null-terminated UTF16LE byte buffers.
66
7const builtin = @import("builtin");
7const std = @import("../std.zig");8const std = @import("../std.zig");
8const assert = std.debug.assert;9const assert = std.debug.assert;
9const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
...@@ -1103,6 +1104,42 @@ pub fn VirtualFree(lpAddress: ?LPVOID, dwSize: usize, dwFreeType: DWORD) void {...@@ -1103,6 +1104,42 @@ pub fn VirtualFree(lpAddress: ?LPVOID, dwSize: usize, dwFreeType: DWORD) void {
1103 assert(kernel32.VirtualFree(lpAddress, dwSize, dwFreeType) != 0);1104 assert(kernel32.VirtualFree(lpAddress, dwSize, dwFreeType) != 0);
1104}1105}
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
1106pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {1143pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
1107 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));1144 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
1108}1145}
...@@ -1127,7 +1164,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)...@@ -1127,7 +1164,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
1127 else => {},1164 else => {},
1128 }1165 }
1129 }1166 }
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: {
1131 const prefix = []u16{ '\\', '\\', '?', '\\' };1168 const prefix = []u16{ '\\', '\\', '?', '\\' };
1132 mem.copy(u16, result[0..], prefix);1169 mem.copy(u16, result[0..], prefix);
1133 break :blk prefix.len;1170 break :blk prefix.len;
std/process.zig+41-27
...@@ -1,13 +1,17 @@...@@ -1,13 +1,17 @@
1const builtin = @import("builtin");
1const std = @import("std.zig");2const std = @import("std.zig");
2const os = std.os;3const os = std.os;
3const BufMap = std.BufMap;4const BufMap = std.BufMap;
4const mem = std.mem;5const mem = std.mem;
6const math = std.math;
5const Allocator = mem.Allocator;7const Allocator = mem.Allocator;
6const assert = std.debug.assert;8const assert = std.debug.assert;
7const testing = std.testing;9const testing = std.testing;
810
9pub const abort = os.abort;11pub const abort = os.abort;
10pub const exit = os.exit;12pub const exit = os.exit;
13pub const changeCurDir = os.chdir;
14pub const changeCurDirC = os.chdirC;
1115
12/// Caller must free result when done.16/// Caller must free result when done.
13/// TODO make this go through libc when we have it17/// TODO make this go through libc when we have it
...@@ -15,9 +19,9 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {...@@ -15,9 +19,9 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
15 var result = BufMap.init(allocator);19 var result = BufMap.init(allocator);
16 errdefer result.deinit();20 errdefer result.deinit();
1721
18 if (is_windows) {22 if (os.windows.is_the_target) {
19 const ptr = windows.GetEnvironmentStringsW() orelse return error.OutOfMemory;23 const ptr = try os.windows.GetEnvironmentStringsW();
20 defer assert(windows.FreeEnvironmentStringsW(ptr) != 0);24 defer os.windows.FreeEnvironmentStringsW(ptr);
2125
22 var i: usize = 0;26 var i: usize = 0;
23 while (true) {27 while (true) {
...@@ -105,7 +109,7 @@ pub const GetEnvVarOwnedError = error{...@@ -105,7 +109,7 @@ pub const GetEnvVarOwnedError = error{
105/// Caller must free returned memory.109/// Caller must free returned memory.
106/// TODO make this go through libc when we have it110/// TODO make this go through libc when we have it
107pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 {111pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 {
108 if (is_windows) {112 if (os.windows.is_the_target) {
109 const key_with_null = try std.unicode.utf8ToUtf16LeWithNull(allocator, key);113 const key_with_null = try std.unicode.utf8ToUtf16LeWithNull(allocator, key);
110 defer allocator.free(key_with_null);114 defer allocator.free(key_with_null);
111115
...@@ -113,19 +117,15 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned...@@ -113,19 +117,15 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
113 defer allocator.free(buf);117 defer allocator.free(buf);
114118
115 while (true) {119 while (true) {
116 const windows_buf_len = math.cast(windows.DWORD, buf.len) catch return error.OutOfMemory;120 const windows_buf_len = math.cast(os.windows.DWORD, buf.len) catch return error.OutOfMemory;
117 const result = windows.GetEnvironmentVariableW(key_with_null.ptr, buf.ptr, windows_buf_len);121 const result = os.windows.GetEnvironmentVariableW(
118122 key_with_null.ptr,
119 if (result == 0) {123 buf.ptr,
120 const err = windows.GetLastError();124 windows_buf_len,
121 return switch (err) {125 ) catch |err| switch (err) {
122 windows.ERROR.ENVVAR_NOT_FOUND => error.EnvironmentVariableNotFound,126 error.Unexpected => return error.EnvironmentVariableNotFound,
123 else => {127 else => return err,
124 windows.unexpectedError(err) catch {};128 };
125 return error.EnvironmentVariableNotFound;
126 },
127 };
128 }
129129
130 if (result > buf.len) {130 if (result > buf.len) {
131 buf = try allocator.realloc(buf, result);131 buf = try allocator.realloc(buf, result);
...@@ -136,11 +136,11 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned...@@ -136,11 +136,11 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
136 error.DanglingSurrogateHalf => return error.InvalidUtf8,136 error.DanglingSurrogateHalf => return error.InvalidUtf8,
137 error.ExpectedSecondSurrogateHalf => return error.InvalidUtf8,137 error.ExpectedSecondSurrogateHalf => return error.InvalidUtf8,
138 error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8,138 error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8,
139 error.OutOfMemory => return error.OutOfMemory,139 else => return err,
140 };140 };
141 }141 }
142 } else {142 } else {
143 const result = getEnvPosix(key) orelse return error.EnvironmentVariableNotFound;143 const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound;
144 return mem.dupe(allocator, u8, result);144 return mem.dupe(allocator, u8, result);
145 }145 }
146}146}
...@@ -157,16 +157,16 @@ pub const ArgIteratorPosix = struct {...@@ -157,16 +157,16 @@ pub const ArgIteratorPosix = struct {
157 pub fn init() ArgIteratorPosix {157 pub fn init() ArgIteratorPosix {
158 return ArgIteratorPosix{158 return ArgIteratorPosix{
159 .index = 0,159 .index = 0,
160 .count = raw.len,160 .count = os.argv.len,
161 };161 };
162 }162 }
163163
164 pub fn next(self: *ArgIteratorPosix) ?[]const u8 {164 pub fn next(self: *ArgIteratorPosix) ?[]const u8 {
165 if (self.index == self.count) return null;165 if (self.index == self.count) return null;
166166
167 const s = raw[self.index];167 const s = os.argv[self.index];
168 self.index += 1;168 self.index += 1;
169 return cstr.toSlice(s);169 return mem.toSlice(u8, s);
170 }170 }
171171
172 pub fn skip(self: *ArgIteratorPosix) bool {172 pub fn skip(self: *ArgIteratorPosix) bool {
...@@ -175,10 +175,6 @@ pub const ArgIteratorPosix = struct {...@@ -175,10 +175,6 @@ pub const ArgIteratorPosix = struct {
175 self.index += 1;175 self.index += 1;
176 return true;176 return true;
177 }177 }
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;
182};178};
183179
184pub const ArgIteratorWindows = struct {180pub const ArgIteratorWindows = struct {
...@@ -191,7 +187,7 @@ pub const ArgIteratorWindows = struct {...@@ -191,7 +187,7 @@ pub const ArgIteratorWindows = struct {
191 pub const NextError = error{OutOfMemory};187 pub const NextError = error{OutOfMemory};
192188
193 pub fn init() ArgIteratorWindows {189 pub fn init() ArgIteratorWindows {
194 return initWithCmdLine(windows.GetCommandLineA());190 return initWithCmdLine(os.windows.kernel32.GetCommandLineA());
195 }191 }
196192
197 pub fn initWithCmdLine(cmd_line: [*]const u8) ArgIteratorWindows {193 pub fn initWithCmdLine(cmd_line: [*]const u8) ArgIteratorWindows {
...@@ -581,3 +577,21 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {...@@ -581,3 +577,21 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
581 if (amt_read < buf.len) return error.UserNotFound;577 if (amt_read < buf.len) return error.UserNotFound;
582 }578 }
583}579}
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 {...@@ -78,7 +78,7 @@ fn posixCallMainAndExit() noreturn {
78 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}78 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
79 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];79 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
8080
81 if (builtin.os == builtin.Os.linux) {81 if (builtin.os == .linux) {
82 // Find the beginning of the auxiliary vector82 // Find the beginning of the auxiliary vector
83 const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);83 const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
84 std.os.linux.elf_aux_maybe = auxv;84 std.os.linux.elf_aux_maybe = auxv;
...@@ -98,7 +98,7 @@ fn posixCallMainAndExit() noreturn {...@@ -98,7 +98,7 @@ fn posixCallMainAndExit() noreturn {
98// This is marked inline because for some reason LLVM in release mode fails to inline it,98// This is marked inline because for some reason LLVM in release mode fails to inline it,
99// and we want fewer call frames in stack traces.99// and we want fewer call frames in stack traces.
100inline fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {100inline fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
101 std.os.ArgIteratorPosix.raw = argv[0..argc];101 std.os.argv = argv[0..argc];
102 std.os.environ = envp;102 std.os.environ = envp;
103 return callMain();103 return callMain();
104}104}
std/special/build_runner.zig+4-4
...@@ -3,15 +3,15 @@ const std = @import("std");...@@ -3,15 +3,15 @@ const std = @import("std");
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const io = std.io;4const io = std.io;
5const fmt = std.fmt;5const fmt = std.fmt;
6const os = std.os;
7const Builder = std.build.Builder;6const Builder = std.build.Builder;
8const mem = std.mem;7const mem = std.mem;
8const process = std.process;
9const ArrayList = std.ArrayList;9const ArrayList = std.ArrayList;
10const warn = std.debug.warn;10const warn = std.debug.warn;
11const File = std.fs.File;11const File = std.fs.File;
1212
13pub fn main() !void {13pub fn main() !void {
14 var arg_it = os.args();14 var arg_it = process.args();
1515
16 // Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,16 // Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,
17 // one shot program. We don't need to waste time freeing memory and finding places to squish17 // 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 {...@@ -139,7 +139,7 @@ pub fn main() !void {
139 error.InvalidStepName => {139 error.InvalidStepName => {
140 return usageAndErr(&builder, true, try stderr_stream);140 return usageAndErr(&builder, true, try stderr_stream);
141 },141 },
142 error.UncleanExit => os.exit(1),142 error.UncleanExit => process.exit(1),
143 else => return err,143 else => return err,
144 }144 }
145 };145 };
...@@ -215,7 +215,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {...@@ -215,7 +215,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
215215
216fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) void {216fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) void {
217 usage(builder, already_ran_build, out_stream) catch {};217 usage(builder, already_ran_build, out_stream) catch {};
218 os.exit(1);218 process.exit(1);
219}219}
220220
221const UnwrapArgError = error{OutOfMemory};221const UnwrapArgError = error{OutOfMemory};
std/thread.zig+1-1
...@@ -227,7 +227,7 @@ pub const Thread = struct {...@@ -227,7 +227,7 @@ pub const Thread = struct {
227 var tls_start_offset: usize = undefined;227 var tls_start_offset: usize = undefined;
228 const mmap_len = blk: {228 const mmap_len = blk: {
229 // First in memory will be the stack, which grows downwards.229 // 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);
231 stack_end_offset = l;231 stack_end_offset = l;
232 // Above the stack, so that it can be in the same mmap call, put the Thread object.232 // Above the stack, so that it can be in the same mmap call, put the Thread object.
233 l = mem.alignForward(l, @alignOf(Thread));233 l = mem.alignForward(l, @alignOf(Thread));
test/cli.zig+21-19
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const os = std.os;
4const testing = std.testing;3const testing = std.testing;
4const process = std.process;
5const fs = std.fs;
6const ChildProcess = std.ChildProcess;
57
6var a: *std.mem.Allocator = undefined;8var a: *std.mem.Allocator = undefined;
79
...@@ -12,7 +14,7 @@ pub fn main() !void {...@@ -12,7 +14,7 @@ pub fn main() !void {
12 var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator);14 var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator);
13 defer arena.deinit();15 defer arena.deinit();
1416
15 var arg_it = os.args();17 var arg_it = process.args();
1618
17 // skip my own exe name19 // skip my own exe name
18 _ = arg_it.skip();20 _ = arg_it.skip();
...@@ -27,9 +29,9 @@ pub fn main() !void {...@@ -27,9 +29,9 @@ pub fn main() !void {
27 std.debug.warn("Expected second argument to be cache root directory path\n");29 std.debug.warn("Expected second argument to be cache root directory path\n");
28 return error.InvalidArgs;30 return error.InvalidArgs;
29 });31 });
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" });
33 const TestFn = fn ([]const u8, []const u8) anyerror!void;35 const TestFn = fn ([]const u8, []const u8) anyerror!void;
34 const test_fns = []TestFn{36 const test_fns = []TestFn{
35 testZigInitLib,37 testZigInitLib,
...@@ -37,8 +39,8 @@ pub fn main() !void {...@@ -37,8 +39,8 @@ pub fn main() !void {
37 testGodboltApi,39 testGodboltApi,
38 };40 };
39 for (test_fns) |testFn| {41 for (test_fns) |testFn| {
40 try os.deleteTree(a, dir_path);42 try fs.deleteTree(a, dir_path);
41 try os.makeDir(dir_path);43 try fs.makeDir(dir_path);
42 try testFn(zig_exe, dir_path);44 try testFn(zig_exe, dir_path);
43 }45 }
44}46}
...@@ -58,15 +60,15 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void {...@@ -58,15 +60,15 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void {
58 std.debug.warn("\n");60 std.debug.warn("\n");
59}61}
6062
61fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult {63fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
62 const max_output_size = 100 * 1024;64 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| {
64 std.debug.warn("The following command failed:\n");66 std.debug.warn("The following command failed:\n");
65 printCmd(cwd, argv);67 printCmd(cwd, argv);
66 return err;68 return err;
67 };69 };
68 switch (result.term) {70 switch (result.term) {
69 os.ChildProcess.Term.Exited => |code| {71 .Exited => |code| {
70 if (code != 0) {72 if (code != 0) {
71 std.debug.warn("The following command exited with error code {}:\n", code);73 std.debug.warn("The following command exited with error code {}:\n", code);
72 printCmd(cwd, argv);74 printCmd(cwd, argv);
...@@ -97,10 +99,10 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {...@@ -97,10 +99,10 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
97}99}
98100
99fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {101fn 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" });104 const example_zig_path = try fs.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" });105 const example_s_path = try fs.path.join(a, [][]const u8{ dir_path, "example.s" });
104106
105 try std.io.writeFile(example_zig_path,107 try std.io.writeFile(example_zig_path,
106 \\// Type your code here, or load an example.108 \\// Type your code here, or load an example.
...@@ -114,13 +116,13 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {...@@ -114,13 +116,13 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
114 );116 );
115117
116 const args = [][]const u8{118 const args = [][]const u8{
117 zig_exe, "build-obj",119 zig_exe, "build-obj",
118 "--cache-dir", dir_path,120 "--cache-dir", dir_path,
119 "--name", "example",121 "--name", "example",
120 "--output-dir", dir_path,122 "--output-dir", dir_path,
121 "--emit", "asm",123 "--emit", "asm",
122 "-mllvm", "--x86-asm-syntax=intel",124 "-mllvm", "--x86-asm-syntax=intel",
123 "--strip", "--release-fast",125 "--strip", "--release-fast",
124 example_zig_path, "--disable-gen-h",126 example_zig_path, "--disable-gen-h",
125 };127 };
126 _ = try exec(dir_path, args);128 _ = try exec(dir_path, args);
test/tests.zig+44-46
...@@ -2,11 +2,9 @@ const std = @import("std");...@@ -2,11 +2,9 @@ const std = @import("std");
2const debug = std.debug;2const debug = std.debug;
3const warn = debug.warn;3const warn = debug.warn;
4const build = std.build;4const build = std.build;
5const os = std.os;
6const StdIo = os.ChildProcess.StdIo;
7const Term = os.ChildProcess.Term;
8const Buffer = std.Buffer;5const Buffer = std.Buffer;
9const io = std.io;6const io = std.io;
7const fs = std.fs;
10const mem = std.mem;8const mem = std.mem;
11const fmt = std.fmt;9const fmt = std.fmt;
12const ArrayList = std.ArrayList;10const ArrayList = std.ArrayList;
...@@ -30,19 +28,19 @@ const TestTarget = struct {...@@ -30,19 +28,19 @@ const TestTarget = struct {
3028
31const test_targets = []TestTarget{29const test_targets = []TestTarget{
32 TestTarget{30 TestTarget{
33 .os = builtin.Os.linux,31 .os = .linux,
34 .arch = builtin.Arch.x86_64,32 .arch = .x86_64,
35 .abi = builtin.Abi.gnu,33 .abi = .gnu,
36 },34 },
37 TestTarget{35 TestTarget{
38 .os = builtin.Os.macosx,36 .os = .macosx,
39 .arch = builtin.Arch.x86_64,37 .arch = .x86_64,
40 .abi = builtin.Abi.gnu,38 .abi = .gnu,
41 },39 },
42 TestTarget{40 TestTarget{
43 .os = builtin.Os.windows,41 .os = .windows,
44 .arch = builtin.Arch.x86_64,42 .arch = .x86_64,
45 .abi = builtin.Abi.msvc,43 .abi = .msvc,
46 },44 },
47};45};
4846
...@@ -114,7 +112,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M...@@ -114,7 +112,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
114 const exe = b.addExecutable("test-cli", "test/cli.zig");112 const exe = b.addExecutable("test-cli", "test/cli.zig");
115 const run_cmd = exe.run();113 const run_cmd = exe.run();
116 run_cmd.addArgs([][]const u8{114 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,
118 b.pathFromRoot(b.cache_root),116 b.pathFromRoot(b.cache_root),
119 });117 });
120118
...@@ -301,12 +299,12 @@ pub const CompareOutputContext = struct {...@@ -301,12 +299,12 @@ pub const CompareOutputContext = struct {
301299
302 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);300 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;
305 defer child.deinit();303 defer child.deinit();
306304
307 child.stdin_behavior = StdIo.Ignore;305 child.stdin_behavior = .Ignore;
308 child.stdout_behavior = StdIo.Pipe;306 child.stdout_behavior = .Pipe;
309 child.stderr_behavior = StdIo.Pipe;307 child.stderr_behavior = .Pipe;
310 child.env_map = b.env_map;308 child.env_map = b.env_map;
311309
312 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));310 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
...@@ -324,7 +322,7 @@ pub const CompareOutputContext = struct {...@@ -324,7 +322,7 @@ pub const CompareOutputContext = struct {
324 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));322 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
325 };323 };
326 switch (term) {324 switch (term) {
327 Term.Exited => |code| {325 .Exited => |code| {
328 if (code != 0) {326 if (code != 0) {
329 warn("Process {} exited with error code {}\n", full_exe_path, code);327 warn("Process {} exited with error code {}\n", full_exe_path, code);
330 printInvocation(args.toSliceConst());328 printInvocation(args.toSliceConst());
...@@ -383,13 +381,13 @@ pub const CompareOutputContext = struct {...@@ -383,13 +381,13 @@ pub const CompareOutputContext = struct {
383381
384 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);382 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;
387 defer child.deinit();385 defer child.deinit();
388386
389 child.env_map = b.env_map;387 child.env_map = b.env_map;
390 child.stdin_behavior = StdIo.Ignore;388 child.stdin_behavior = .Ignore;
391 child.stdout_behavior = StdIo.Ignore;389 child.stdout_behavior = .Ignore;
392 child.stderr_behavior = StdIo.Ignore;390 child.stderr_behavior = .Ignore;
393391
394 const term = child.spawnAndWait() catch |err| {392 const term = child.spawnAndWait() catch |err| {
395 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));393 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
...@@ -397,13 +395,13 @@ pub const CompareOutputContext = struct {...@@ -397,13 +395,13 @@ pub const CompareOutputContext = struct {
397395
398 const expected_exit_code: i32 = 126;396 const expected_exit_code: i32 = 126;
399 switch (term) {397 switch (term) {
400 Term.Exited => |code| {398 .Exited => |code| {
401 if (code != expected_exit_code) {399 if (code != expected_exit_code) {
402 warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code);400 warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code);
403 return error.TestFailed;401 return error.TestFailed;
404 }402 }
405 },403 },
406 Term.Signal => |sig| {404 .Signal => |sig| {
407 warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig);405 warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig);
408 return error.TestFailed;406 return error.TestFailed;
409 },407 },
...@@ -459,7 +457,7 @@ pub const CompareOutputContext = struct {...@@ -459,7 +457,7 @@ pub const CompareOutputContext = struct {
459 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {457 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
460 const b = self.b;458 const b = self.b;
461459
462 const root_src = os.path.join(460 const root_src = fs.path.join(
463 b.allocator,461 b.allocator,
464 [][]const u8{ b.cache_root, case.sources.items[0].filename },462 [][]const u8{ b.cache_root, case.sources.items[0].filename },
465 ) catch unreachable;463 ) catch unreachable;
...@@ -475,7 +473,7 @@ pub const CompareOutputContext = struct {...@@ -475,7 +473,7 @@ pub const CompareOutputContext = struct {
475 exe.addAssemblyFile(root_src);473 exe.addAssemblyFile(root_src);
476474
477 for (case.sources.toSliceConst()) |src_file| {475 for (case.sources.toSliceConst()) |src_file| {
478 const expanded_src_path = os.path.join(476 const expanded_src_path = fs.path.join(
479 b.allocator,477 b.allocator,
480 [][]const u8{ b.cache_root, src_file.filename },478 [][]const u8{ b.cache_root, src_file.filename },
481 ) catch unreachable;479 ) catch unreachable;
...@@ -507,7 +505,7 @@ pub const CompareOutputContext = struct {...@@ -507,7 +505,7 @@ pub const CompareOutputContext = struct {
507 }505 }
508506
509 for (case.sources.toSliceConst()) |src_file| {507 for (case.sources.toSliceConst()) |src_file| {
510 const expanded_src_path = os.path.join(508 const expanded_src_path = fs.path.join(
511 b.allocator,509 b.allocator,
512 [][]const u8{ b.cache_root, src_file.filename },510 [][]const u8{ b.cache_root, src_file.filename },
513 ) catch unreachable;511 ) catch unreachable;
...@@ -538,7 +536,7 @@ pub const CompareOutputContext = struct {...@@ -538,7 +536,7 @@ pub const CompareOutputContext = struct {
538 }536 }
539537
540 for (case.sources.toSliceConst()) |src_file| {538 for (case.sources.toSliceConst()) |src_file| {
541 const expanded_src_path = os.path.join(539 const expanded_src_path = fs.path.join(
542 b.allocator,540 b.allocator,
543 [][]const u8{ b.cache_root, src_file.filename },541 [][]const u8{ b.cache_root, src_file.filename },
544 ) catch unreachable;542 ) catch unreachable;
...@@ -633,7 +631,7 @@ pub const CompileErrorContext = struct {...@@ -633,7 +631,7 @@ pub const CompileErrorContext = struct {
633 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);631 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
634 const b = self.context.b;632 const b = self.context.b;
635633
636 const root_src = os.path.join(634 const root_src = fs.path.join(
637 b.allocator,635 b.allocator,
638 [][]const u8{ b.cache_root, self.case.sources.items[0].filename },636 [][]const u8{ b.cache_root, self.case.sources.items[0].filename },
639 ) catch unreachable;637 ) catch unreachable;
...@@ -669,13 +667,13 @@ pub const CompileErrorContext = struct {...@@ -669,13 +667,13 @@ pub const CompileErrorContext = struct {
669 printInvocation(zig_args.toSliceConst());667 printInvocation(zig_args.toSliceConst());
670 }668 }
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;
673 defer child.deinit();671 defer child.deinit();
674672
675 child.env_map = b.env_map;673 child.env_map = b.env_map;
676 child.stdin_behavior = StdIo.Ignore;674 child.stdin_behavior = .Ignore;
677 child.stdout_behavior = StdIo.Pipe;675 child.stdout_behavior = .Pipe;
678 child.stderr_behavior = StdIo.Pipe;676 child.stderr_behavior = .Pipe;
679677
680 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));678 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 {...@@ -692,7 +690,7 @@ pub const CompileErrorContext = struct {
692 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));690 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
693 };691 };
694 switch (term) {692 switch (term) {
695 Term.Exited => |code| {693 .Exited => |code| {
696 if (code == 0) {694 if (code == 0) {
697 printInvocation(zig_args.toSliceConst());695 printInvocation(zig_args.toSliceConst());
698 return error.CompilationIncorrectlySucceeded;696 return error.CompilationIncorrectlySucceeded;
...@@ -823,7 +821,7 @@ pub const CompileErrorContext = struct {...@@ -823,7 +821,7 @@ pub const CompileErrorContext = struct {
823 self.step.dependOn(&compile_and_cmp_errors.step);821 self.step.dependOn(&compile_and_cmp_errors.step);
824822
825 for (case.sources.toSliceConst()) |src_file| {823 for (case.sources.toSliceConst()) |src_file| {
826 const expanded_src_path = os.path.join(824 const expanded_src_path = fs.path.join(
827 b.allocator,825 b.allocator,
828 [][]const u8{ b.cache_root, src_file.filename },826 [][]const u8{ b.cache_root, src_file.filename },
829 ) catch unreachable;827 ) catch unreachable;
...@@ -858,7 +856,7 @@ pub const BuildExamplesContext = struct {...@@ -858,7 +856,7 @@ pub const BuildExamplesContext = struct {
858 }856 }
859857
860 var zig_args = ArrayList([]const u8).init(b.allocator);858 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;
862 zig_args.append(rel_zig_exe) catch unreachable;860 zig_args.append(rel_zig_exe) catch unreachable;
863 zig_args.append("build") catch unreachable;861 zig_args.append("build") catch unreachable;
864862
...@@ -958,7 +956,7 @@ pub const TranslateCContext = struct {...@@ -958,7 +956,7 @@ pub const TranslateCContext = struct {
958 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);956 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
959 const b = self.context.b;957 const b = self.context.b;
960958
961 const root_src = os.path.join(959 const root_src = fs.path.join(
962 b.allocator,960 b.allocator,
963 [][]const u8{ b.cache_root, self.case.sources.items[0].filename },961 [][]const u8{ b.cache_root, self.case.sources.items[0].filename },
964 ) catch unreachable;962 ) catch unreachable;
...@@ -976,13 +974,13 @@ pub const TranslateCContext = struct {...@@ -976,13 +974,13 @@ pub const TranslateCContext = struct {
976 printInvocation(zig_args.toSliceConst());974 printInvocation(zig_args.toSliceConst());
977 }975 }
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;
980 defer child.deinit();978 defer child.deinit();
981979
982 child.env_map = b.env_map;980 child.env_map = b.env_map;
983 child.stdin_behavior = StdIo.Ignore;981 child.stdin_behavior = .Ignore;
984 child.stdout_behavior = StdIo.Pipe;982 child.stdout_behavior = .Pipe;
985 child.stderr_behavior = StdIo.Pipe;983 child.stderr_behavior = .Pipe;
986984
987 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));985 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 {...@@ -999,14 +997,14 @@ pub const TranslateCContext = struct {
999 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));997 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
1000 };998 };
1001 switch (term) {999 switch (term) {
1002 Term.Exited => |code| {1000 .Exited => |code| {
1003 if (code != 0) {1001 if (code != 0) {
1004 warn("Compilation failed with exit code {}\n", code);1002 warn("Compilation failed with exit code {}\n", code);
1005 printInvocation(zig_args.toSliceConst());1003 printInvocation(zig_args.toSliceConst());
1006 return error.TestFailed;1004 return error.TestFailed;
1007 }1005 }
1008 },1006 },
1009 Term.Signal => |code| {1007 .Signal => |code| {
1010 warn("Compilation failed with signal {}\n", code);1008 warn("Compilation failed with signal {}\n", code);
1011 printInvocation(zig_args.toSliceConst());1009 printInvocation(zig_args.toSliceConst());
1012 return error.TestFailed;1010 return error.TestFailed;
...@@ -1131,7 +1129,7 @@ pub const TranslateCContext = struct {...@@ -1131,7 +1129,7 @@ pub const TranslateCContext = struct {
1131 self.step.dependOn(&translate_c_and_cmp.step);1129 self.step.dependOn(&translate_c_and_cmp.step);
11321130
1133 for (case.sources.toSliceConst()) |src_file| {1131 for (case.sources.toSliceConst()) |src_file| {
1134 const expanded_src_path = os.path.join(1132 const expanded_src_path = fs.path.join(
1135 b.allocator,1133 b.allocator,
1136 [][]const u8{ b.cache_root, src_file.filename },1134 [][]const u8{ b.cache_root, src_file.filename },
1137 ) catch unreachable;1135 ) catch unreachable;
...@@ -1254,7 +1252,7 @@ pub const GenHContext = struct {...@@ -1254,7 +1252,7 @@ pub const GenHContext = struct {
12541252
1255 pub fn addCase(self: *GenHContext, case: *const TestCase) void {1253 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
1256 const b = self.b;1254 const b = self.b;
1257 const root_src = os.path.join(1255 const root_src = fs.path.join(
1258 b.allocator,1256 b.allocator,
1259 [][]const u8{ b.cache_root, case.sources.items[0].filename },1257 [][]const u8{ b.cache_root, case.sources.items[0].filename },
1260 ) catch unreachable;1258 ) catch unreachable;
...@@ -1269,7 +1267,7 @@ pub const GenHContext = struct {...@@ -1269,7 +1267,7 @@ pub const GenHContext = struct {
1269 obj.setBuildMode(mode);1267 obj.setBuildMode(mode);
12701268
1271 for (case.sources.toSliceConst()) |src_file| {1269 for (case.sources.toSliceConst()) |src_file| {
1272 const expanded_src_path = os.path.join(1270 const expanded_src_path = fs.path.join(
1273 b.allocator,1271 b.allocator,
1274 [][]const u8{ b.cache_root, src_file.filename },1272 [][]const u8{ b.cache_root, src_file.filename },
1275 ) catch unreachable;1273 ) catch unreachable;