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