authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-19 19:42:52-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:11-08:00
log50c585227ed2a57a4c1cf3f3b44914881999559d
tree1abd9e3bda5967c994e69397582cce0dd1b2d5cc
parent7d955274bb40bc937275b3d59c6304dd44c85d40

fix compilation of incr-check


15 files changed, 262 insertions(+), 213 deletions(-)

tools/docgen.zig+3-3
......@@ -73,15 +73,15 @@ pub fn main() !void {
7373 const code_dir_path = opt_code_dir orelse fatal("missing --code-dir argument", .{});
7474
7575 var in_file = try fs.cwd().openFile(input_path, .{});
76 defer in_file.close();
76 defer in_file.close(io);
7777
7878 var out_file = try fs.cwd().createFile(output_path, .{});
79 defer out_file.close();
79 defer out_file.close(io);
8080 var out_file_buffer: [4096]u8 = undefined;
8181 var out_file_writer = out_file.writer(&out_file_buffer);
8282
8383 var code_dir = try fs.cwd().openDir(code_dir_path, .{});
84 defer code_dir.close();
84 defer code_dir.close(io);
8585
8686 var in_file_reader = in_file.reader(io, &.{});
8787 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size));
tools/doctest.zig+7-7
......@@ -85,16 +85,16 @@ pub fn main() !void {
8585 const tmp_dir_path = try std.fmt.allocPrint(arena, "{s}/tmp/{x}", .{
8686 cache_root, std.crypto.random.int(u64),
8787 });
88 fs.cwd().makePath(tmp_dir_path) catch |err|
89 fatal("unable to create tmp dir '{s}': {s}", .{ tmp_dir_path, @errorName(err) });
90 defer fs.cwd().deleteTree(tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {s}", .{
91 tmp_dir_path, @errorName(err),
88 fs.cwd().createDirPath(io, tmp_dir_path) catch |err|
89 fatal("unable to create tmp dir '{s}': {t}", .{ tmp_dir_path, err });
90 defer fs.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{
91 tmp_dir_path, err,
9292 });
9393
94 var out_file = try fs.cwd().createFile(output_path, .{});
95 defer out_file.close();
94 var out_file = try fs.cwd().createFile(io, output_path, .{});
95 defer out_file.close(io);
9696 var out_file_buffer: [4096]u8 = undefined;
97 var out_file_writer = out_file.writer(&out_file_buffer);
97 var out_file_writer = out_file.writer(io, &out_file_buffer);
9898
9999 const out = &out_file_writer.interface;
100100
tools/fetch_them_macos_headers.zig+21-21
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const Io = std.Io;
3const fs = std.fs;
3const Dir = std.Io.Dir;
44const mem = std.mem;
55const process = std.process;
66const assert = std.debug.assert;
......@@ -96,9 +96,9 @@ pub fn main() anyerror!void {
9696 fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{});
9797 };
9898
99 var sdk_dir = try std.fs.cwd().openDir(sysroot_path, .{});
100 defer sdk_dir.close();
101 const sdk_info = try sdk_dir.readFileAlloc("SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));
99 var sdk_dir = try Dir.cwd().openDir(io, sysroot_path, .{});
100 defer sdk_dir.close(io);
101 const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));
102102
103103 const parsed_json = try std.json.parseFromSlice(struct {
104104 DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 },
......@@ -135,8 +135,8 @@ fn fetchTarget(
135135 const tmp_filename = "macos-headers";
136136 const headers_list_filename = "macos-headers.o.d";
137137 const tmp_path = try tmp.dir.realpathAlloc(arena, ".");
138 const tmp_file_path = try fs.path.join(arena, &[_][]const u8{ tmp_path, tmp_filename });
139 const headers_list_path = try fs.path.join(arena, &[_][]const u8{ tmp_path, headers_list_filename });
138 const tmp_file_path = try Dir.path.join(arena, &[_][]const u8{ tmp_path, tmp_filename });
139 const headers_list_path = try Dir.path.join(arena, &[_][]const u8{ tmp_path, headers_list_filename });
140140
141141 const macos_version = try std.fmt.allocPrint(arena, "-mmacosx-version-min={d}.{d}", .{
142142 ver.major,
......@@ -176,10 +176,10 @@ fn fetchTarget(
176176 }
177177
178178 // Read in the contents of `macos-headers.o.d`
179 const headers_list_file = try tmp.dir.openFile(headers_list_filename, .{});
180 defer headers_list_file.close();
179 const headers_list_file = try tmp.dir.openFile(io, headers_list_filename, .{});
180 defer headers_list_file.close(io);
181181
182 var headers_dir = fs.cwd().openDir(headers_source_prefix, .{}) catch |err| switch (err) {
182 var headers_dir = Dir.cwd().openDir(headers_source_prefix, .{}) catch |err| switch (err) {
183183 error.FileNotFound,
184184 error.NotDir,
185185 => fatal("path '{s}' not found or not a directory. Did you accidentally delete it?", .{
......@@ -187,13 +187,13 @@ fn fetchTarget(
187187 }),
188188 else => return err,
189189 };
190 defer headers_dir.close();
190 defer headers_dir.close(io);
191191
192192 const dest_path = try target.fullName(arena);
193 try headers_dir.deleteTree(dest_path);
193 try headers_dir.deleteTree(io, dest_path);
194194
195 var dest_dir = try headers_dir.makeOpenPath(dest_path, .{});
196 var dirs = std.StringHashMap(fs.Dir).init(arena);
195 var dest_dir = try headers_dir.createDirPathOpen(io, dest_path, .{});
196 var dirs = std.StringHashMap(Dir).init(arena);
197197 try dirs.putNoClobber(".", dest_dir);
198198
199199 var headers_list_file_reader = headers_list_file.reader(io, &.{});
......@@ -206,25 +206,25 @@ fn fetchTarget(
206206 if (mem.lastIndexOf(u8, line, prefix[0..])) |idx| {
207207 const out_rel_path = line[idx + prefix.len + 1 ..];
208208 const out_rel_path_stripped = mem.trim(u8, out_rel_path, " \\");
209 const dirname = fs.path.dirname(out_rel_path_stripped) orelse ".";
209 const dirname = Dir.path.dirname(out_rel_path_stripped) orelse ".";
210210 const maybe_dir = try dirs.getOrPut(dirname);
211211 if (!maybe_dir.found_existing) {
212 maybe_dir.value_ptr.* = try dest_dir.makeOpenPath(dirname, .{});
212 maybe_dir.value_ptr.* = try dest_dir.createDirPathOpen(io, dirname, .{});
213213 }
214 const basename = fs.path.basename(out_rel_path_stripped);
214 const basename = Dir.path.basename(out_rel_path_stripped);
215215
216216 const line_stripped = mem.trim(u8, line, " \\");
217 const abs_dirname = fs.path.dirname(line_stripped).?;
218 var orig_subdir = try fs.cwd().openDir(abs_dirname, .{});
219 defer orig_subdir.close();
217 const abs_dirname = Dir.path.dirname(line_stripped).?;
218 var orig_subdir = try Dir.cwd().openDir(abs_dirname, .{});
219 defer orig_subdir.close(io);
220220
221221 try orig_subdir.copyFile(basename, maybe_dir.value_ptr.*, basename, .{});
222222 }
223223 }
224224
225225 var dir_it = dirs.iterator();
226 while (dir_it.next()) |entry| {
227 entry.value_ptr.close();
226 while (dir_it.next(io)) |entry| {
227 entry.value_ptr.close(io);
228228 }
229229}
230230
tools/gen_macos_headers_c.zig+14-8
......@@ -1,8 +1,9 @@
11const std = @import("std");
2const Io = std.Io;
3const Dir = std.Io.Dir;
24const assert = std.debug.assert;
35const info = std.log.info;
46const fatal = std.process.fatal;
5
67const Allocator = std.mem.Allocator;
78
89var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
......@@ -20,6 +21,10 @@ pub fn main() anyerror!void {
2021 defer arena_allocator.deinit();
2122 const arena = arena_allocator.allocator();
2223
24 var threaded: Io.Threaded = .init(gpa);
25 defer threaded.deinit();
26 const io = threaded.io();
27
2328 const args = try std.process.argsAlloc(arena);
2429 if (args.len == 1) fatal("no command or option specified", .{});
2530
......@@ -33,10 +38,10 @@ pub fn main() anyerror!void {
3338
3439 if (positionals.items.len != 1) fatal("expected one positional argument: [dir]", .{});
3540
36 var dir = try std.fs.cwd().openDir(positionals.items[0], .{ .follow_symlinks = false });
37 defer dir.close();
41 var dir = try std.fs.cwd().openDir(io, positionals.items[0], .{ .follow_symlinks = false });
42 defer dir.close(io);
3843 var paths = std.array_list.Managed([]const u8).init(arena);
39 try findHeaders(arena, dir, "", &paths);
44 try findHeaders(arena, io, dir, "", &paths);
4045
4146 const SortFn = struct {
4247 pub fn lessThan(ctx: void, lhs: []const u8, rhs: []const u8) bool {
......@@ -64,7 +69,8 @@ pub fn main() anyerror!void {
6469
6570fn findHeaders(
6671 arena: Allocator,
67 dir: std.fs.Dir,
72 io: Io,
73 dir: Dir,
6874 prefix: []const u8,
6975 paths: *std.array_list.Managed([]const u8),
7076) anyerror!void {
......@@ -73,9 +79,9 @@ fn findHeaders(
7379 switch (entry.kind) {
7480 .directory => {
7581 const path = try std.fs.path.join(arena, &.{ prefix, entry.name });
76 var subdir = try dir.openDir(entry.name, .{ .follow_symlinks = false });
77 defer subdir.close();
78 try findHeaders(arena, subdir, path, paths);
82 var subdir = try dir.openDir(io, entry.name, .{ .follow_symlinks = false });
83 defer subdir.close(io);
84 try findHeaders(arena, io, subdir, path, paths);
7985 },
8086 .file, .sym_link => {
8187 const ext = std.fs.path.extension(entry.name);
tools/generate_linux_syscalls.zig+7-3
......@@ -175,6 +175,10 @@ pub fn main() !void {
175175 defer arena.deinit();
176176 const gpa = arena.allocator();
177177
178 var threaded: Io.Threaded = .init(gpa);
179 defer threaded.deinit();
180 const io = threaded.io();
181
178182 const args = try std.process.argsAlloc(gpa);
179183 if (args.len < 2 or mem.eql(u8, args[1], "--help")) {
180184 const w, _ = std.debug.lockStderrWriter(&.{});
......@@ -188,8 +192,8 @@ pub fn main() !void {
188192 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
189193 const stdout = &stdout_writer.interface;
190194
191 var linux_dir = try std.fs.cwd().openDir(linux_path, .{});
192 defer linux_dir.close();
195 var linux_dir = try std.fs.cwd().openDir(io, linux_path, .{});
196 defer linux_dir.close(io);
193197
194198 // As of 6.11, the largest table is 24195 bytes.
195199 // 32k should be enough for now.
......@@ -198,7 +202,7 @@ pub fn main() !void {
198202
199203 // Fetch the kernel version from the Makefile variables.
200204 const version = blk: {
201 const head = try linux_dir.readFile("Makefile", buf[0..128]);
205 const head = try linux_dir.readFile(io, "Makefile", buf[0..128]);
202206 var lines = mem.tokenizeScalar(u8, head, '\n');
203207 _ = lines.next(); // Skip SPDX identifier
204208
tools/incr-check.zig+54-44
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const Io = std.Io;
3const Dir = std.Io.Dir;
34const Allocator = std.mem.Allocator;
45const Cache = std.Build.Cache;
56
......@@ -59,7 +60,7 @@ pub fn main() !void {
5960 const zig_exe = opt_zig_exe orelse fatal("missing path to zig\n{s}", .{usage});
6061 const input_file_name = opt_input_file_name orelse fatal("missing input file\n{s}", .{usage});
6162
62 const input_file_bytes = try std.fs.cwd().readFileAlloc(input_file_name, arena, .limited(std.math.maxInt(u32)));
63 const input_file_bytes = try Dir.cwd().readFileAlloc(io, input_file_name, arena, .limited(std.math.maxInt(u32)));
6364 const case = try Case.parse(arena, io, input_file_bytes);
6465
6566 // Check now: if there are any targets using the `cbe` backend, we need the lib dir.
......@@ -71,25 +72,25 @@ pub fn main() !void {
7172 }
7273 }
7374
74 const prog_node = std.Progress.start(.{});
75 const prog_node = std.Progress.start(io, .{});
7576 defer prog_node.end();
7677
7778 const rand_int = std.crypto.random.int(u64);
7879 const tmp_dir_path = "tmp_" ++ std.fmt.hex(rand_int);
79 var tmp_dir = try std.fs.cwd().makeOpenPath(tmp_dir_path, .{});
80 var tmp_dir = try Dir.cwd().createDirPathOpen(io, tmp_dir_path, .{});
8081 defer {
81 tmp_dir.close();
82 tmp_dir.close(io);
8283 if (!preserve_tmp) {
83 std.fs.cwd().deleteTree(tmp_dir_path) catch |err| {
84 std.log.warn("failed to delete tree '{s}': {s}", .{ tmp_dir_path, @errorName(err) });
84 Dir.cwd().deleteTree(io, tmp_dir_path) catch |err| {
85 std.log.warn("failed to delete tree '{s}': {t}", .{ tmp_dir_path, err });
8586 };
8687 }
8788 }
8889
8990 // Convert paths to be relative to the cwd of the subprocess.
90 const resolved_zig_exe = try std.fs.path.relative(arena, tmp_dir_path, zig_exe);
91 const resolved_zig_exe = try Dir.path.relative(arena, tmp_dir_path, zig_exe);
9192 const opt_resolved_lib_dir = if (opt_lib_dir) |lib_dir|
92 try std.fs.path.relative(arena, tmp_dir_path, lib_dir)
93 try Dir.path.relative(arena, tmp_dir_path, lib_dir)
9394 else
9495 null;
9596
......@@ -164,7 +165,7 @@ pub fn main() !void {
164165 var cc_child_args: std.ArrayList([]const u8) = .empty;
165166 if (target.backend == .cbe) {
166167 const resolved_cc_zig_exe = if (opt_cc_zig) |cc_zig_exe|
167 try std.fs.path.relative(arena, tmp_dir_path, cc_zig_exe)
168 try Dir.path.relative(arena, tmp_dir_path, cc_zig_exe)
168169 else
169170 resolved_zig_exe;
170171
......@@ -185,6 +186,7 @@ pub fn main() !void {
185186
186187 var eval: Eval = .{
187188 .arena = arena,
189 .io = io,
188190 .case = case,
189191 .host = host,
190192 .target = target,
......@@ -196,9 +198,9 @@ pub fn main() !void {
196198 .cc_child_args = &cc_child_args,
197199 };
198200
199 try child.spawn();
201 try child.spawn(io);
200202 errdefer {
201 _ = child.kill() catch {};
203 _ = child.kill(io) catch {};
202204 }
203205
204206 var poller = Io.poll(arena, Eval.StreamEnum, .{
......@@ -228,10 +230,11 @@ pub fn main() !void {
228230
229231const Eval = struct {
230232 arena: Allocator,
233 io: Io,
231234 host: std.Target,
232235 case: Case,
233236 target: Case.Target,
234 tmp_dir: std.fs.Dir,
237 tmp_dir: Dir,
235238 tmp_dir_path: []const u8,
236239 child: *std.process.Child,
237240 allow_stderr: bool,
......@@ -245,17 +248,18 @@ const Eval = struct {
245248
246249 /// Currently this function assumes the previous updates have already been written.
247250 fn write(eval: *Eval, update: Case.Update) void {
251 const io = eval.io;
248252 for (update.changes) |full_contents| {
249 eval.tmp_dir.writeFile(.{
253 eval.tmp_dir.writeFile(io, .{
250254 .sub_path = full_contents.name,
251255 .data = full_contents.bytes,
252256 }) catch |err| {
253 eval.fatal("failed to update '{s}': {s}", .{ full_contents.name, @errorName(err) });
257 eval.fatal("failed to update '{s}': {t}", .{ full_contents.name, err });
254258 };
255259 }
256260 for (update.deletes) |doomed_name| {
257 eval.tmp_dir.deleteFile(doomed_name) catch |err| {
258 eval.fatal("failed to delete '{s}': {s}", .{ doomed_name, @errorName(err) });
261 eval.tmp_dir.deleteFile(io, doomed_name) catch |err| {
262 eval.fatal("failed to delete '{s}': {t}", .{ doomed_name, err });
259263 };
260264 }
261265 }
......@@ -307,14 +311,14 @@ const Eval = struct {
307311 }
308312
309313 const digest = r.takeArray(Cache.bin_digest_len) catch unreachable;
310 const result_dir = ".local-cache" ++ std.fs.path.sep_str ++ "o" ++ std.fs.path.sep_str ++ Cache.binToHex(digest.*);
314 const result_dir = ".local-cache" ++ Dir.path.sep_str ++ "o" ++ Dir.path.sep_str ++ Cache.binToHex(digest.*);
311315
312316 const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{
313317 .root_name = "root", // corresponds to the module name "root"
314318 .target = &eval.target.resolved,
315319 .output_mode = .Exe,
316320 });
317 const bin_path = try std.fs.path.join(arena, &.{ result_dir, bin_name });
321 const bin_path = try Dir.path.join(arena, &.{ result_dir, bin_name });
318322
319323 try eval.checkSuccessOutcome(update, bin_path, prog_node);
320324 // This message indicates the end of the update.
......@@ -338,11 +342,12 @@ const Eval = struct {
338342 }
339343
340344 fn checkErrorOutcome(eval: *Eval, update: Case.Update, error_bundle: std.zig.ErrorBundle) !void {
345 const io = eval.io;
341346 const expected = switch (update.outcome) {
342347 .unknown => return,
343348 .compile_errors => |ce| ce,
344349 .stdout, .exit_code => {
345 error_bundle.renderToStdErr(.{}, .auto);
350 try error_bundle.renderToStderr(io, .{}, .auto);
346351 eval.fatal("update '{s}': unexpected compile errors", .{update.name});
347352 },
348353 };
......@@ -351,7 +356,7 @@ const Eval = struct {
351356
352357 for (error_bundle.getMessages()) |err_idx| {
353358 if (expected_idx == expected.errors.len) {
354 error_bundle.renderToStdErr(.{}, .auto);
359 try error_bundle.renderToStderr(io, .{}, .auto);
355360 eval.fatal("update '{s}': more errors than expected", .{update.name});
356361 }
357362 try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], false, err_idx);
......@@ -359,7 +364,7 @@ const Eval = struct {
359364
360365 for (error_bundle.getNotes(err_idx)) |note_idx| {
361366 if (expected_idx == expected.errors.len) {
362 error_bundle.renderToStdErr(.{}, .auto);
367 try error_bundle.renderToStderr(io, .{}, .auto);
363368 eval.fatal("update '{s}': more error notes than expected", .{update.name});
364369 }
365370 try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], true, note_idx);
......@@ -368,7 +373,7 @@ const Eval = struct {
368373 }
369374
370375 if (!std.mem.eql(u8, error_bundle.getCompileLogOutput(), expected.compile_log_output)) {
371 error_bundle.renderToStdErr(.{}, .auto);
376 try error_bundle.renderToStderr(io, .{}, .auto);
372377 eval.fatal("update '{s}': unexpected compile log output", .{update.name});
373378 }
374379 }
......@@ -388,6 +393,8 @@ const Eval = struct {
388393 const src = eb.getSourceLocation(err.src_loc);
389394 const raw_filename = eb.nullTerminatedString(src.src_path);
390395
396 const io = eval.io;
397
391398 // We need to replace backslashes for consistency between platforms.
392399 const filename = name: {
393400 if (std.mem.indexOfScalar(u8, raw_filename, '\\') == null) break :name raw_filename;
......@@ -402,7 +409,7 @@ const Eval = struct {
402409 expected.column != src.column + 1 or
403410 !std.mem.eql(u8, expected.msg, msg))
404411 {
405 eb.renderToStdErr(.{}, .auto);
412 eb.renderToStderr(io, .{}, .auto) catch {};
406413 eval.fatal("update '{s}': compile error did not match expected error", .{update.name});
407414 }
408415 }
......@@ -429,8 +436,11 @@ const Eval = struct {
429436 },
430437 };
431438
439 const io = eval.io;
440
432441 var argv_buf: [2][]const u8 = undefined;
433442 const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor(
443 io,
434444 &eval.host,
435445 &eval.target.resolved,
436446 .{ .link_libc = eval.target.backend == .cbe },
......@@ -459,8 +469,7 @@ const Eval = struct {
459469 const run_prog_node = prog_node.start("run generated executable", 0);
460470 defer run_prog_node.end();
461471
462 const result = std.process.Child.run(.{
463 .allocator = eval.arena,
472 const result = std.process.Child.run(eval.arena, io, .{
464473 .argv = argv,
465474 .cwd_dir = eval.tmp_dir,
466475 .cwd = eval.tmp_dir_path,
......@@ -468,17 +477,17 @@ const Eval = struct {
468477 if (is_foreign) {
469478 // Chances are the foreign executor isn't available. Skip this evaluation.
470479 if (eval.allow_stderr) {
471 std.log.warn("update '{s}': skipping execution of '{s}' via executor for foreign target '{s}': {s}", .{
480 std.log.warn("update '{s}': skipping execution of '{s}' via executor for foreign target '{s}': {t}", .{
472481 update.name,
473482 binary_path,
474483 try eval.target.resolved.zigTriple(eval.arena),
475 @errorName(err),
484 err,
476485 });
477486 }
478487 return;
479488 }
480 eval.fatal("update '{s}': failed to run the generated executable '{s}': {s}", .{
481 update.name, binary_path, @errorName(err),
489 eval.fatal("update '{s}': failed to run the generated executable '{s}': {t}", .{
490 update.name, binary_path, err,
482491 });
483492 };
484493
......@@ -514,11 +523,12 @@ const Eval = struct {
514523 }
515524
516525 fn requestUpdate(eval: *Eval) !void {
526 const io = eval.io;
517527 const header: std.zig.Client.Message.Header = .{
518528 .tag = .update,
519529 .bytes_len = 0,
520530 };
521 var w = eval.child.stdin.?.writer(&.{});
531 var w = eval.child.stdin.?.writer(io, &.{});
522532 w.interface.writeStruct(header, .little) catch |err| switch (err) {
523533 error.WriteFailed => return w.err.?,
524534 };
......@@ -552,16 +562,13 @@ const Eval = struct {
552562 try eval.cc_child_args.appendSlice(eval.arena, &.{ out_path, c_path });
553563 defer eval.cc_child_args.items.len -= 2;
554564
555 const result = std.process.Child.run(.{
556 .allocator = eval.arena,
565 const result = std.process.Child.run(eval.arena, eval.io, .{
557566 .argv = eval.cc_child_args.items,
558567 .cwd_dir = eval.tmp_dir,
559568 .cwd = eval.tmp_dir_path,
560569 .progress_node = child_prog_node,
561570 }) catch |err| {
562 eval.fatal("update '{s}': failed to spawn zig cc for '{s}': {s}", .{
563 update.name, c_path, @errorName(err),
564 });
571 eval.fatal("update '{s}': failed to spawn zig cc for '{s}': {t}", .{ update.name, c_path, err });
565572 };
566573 switch (result.term) {
567574 .Exited => |code| if (code != 0) {
......@@ -588,12 +595,13 @@ const Eval = struct {
588595 }
589596
590597 fn fatal(eval: *Eval, comptime fmt: []const u8, args: anytype) noreturn {
591 eval.tmp_dir.close();
598 const io = eval.io;
599 eval.tmp_dir.close(io);
592600 if (!eval.preserve_tmp_on_fatal) {
593601 // Kill the child since it holds an open handle to its CWD which is the tmp dir path
594 _ = eval.child.kill() catch {};
595 std.fs.cwd().deleteTree(eval.tmp_dir_path) catch |err| {
596 std.log.warn("failed to delete tree '{s}': {s}", .{ eval.tmp_dir_path, @errorName(err) });
602 _ = eval.child.kill(io) catch {};
603 Dir.cwd().deleteTree(io, eval.tmp_dir_path) catch |err| {
604 std.log.warn("failed to delete tree '{s}': {t}", .{ eval.tmp_dir_path, err });
597605 };
598606 }
599607 std.process.fatal(fmt, args);
......@@ -759,7 +767,7 @@ const Case = struct {
759767 if (last_update.outcome != .unknown) fatal("line {d}: conflicting expect directive", .{line_n});
760768 last_update.outcome = .{
761769 .stdout = std.zig.string_literal.parseAlloc(arena, val) catch |err| {
762 fatal("line {d}: bad string literal: {s}", .{ line_n, @errorName(err) });
770 fatal("line {d}: bad string literal: {t}", .{ line_n, err });
763771 },
764772 };
765773 } else if (std.mem.eql(u8, key, "expect_error")) {
......@@ -833,27 +841,29 @@ const Case = struct {
833841
834842fn requestExit(child: *std.process.Child, eval: *Eval) void {
835843 if (child.stdin == null) return;
844 const io = eval.io;
836845
837846 const header: std.zig.Client.Message.Header = .{
838847 .tag = .exit,
839848 .bytes_len = 0,
840849 };
841 var w = eval.child.stdin.?.writer(&.{});
850 var w = eval.child.stdin.?.writer(io, &.{});
842851 w.interface.writeStruct(header, .little) catch |err| switch (err) {
843852 error.WriteFailed => switch (w.err.?) {
844853 error.BrokenPipe => {},
845 else => |e| eval.fatal("failed to send exit: {s}", .{@errorName(e)}),
854 else => |e| eval.fatal("failed to send exit: {t}", .{e}),
846855 },
847856 };
848857
849858 // Send EOF to stdin.
850 child.stdin.?.close();
859 child.stdin.?.close(io);
851860 child.stdin = null;
852861}
853862
854863fn waitChild(child: *std.process.Child, eval: *Eval) void {
864 const io = eval.io;
855865 requestExit(child, eval);
856 const term = child.wait() catch |err| eval.fatal("child process failed: {s}", .{@errorName(err)});
866 const term = child.wait(io) catch |err| eval.fatal("child process failed: {t}", .{err});
857867 switch (term) {
858868 .Exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),
859869 .Signal, .Stopped, .Unknown => eval.fatal("compiler terminated unexpectedly", .{}),
tools/migrate_langref.zig+14-11
......@@ -1,13 +1,16 @@
1const std = @import("std");
21const builtin = @import("builtin");
3const fs = std.fs;
2
3const std = @import("std");
4const Io = std.Io;
5const Dir = std.Io.Dir;
46const print = std.debug.print;
57const mem = std.mem;
68const testing = std.testing;
79const Allocator = std.mem.Allocator;
8const max_doc_file_size = 10 * 1024 * 1024;
910const fatal = std.process.fatal;
1011
12const max_doc_file_size = 10 * 1024 * 1024;
13
1114pub fn main() !void {
1215 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
1316 defer arena_instance.deinit();
......@@ -23,16 +26,16 @@ pub fn main() !void {
2326 defer threaded.deinit();
2427 const io = threaded.io();
2528
26 var in_file = try fs.cwd().openFile(input_file, .{ .mode = .read_only });
27 defer in_file.close();
29 var in_file = try Dir.cwd().openFile(input_file, .{ .mode = .read_only });
30 defer in_file.close(io);
2831
29 var out_file = try fs.cwd().createFile(output_file, .{});
30 defer out_file.close();
32 var out_file = try Dir.cwd().createFile(output_file, .{});
33 defer out_file.close(io);
3134 var out_file_buffer: [4096]u8 = undefined;
3235 var out_file_writer = out_file.writer(&out_file_buffer);
3336
34 var out_dir = try fs.cwd().openDir(fs.path.dirname(output_file).?, .{});
35 defer out_dir.close();
37 var out_dir = try Dir.cwd().openDir(Dir.path.dirname(output_file).?, .{});
38 defer out_dir.close(io);
3639
3740 var in_file_reader = in_file.reader(io, &.{});
3841 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .unlimited);
......@@ -266,7 +269,7 @@ const Code = struct {
266269 };
267270};
268271
269fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype) !void {
272fn walk(arena: Allocator, io: Io, tokenizer: *Tokenizer, out_dir: Dir, w: anytype) !void {
270273 while (true) {
271274 const token = tokenizer.next();
272275 switch (token.id) {
......@@ -387,7 +390,7 @@ fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype
387390 var file = out_dir.createFile(basename, .{ .exclusive = true }) catch |err| {
388391 fatal("unable to create file '{s}': {s}", .{ name, @errorName(err) });
389392 };
390 defer file.close();
393 defer file.close(io);
391394 var file_buffer: [1024]u8 = undefined;
392395 var file_writer = file.writer(&file_buffer);
393396 const code = &file_writer.interface;
tools/process_headers.zig+20-13
......@@ -12,6 +12,8 @@
1212//! You'll then have to manually update Zig source repo with these new files.
1313
1414const std = @import("std");
15const Io = std.Io;
16const Dir = std.Io.Dir;
1517const Arch = std.Target.Cpu.Arch;
1618const Abi = std.Target.Abi;
1719const OsTag = std.Target.Os.Tag;
......@@ -128,6 +130,11 @@ const LibCVendor = enum {
128130pub fn main() !void {
129131 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
130132 const allocator = arena.allocator();
133
134 var threaded: Io.Threaded = .init(allocator);
135 defer threaded.deinit();
136 const io = threaded.io();
137
131138 const args = try std.process.argsAlloc(allocator);
132139 var search_paths = std.array_list.Managed([]const u8).init(allocator);
133140 var opt_out_dir: ?[]const u8 = null;
......@@ -232,28 +239,28 @@ pub fn main() !void {
232239 => &[_][]const u8{ search_path, libc_dir, "usr", "include" },
233240 .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" },
234241 };
235 const target_include_dir = try std.fs.path.join(allocator, sub_path);
242 const target_include_dir = try Dir.path.join(allocator, sub_path);
236243 var dir_stack = std.array_list.Managed([]const u8).init(allocator);
237244 try dir_stack.append(target_include_dir);
238245
239246 while (dir_stack.pop()) |full_dir_name| {
240 var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
247 var dir = Dir.cwd().openDir(io, full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
241248 error.FileNotFound => continue :search,
242249 error.AccessDenied => continue :search,
243250 else => return err,
244251 };
245 defer dir.close();
252 defer dir.close(io);
246253
247254 var dir_it = dir.iterate();
248255
249256 while (try dir_it.next()) |entry| {
250 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name });
257 const full_path = try Dir.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name });
251258 switch (entry.kind) {
252259 .directory => try dir_stack.append(full_path),
253260 .file, .sym_link => {
254 const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path);
261 const rel_path = try Dir.path.relative(allocator, target_include_dir, full_path);
255262 const max_size = 2 * 1024 * 1024 * 1024;
256 const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, allocator, .limited(max_size));
263 const raw_bytes = try Dir.cwd().readFileAlloc(full_path, allocator, .limited(max_size));
257264 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
258265 total_bytes += raw_bytes.len;
259266 const hash = try allocator.alloc(u8, 32);
......@@ -314,7 +321,7 @@ pub fn main() !void {
314321 total_bytes,
315322 total_bytes - max_bytes_saved,
316323 });
317 try std.fs.cwd().makePath(out_dir);
324 try Dir.cwd().createDirPath(io, out_dir);
318325
319326 var missed_opportunity_bytes: usize = 0;
320327 // iterate path_table. for each path, put all the hashes into a list. sort by hit_count.
......@@ -334,9 +341,9 @@ pub fn main() !void {
334341 const best_contents = contents_list.pop().?;
335342 if (best_contents.hit_count > 1) {
336343 // worth it to make it generic
337 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
338 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
339 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
344 const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
345 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
346 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes });
340347 best_contents.is_generic = true;
341348 while (contents_list.pop()) |contender| {
342349 if (contender.hit_count > 1) {
......@@ -355,9 +362,9 @@ pub fn main() !void {
355362 if (contents.is_generic) continue;
356363
357364 const dest_target = hash_kv.key_ptr.*;
358 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* });
359 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
360 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });
365 const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* });
366 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
367 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes });
361368 }
362369 }
363370}
tools/update-linux-headers.zig+22-15
......@@ -15,6 +15,8 @@
1515//! You'll then have to manually update Zig source repo with these new files.
1616
1717const std = @import("std");
18const Io = std.Io;
19const Dir = std.Io.Dir;
1820const Arch = std.Target.Cpu.Arch;
1921const Abi = std.Target.Abi;
2022const assert = std.debug.assert;
......@@ -142,6 +144,11 @@ const PathTable = std.StringHashMap(*TargetToHash);
142144pub fn main() !void {
143145 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
144146 const arena = arena_state.allocator();
147
148 var threaded: Io.Threaded = .init(arena);
149 defer threaded.deinit();
150 const io = threaded.io();
151
145152 const args = try std.process.argsAlloc(arena);
146153 var search_paths = std.array_list.Managed([]const u8).init(arena);
147154 var opt_out_dir: ?[]const u8 = null;
......@@ -183,30 +190,30 @@ pub fn main() !void {
183190 .arch = linux_target.arch,
184191 };
185192 search: for (search_paths.items) |search_path| {
186 const target_include_dir = try std.fs.path.join(arena, &.{
193 const target_include_dir = try Dir.path.join(arena, &.{
187194 search_path, linux_target.name, "include",
188195 });
189196 var dir_stack = std.array_list.Managed([]const u8).init(arena);
190197 try dir_stack.append(target_include_dir);
191198
192199 while (dir_stack.pop()) |full_dir_name| {
193 var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
200 var dir = Dir.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
194201 error.FileNotFound => continue :search,
195202 error.AccessDenied => continue :search,
196203 else => return err,
197204 };
198 defer dir.close();
205 defer dir.close(io);
199206
200207 var dir_it = dir.iterate();
201208
202209 while (try dir_it.next()) |entry| {
203 const full_path = try std.fs.path.join(arena, &[_][]const u8{ full_dir_name, entry.name });
210 const full_path = try Dir.path.join(arena, &[_][]const u8{ full_dir_name, entry.name });
204211 switch (entry.kind) {
205212 .directory => try dir_stack.append(full_path),
206213 .file => {
207 const rel_path = try std.fs.path.relative(arena, target_include_dir, full_path);
214 const rel_path = try Dir.path.relative(arena, target_include_dir, full_path);
208215 const max_size = 2 * 1024 * 1024 * 1024;
209 const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, arena, .limited(max_size));
216 const raw_bytes = try Dir.cwd().readFileAlloc(full_path, arena, .limited(max_size));
210217 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
211218 total_bytes += raw_bytes.len;
212219 const hash = try arena.alloc(u8, 32);
......@@ -253,7 +260,7 @@ pub fn main() !void {
253260 total_bytes,
254261 total_bytes - max_bytes_saved,
255262 });
256 try std.fs.cwd().makePath(out_dir);
263 try Dir.cwd().createDirPath(io, out_dir);
257264
258265 var missed_opportunity_bytes: usize = 0;
259266 // iterate path_table. for each path, put all the hashes into a list. sort by hit_count.
......@@ -273,9 +280,9 @@ pub fn main() !void {
273280 const best_contents = contents_list.pop().?;
274281 if (best_contents.hit_count > 1) {
275282 // worth it to make it generic
276 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
277 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
278 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
283 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
284 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
285 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes });
279286 best_contents.is_generic = true;
280287 while (contents_list.pop()) |contender| {
281288 if (contender.hit_count > 1) {
......@@ -299,9 +306,9 @@ pub fn main() !void {
299306 else => @tagName(dest_target.arch),
300307 };
301308 const out_subpath = try std.fmt.allocPrint(arena, "{s}-linux-any", .{arch_name});
302 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* });
303 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
304 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });
309 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* });
310 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
311 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes });
305312 }
306313 }
307314
......@@ -316,8 +323,8 @@ pub fn main() !void {
316323 "any-linux-any/linux/netfilter_ipv6/ip6t_HL.h",
317324 };
318325 for (bad_files) |bad_file| {
319 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, bad_file });
320 try std.fs.cwd().deleteFile(full_path);
326 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, bad_file });
327 try Dir.cwd().deleteFile(io, full_path);
321328 }
322329}
323330
tools/update_cpu_features.zig+16-14
......@@ -1,6 +1,8 @@
1const std = @import("std");
21const builtin = @import("builtin");
3const fs = std.fs;
2
3const std = @import("std");
4const Io = std.Io;
5const Dir = std.Io.Dir;
46const mem = std.mem;
57const json = std.json;
68const assert = std.debug.assert;
......@@ -1927,26 +1929,26 @@ pub fn main() anyerror!void {
19271929 // there shouldn't be any more argument after the optional filter
19281930 if (args.skip()) usageAndExit(args0, 1);
19291931
1930 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
1931 defer zig_src_dir.close();
1932 var zig_src_dir = try Dir.cwd().openDir(io, zig_src_root, .{});
1933 defer zig_src_dir.close(io);
19321934
1933 const root_progress = std.Progress.start(.{ .estimated_total_items = targets.len });
1935 const root_progress = std.Progress.start(io, .{ .estimated_total_items = targets.len });
19341936 defer root_progress.end();
19351937
1936 var group: std.Io.Group = .init;
1938 var group: Io.Group = .init;
19371939 defer group.cancel(io);
19381940
19391941 for (targets) |target| {
19401942 if (filter) |zig_name| {
19411943 if (!std.mem.eql(u8, target.zig_name, zig_name)) continue;
19421944 }
1943 group.async(io, processOneTarget, .{.{
1945 group.async(io, processOneTarget, .{ io, .{
19441946 .llvm_tblgen_exe = llvm_tblgen_exe,
19451947 .llvm_src_root = llvm_src_root,
19461948 .zig_src_dir = zig_src_dir,
19471949 .root_progress = root_progress,
19481950 .target = target,
1949 }});
1951 } });
19501952 }
19511953
19521954 group.wait(io);
......@@ -1955,12 +1957,12 @@ pub fn main() anyerror!void {
19551957const Job = struct {
19561958 llvm_tblgen_exe: []const u8,
19571959 llvm_src_root: []const u8,
1958 zig_src_dir: std.fs.Dir,
1960 zig_src_dir: Dir,
19591961 root_progress: std.Progress.Node,
19601962 target: ArchTarget,
19611963};
19621964
1963fn processOneTarget(job: Job) void {
1965fn processOneTarget(io: Io, job: Job) void {
19641966 errdefer |err| std.debug.panic("panic: {s}", .{@errorName(err)});
19651967 const target = job.target;
19661968
......@@ -2240,12 +2242,12 @@ fn processOneTarget(job: Job) void {
22402242
22412243 const render_progress = progress_node.start("rendering Zig code", 0);
22422244
2243 var target_dir = try job.zig_src_dir.openDir("lib/std/Target", .{});
2244 defer target_dir.close();
2245 var target_dir = try job.zig_src_dir.openDir(io, "lib/std/Target", .{});
2246 defer target_dir.close(io);
22452247
22462248 const zig_code_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{target.zig_name});
2247 var zig_code_file = try target_dir.createFile(zig_code_basename, .{});
2248 defer zig_code_file.close();
2249 var zig_code_file = try target_dir.createFile(io, zig_code_basename, .{});
2250 defer zig_code_file.close(io);
22492251
22502252 var zig_code_file_buffer: [4096]u8 = undefined;
22512253 var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer);
tools/update_crc_catalog.zig+18-13
......@@ -1,5 +1,6 @@
11const std = @import("std");
2const fs = std.fs;
2const Io = std.Io;
3const Dir = std.Io.Dir;
34const mem = std.mem;
45const ascii = std.ascii;
56
......@@ -10,25 +11,29 @@ pub fn main() anyerror!void {
1011 defer arena_state.deinit();
1112 const arena = arena_state.allocator();
1213
14 var threaded: Io.Threaded = .init(arena);
15 defer threaded.deinit();
16 const io = threaded.io();
17
1318 const args = try std.process.argsAlloc(arena);
1419 if (args.len <= 1) printUsageAndExit(args[0]);
1520
1621 const zig_src_root = args[1];
1722 if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]);
1823
19 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
20 defer zig_src_dir.close();
24 var zig_src_dir = try Dir.cwd().openDir(io, zig_src_root, .{});
25 defer zig_src_dir.close(io);
2126
22 const hash_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash" });
23 var hash_target_dir = try zig_src_dir.makeOpenPath(hash_sub_path, .{});
24 defer hash_target_dir.close();
27 const hash_sub_path = try Dir.path.join(arena, &.{ "lib", "std", "hash" });
28 var hash_target_dir = try zig_src_dir.createDirPathOpen(io, hash_sub_path, .{});
29 defer hash_target_dir.close(io);
2530
26 const crc_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" });
27 var crc_target_dir = try zig_src_dir.makeOpenPath(crc_sub_path, .{});
28 defer crc_target_dir.close();
31 const crc_sub_path = try Dir.path.join(arena, &.{ "lib", "std", "hash", "crc" });
32 var crc_target_dir = try zig_src_dir.createDirPathOpen(io, crc_sub_path, .{});
33 defer crc_target_dir.close(io);
2934
30 var zig_code_file = try hash_target_dir.createFile("crc.zig", .{});
31 defer zig_code_file.close();
35 var zig_code_file = try hash_target_dir.createFile(io, "crc.zig", .{});
36 defer zig_code_file.close(io);
3237 var zig_code_file_buffer: [4096]u8 = undefined;
3338 var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer);
3439 const code_writer = &zig_code_file_writer.interface;
......@@ -51,8 +56,8 @@ pub fn main() anyerror!void {
5156 \\
5257 );
5358
54 var zig_test_file = try crc_target_dir.createFile("test.zig", .{});
55 defer zig_test_file.close();
59 var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{});
60 defer zig_test_file.close(io);
5661 var zig_test_file_buffer: [4096]u8 = undefined;
5762 var zig_test_file_writer = zig_test_file.writer(&zig_test_file_buffer);
5863 const test_writer = &zig_test_file_writer.interface;
tools/update_freebsd_libc.zig+10-7
......@@ -5,6 +5,7 @@
55//! `zig run tools/update_freebsd_libc.zig -- ~/Downloads/freebsd-src .`
66
77const std = @import("std");
8const Io = std.Io;
89
910const exempt_files = [_][]const u8{
1011 // This file is maintained by a separate project and does not come from FreeBSD.
......@@ -16,22 +17,24 @@ pub fn main() !void {
1617 defer arena_instance.deinit();
1718 const arena = arena_instance.allocator();
1819
20 var threaded: Io.Threaded = .init(arena);
21 defer threaded.deinit();
22 const io = threaded.io();
23
1924 const args = try std.process.argsAlloc(arena);
2025 const freebsd_src_path = args[1];
2126 const zig_src_path = args[2];
2227
2328 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/freebsd", .{zig_src_path});
2429
25 var dest_dir = std.fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| {
26 std.log.err("unable to open destination directory '{s}': {s}", .{
27 dest_dir_path, @errorName(err),
28 });
30 var dest_dir = std.fs.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
31 std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
2932 std.process.exit(1);
3033 };
31 defer dest_dir.close();
34 defer dest_dir.close(io);
3235
3336 var freebsd_src_dir = try std.fs.cwd().openDir(freebsd_src_path, .{});
34 defer freebsd_src_dir.close();
37 defer freebsd_src_dir.close(io);
3538
3639 // Copy updated files from upstream.
3740 {
......@@ -57,7 +60,7 @@ pub fn main() !void {
5760 @errorName(err),
5861 });
5962 if (err == error.FileNotFound) {
60 try dest_dir.deleteFile(entry.path);
63 try dest_dir.deleteFile(io, entry.path);
6164 }
6265 };
6366 }
tools/update_glibc.zig+20-25
......@@ -7,9 +7,11 @@
77//! `zig run ../tools/update_glibc.zig -- ~/Downloads/glibc ..`
88
99const std = @import("std");
10const Io = std.Io;
11const Dir = std.Io.Dir;
1012const mem = std.mem;
1113const log = std.log;
12const fs = std.fs;
14const fatal = std.process.fatal;
1315
1416const exempt_files = [_][]const u8{
1517 // This file is maintained by a separate project and does not come from glibc.
......@@ -41,21 +43,23 @@ pub fn main() !void {
4143 defer arena_instance.deinit();
4244 const arena = arena_instance.allocator();
4345
46 var threaded: Io.Threaded = .init(arena);
47 defer threaded.deinit();
48 const io = threaded.io();
49
4450 const args = try std.process.argsAlloc(arena);
4551 const glibc_src_path = args[1];
4652 const zig_src_path = args[2];
4753
4854 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/glibc", .{zig_src_path});
4955
50 var dest_dir = fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| {
51 fatal("unable to open destination directory '{s}': {s}", .{
52 dest_dir_path, @errorName(err),
53 });
56 var dest_dir = Dir.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
57 fatal("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
5458 };
55 defer dest_dir.close();
59 defer dest_dir.close(io);
5660
57 var glibc_src_dir = try fs.cwd().openDir(glibc_src_path, .{});
58 defer glibc_src_dir.close();
61 var glibc_src_dir = try Dir.cwd().openDir(io, glibc_src_path, .{});
62 defer glibc_src_dir.close(io);
5963
6064 // Copy updated files from upstream.
6165 {
......@@ -73,13 +77,11 @@ pub fn main() !void {
7377 }
7478
7579 glibc_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {
76 log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{
77 glibc_src_path, entry.path,
78 dest_dir_path, entry.path,
79 @errorName(err),
80 log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{
81 glibc_src_path, entry.path, dest_dir_path, entry.path, err,
8082 });
8183 if (err == error.FileNotFound) {
82 try dest_dir.deleteFile(entry.path);
84 try dest_dir.deleteFile(io, entry.path);
8385 }
8486 };
8587 }
......@@ -88,20 +90,18 @@ pub fn main() !void {
8890 // Warn about duplicated files inside glibc/include/* that can be omitted
8991 // because they are already in generic-glibc/*.
9092
91 var include_dir = dest_dir.openDir("include", .{ .iterate = true }) catch |err| {
92 fatal("unable to open directory '{s}/include': {s}", .{
93 dest_dir_path, @errorName(err),
94 });
93 var include_dir = dest_dir.openDir(io, "include", .{ .iterate = true }) catch |err| {
94 fatal("unable to open directory '{s}/include': {t}", .{ dest_dir_path, err });
9595 };
96 defer include_dir.close();
96 defer include_dir.close(io);
9797
9898 const generic_glibc_path = try std.fmt.allocPrint(
9999 arena,
100100 "{s}/lib/libc/include/generic-glibc",
101101 .{zig_src_path},
102102 );
103 var generic_glibc_dir = try fs.cwd().openDir(generic_glibc_path, .{});
104 defer generic_glibc_dir.close();
103 var generic_glibc_dir = try Dir.cwd().openDir(io, generic_glibc_path, .{});
104 defer generic_glibc_dir.close(io);
105105
106106 var walker = try include_dir.walk(arena);
107107 defer walker.deinit();
......@@ -146,8 +146,3 @@ pub fn main() !void {
146146 }
147147 }
148148}
149
150fn fatal(comptime format: []const u8, args: anytype) noreturn {
151 log.err(format, args);
152 std.process.exit(1);
153}
tools/update_mingw.zig+23-17
......@@ -1,35 +1,41 @@
11const std = @import("std");
2const Io = std.Io;
3const Dir = std.Io.Dir;
24
35pub fn main() !void {
46 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
57 defer arena_instance.deinit();
68 const arena = arena_instance.allocator();
79
10 var threaded: Io.Threaded = .init(arena);
11 defer threaded.deinit();
12 const io = threaded.io();
13
814 const args = try std.process.argsAlloc(arena);
915 const zig_src_lib_path = args[1];
1016 const mingw_src_path = args[2];
1117
12 const dest_mingw_crt_path = try std.fs.path.join(arena, &.{
18 const dest_mingw_crt_path = try Dir.path.join(arena, &.{
1319 zig_src_lib_path, "libc", "mingw",
1420 });
15 const src_mingw_crt_path = try std.fs.path.join(arena, &.{
21 const src_mingw_crt_path = try Dir.path.join(arena, &.{
1622 mingw_src_path, "mingw-w64-crt",
1723 });
1824
1925 // Update only the set of existing files we have already chosen to include
2026 // in zig's installation.
2127
22 var dest_crt_dir = std.fs.cwd().openDir(dest_mingw_crt_path, .{ .iterate = true }) catch |err| {
28 var dest_crt_dir = Dir.cwd().openDir(io, dest_mingw_crt_path, .{ .iterate = true }) catch |err| {
2329 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_crt_path, @errorName(err) });
2430 std.process.exit(1);
2531 };
26 defer dest_crt_dir.close();
32 defer dest_crt_dir.close(io);
2733
28 var src_crt_dir = std.fs.cwd().openDir(src_mingw_crt_path, .{ .iterate = true }) catch |err| {
34 var src_crt_dir = Dir.cwd().openDir(io, src_mingw_crt_path, .{ .iterate = true }) catch |err| {
2935 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_crt_path, @errorName(err) });
3036 std.process.exit(1);
3137 };
32 defer src_crt_dir.close();
38 defer src_crt_dir.close(io);
3339
3440 {
3541 var walker = try dest_crt_dir.walk(arena);
......@@ -49,11 +55,11 @@ pub fn main() !void {
4955
5056 if (!keep) {
5157 std.log.warn("deleting {s}", .{entry.path});
52 try dest_crt_dir.deleteFile(entry.path);
58 try dest_crt_dir.deleteFile(io, entry.path);
5359 }
5460 },
5561 else => {
56 std.log.err("unable to copy {s}: {s}", .{ entry.path, @errorName(err) });
62 std.log.err("unable to copy {s}: {t}", .{ entry.path, err });
5763 fail = true;
5864 },
5965 };
......@@ -63,24 +69,24 @@ pub fn main() !void {
6369 }
6470
6571 {
66 const dest_mingw_winpthreads_path = try std.fs.path.join(arena, &.{
72 const dest_mingw_winpthreads_path = try Dir.path.join(arena, &.{
6773 zig_src_lib_path, "libc", "mingw", "winpthreads",
6874 });
69 const src_mingw_libraries_winpthreads_src_path = try std.fs.path.join(arena, &.{
75 const src_mingw_libraries_winpthreads_src_path = try Dir.path.join(arena, &.{
7076 mingw_src_path, "mingw-w64-libraries", "winpthreads", "src",
7177 });
7278
73 var dest_winpthreads_dir = std.fs.cwd().openDir(dest_mingw_winpthreads_path, .{ .iterate = true }) catch |err| {
79 var dest_winpthreads_dir = Dir.cwd().openDir(io, dest_mingw_winpthreads_path, .{ .iterate = true }) catch |err| {
7480 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_winpthreads_path, @errorName(err) });
7581 std.process.exit(1);
7682 };
77 defer dest_winpthreads_dir.close();
83 defer dest_winpthreads_dir.close(io);
7884
79 var src_winpthreads_dir = std.fs.cwd().openDir(src_mingw_libraries_winpthreads_src_path, .{ .iterate = true }) catch |err| {
85 var src_winpthreads_dir = Dir.cwd().openDir(io, src_mingw_libraries_winpthreads_src_path, .{ .iterate = true }) catch |err| {
8086 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_libraries_winpthreads_src_path, @errorName(err) });
8187 std.process.exit(1);
8288 };
83 defer src_winpthreads_dir.close();
89 defer src_winpthreads_dir.close(io);
8490
8591 {
8692 var walker = try dest_winpthreads_dir.walk(arena);
......@@ -94,10 +100,10 @@ pub fn main() !void {
94100 src_winpthreads_dir.copyFile(entry.path, dest_winpthreads_dir, entry.path, .{}) catch |err| switch (err) {
95101 error.FileNotFound => {
96102 std.log.warn("deleting {s}", .{entry.path});
97 try dest_winpthreads_dir.deleteFile(entry.path);
103 try dest_winpthreads_dir.deleteFile(io, entry.path);
98104 },
99105 else => {
100 std.log.err("unable to copy {s}: {s}", .{ entry.path, @errorName(err) });
106 std.log.err("unable to copy {s}: {t}", .{ entry.path, err });
101107 fail = true;
102108 },
103109 };
......@@ -164,7 +170,7 @@ pub fn main() !void {
164170
165171const kept_crt_files = [_][]const u8{
166172 "COPYING",
167 "include" ++ std.fs.path.sep_str ++ "config.h",
173 "include" ++ Dir.path.sep_str ++ "config.h",
168174};
169175
170176const def_exts = [_][]const u8{
tools/update_netbsd_libc.zig+13-12
......@@ -5,6 +5,7 @@
55//! `zig run tools/update_netbsd_libc.zig -- ~/Downloads/netbsd-src .`
66
77const std = @import("std");
8const Io = std.Io;
89
910const exempt_files = [_][]const u8{
1011 // This file is maintained by a separate project and does not come from NetBSD.
......@@ -16,22 +17,24 @@ pub fn main() !void {
1617 defer arena_instance.deinit();
1718 const arena = arena_instance.allocator();
1819
20 var threaded: Io.Threaded = .init(arena);
21 defer threaded.deinit();
22 const io = threaded.io();
23
1924 const args = try std.process.argsAlloc(arena);
2025 const netbsd_src_path = args[1];
2126 const zig_src_path = args[2];
2227
2328 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/netbsd", .{zig_src_path});
2429
25 var dest_dir = std.fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| {
26 std.log.err("unable to open destination directory '{s}': {s}", .{
27 dest_dir_path, @errorName(err),
28 });
30 var dest_dir = std.fs.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
31 std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
2932 std.process.exit(1);
3033 };
31 defer dest_dir.close();
34 defer dest_dir.close(io);
3235
33 var netbsd_src_dir = try std.fs.cwd().openDir(netbsd_src_path, .{});
34 defer netbsd_src_dir.close();
36 var netbsd_src_dir = try std.fs.cwd().openDir(io, netbsd_src_path, .{});
37 defer netbsd_src_dir.close(io);
3538
3639 // Copy updated files from upstream.
3740 {
......@@ -51,13 +54,11 @@ pub fn main() !void {
5154 });
5255
5356 netbsd_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {
54 std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{
55 netbsd_src_path, entry.path,
56 dest_dir_path, entry.path,
57 @errorName(err),
57 std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{
58 netbsd_src_path, entry.path, dest_dir_path, entry.path, err,
5859 });
5960 if (err == error.FileNotFound) {
60 try dest_dir.deleteFile(entry.path);
61 try dest_dir.deleteFile(io, entry.path);
6162 }
6263 };
6364 }