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 {...@@ -73,15 +73,15 @@ pub fn main() !void {
73 const code_dir_path = opt_code_dir orelse fatal("missing --code-dir argument", .{});73 const code_dir_path = opt_code_dir orelse fatal("missing --code-dir argument", .{});
7474
75 var in_file = try fs.cwd().openFile(input_path, .{});75 var in_file = try fs.cwd().openFile(input_path, .{});
76 defer in_file.close();76 defer in_file.close(io);
7777
78 var out_file = try fs.cwd().createFile(output_path, .{});78 var out_file = try fs.cwd().createFile(output_path, .{});
79 defer out_file.close();79 defer out_file.close(io);
80 var out_file_buffer: [4096]u8 = undefined;80 var out_file_buffer: [4096]u8 = undefined;
81 var out_file_writer = out_file.writer(&out_file_buffer);81 var out_file_writer = out_file.writer(&out_file_buffer);
8282
83 var code_dir = try fs.cwd().openDir(code_dir_path, .{});83 var code_dir = try fs.cwd().openDir(code_dir_path, .{});
84 defer code_dir.close();84 defer code_dir.close(io);
8585
86 var in_file_reader = in_file.reader(io, &.{});86 var in_file_reader = in_file.reader(io, &.{});
87 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size));87 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 {...@@ -85,16 +85,16 @@ pub fn main() !void {
85 const tmp_dir_path = try std.fmt.allocPrint(arena, "{s}/tmp/{x}", .{85 const tmp_dir_path = try std.fmt.allocPrint(arena, "{s}/tmp/{x}", .{
86 cache_root, std.crypto.random.int(u64),86 cache_root, std.crypto.random.int(u64),
87 });87 });
88 fs.cwd().makePath(tmp_dir_path) catch |err|88 fs.cwd().createDirPath(io, tmp_dir_path) catch |err|
89 fatal("unable to create tmp dir '{s}': {s}", .{ tmp_dir_path, @errorName(err) });89 fatal("unable to create tmp dir '{s}': {t}", .{ tmp_dir_path, err });
90 defer fs.cwd().deleteTree(tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {s}", .{90 defer fs.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{
91 tmp_dir_path, @errorName(err),91 tmp_dir_path, err,
92 });92 });
9393
94 var out_file = try fs.cwd().createFile(output_path, .{});94 var out_file = try fs.cwd().createFile(io, output_path, .{});
95 defer out_file.close();95 defer out_file.close(io);
96 var out_file_buffer: [4096]u8 = undefined;96 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
99 const out = &out_file_writer.interface;99 const out = &out_file_writer.interface;
100100
tools/fetch_them_macos_headers.zig+21-21
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;2const Io = std.Io;
3const fs = std.fs;3const Dir = std.Io.Dir;
4const mem = std.mem;4const mem = std.mem;
5const process = std.process;5const process = std.process;
6const assert = std.debug.assert;6const assert = std.debug.assert;
...@@ -96,9 +96,9 @@ pub fn main() anyerror!void {...@@ -96,9 +96,9 @@ pub fn main() anyerror!void {
96 fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{});96 fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{});
97 };97 };
9898
99 var sdk_dir = try std.fs.cwd().openDir(sysroot_path, .{});99 var sdk_dir = try Dir.cwd().openDir(io, sysroot_path, .{});
100 defer sdk_dir.close();100 defer sdk_dir.close(io);
101 const sdk_info = try sdk_dir.readFileAlloc("SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));101 const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", allocator, .limited(std.math.maxInt(u32)));
102102
103 const parsed_json = try std.json.parseFromSlice(struct {103 const parsed_json = try std.json.parseFromSlice(struct {
104 DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 },104 DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 },
...@@ -135,8 +135,8 @@ fn fetchTarget(...@@ -135,8 +135,8 @@ fn fetchTarget(
135 const tmp_filename = "macos-headers";135 const tmp_filename = "macos-headers";
136 const headers_list_filename = "macos-headers.o.d";136 const headers_list_filename = "macos-headers.o.d";
137 const tmp_path = try tmp.dir.realpathAlloc(arena, ".");137 const tmp_path = try tmp.dir.realpathAlloc(arena, ".");
138 const tmp_file_path = try fs.path.join(arena, &[_][]const u8{ tmp_path, tmp_filename });138 const tmp_file_path = try Dir.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 });139 const headers_list_path = try Dir.path.join(arena, &[_][]const u8{ tmp_path, headers_list_filename });
140140
141 const macos_version = try std.fmt.allocPrint(arena, "-mmacosx-version-min={d}.{d}", .{141 const macos_version = try std.fmt.allocPrint(arena, "-mmacosx-version-min={d}.{d}", .{
142 ver.major,142 ver.major,
...@@ -176,10 +176,10 @@ fn fetchTarget(...@@ -176,10 +176,10 @@ fn fetchTarget(
176 }176 }
177177
178 // Read in the contents of `macos-headers.o.d`178 // Read in the contents of `macos-headers.o.d`
179 const headers_list_file = try tmp.dir.openFile(headers_list_filename, .{});179 const headers_list_file = try tmp.dir.openFile(io, headers_list_filename, .{});
180 defer headers_list_file.close();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) {
183 error.FileNotFound,183 error.FileNotFound,
184 error.NotDir,184 error.NotDir,
185 => fatal("path '{s}' not found or not a directory. Did you accidentally delete it?", .{185 => fatal("path '{s}' not found or not a directory. Did you accidentally delete it?", .{
...@@ -187,13 +187,13 @@ fn fetchTarget(...@@ -187,13 +187,13 @@ fn fetchTarget(
187 }),187 }),
188 else => return err,188 else => return err,
189 };189 };
190 defer headers_dir.close();190 defer headers_dir.close(io);
191191
192 const dest_path = try target.fullName(arena);192 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, .{});195 var dest_dir = try headers_dir.createDirPathOpen(io, dest_path, .{});
196 var dirs = std.StringHashMap(fs.Dir).init(arena);196 var dirs = std.StringHashMap(Dir).init(arena);
197 try dirs.putNoClobber(".", dest_dir);197 try dirs.putNoClobber(".", dest_dir);
198198
199 var headers_list_file_reader = headers_list_file.reader(io, &.{});199 var headers_list_file_reader = headers_list_file.reader(io, &.{});
...@@ -206,25 +206,25 @@ fn fetchTarget(...@@ -206,25 +206,25 @@ fn fetchTarget(
206 if (mem.lastIndexOf(u8, line, prefix[0..])) |idx| {206 if (mem.lastIndexOf(u8, line, prefix[0..])) |idx| {
207 const out_rel_path = line[idx + prefix.len + 1 ..];207 const out_rel_path = line[idx + prefix.len + 1 ..];
208 const out_rel_path_stripped = mem.trim(u8, out_rel_path, " \\");208 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 ".";
210 const maybe_dir = try dirs.getOrPut(dirname);210 const maybe_dir = try dirs.getOrPut(dirname);
211 if (!maybe_dir.found_existing) {211 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, .{});
213 }213 }
214 const basename = fs.path.basename(out_rel_path_stripped);214 const basename = Dir.path.basename(out_rel_path_stripped);
215215
216 const line_stripped = mem.trim(u8, line, " \\");216 const line_stripped = mem.trim(u8, line, " \\");
217 const abs_dirname = fs.path.dirname(line_stripped).?;217 const abs_dirname = Dir.path.dirname(line_stripped).?;
218 var orig_subdir = try fs.cwd().openDir(abs_dirname, .{});218 var orig_subdir = try Dir.cwd().openDir(abs_dirname, .{});
219 defer orig_subdir.close();219 defer orig_subdir.close(io);
220220
221 try orig_subdir.copyFile(basename, maybe_dir.value_ptr.*, basename, .{});221 try orig_subdir.copyFile(basename, maybe_dir.value_ptr.*, basename, .{});
222 }222 }
223 }223 }
224224
225 var dir_it = dirs.iterator();225 var dir_it = dirs.iterator();
226 while (dir_it.next()) |entry| {226 while (dir_it.next(io)) |entry| {
227 entry.value_ptr.close();227 entry.value_ptr.close(io);
228 }228 }
229}229}
230230
tools/gen_macos_headers_c.zig+14-8
...@@ -1,8 +1,9 @@...@@ -1,8 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
3const Dir = std.Io.Dir;
2const assert = std.debug.assert;4const assert = std.debug.assert;
3const info = std.log.info;5const info = std.log.info;
4const fatal = std.process.fatal;6const fatal = std.process.fatal;
5
6const Allocator = std.mem.Allocator;7const Allocator = std.mem.Allocator;
78
8var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};9var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
...@@ -20,6 +21,10 @@ pub fn main() anyerror!void {...@@ -20,6 +21,10 @@ pub fn main() anyerror!void {
20 defer arena_allocator.deinit();21 defer arena_allocator.deinit();
21 const arena = arena_allocator.allocator();22 const arena = arena_allocator.allocator();
2223
24 var threaded: Io.Threaded = .init(gpa);
25 defer threaded.deinit();
26 const io = threaded.io();
27
23 const args = try std.process.argsAlloc(arena);28 const args = try std.process.argsAlloc(arena);
24 if (args.len == 1) fatal("no command or option specified", .{});29 if (args.len == 1) fatal("no command or option specified", .{});
2530
...@@ -33,10 +38,10 @@ pub fn main() anyerror!void {...@@ -33,10 +38,10 @@ pub fn main() anyerror!void {
3338
34 if (positionals.items.len != 1) fatal("expected one positional argument: [dir]", .{});39 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 });41 var dir = try std.fs.cwd().openDir(io, positionals.items[0], .{ .follow_symlinks = false });
37 defer dir.close();42 defer dir.close(io);
38 var paths = std.array_list.Managed([]const u8).init(arena);43 var paths = std.array_list.Managed([]const u8).init(arena);
39 try findHeaders(arena, dir, "", &paths);44 try findHeaders(arena, io, dir, "", &paths);
4045
41 const SortFn = struct {46 const SortFn = struct {
42 pub fn lessThan(ctx: void, lhs: []const u8, rhs: []const u8) bool {47 pub fn lessThan(ctx: void, lhs: []const u8, rhs: []const u8) bool {
...@@ -64,7 +69,8 @@ pub fn main() anyerror!void {...@@ -64,7 +69,8 @@ pub fn main() anyerror!void {
6469
65fn findHeaders(70fn findHeaders(
66 arena: Allocator,71 arena: Allocator,
67 dir: std.fs.Dir,72 io: Io,
73 dir: Dir,
68 prefix: []const u8,74 prefix: []const u8,
69 paths: *std.array_list.Managed([]const u8),75 paths: *std.array_list.Managed([]const u8),
70) anyerror!void {76) anyerror!void {
...@@ -73,9 +79,9 @@ fn findHeaders(...@@ -73,9 +79,9 @@ fn findHeaders(
73 switch (entry.kind) {79 switch (entry.kind) {
74 .directory => {80 .directory => {
75 const path = try std.fs.path.join(arena, &.{ prefix, entry.name });81 const path = try std.fs.path.join(arena, &.{ prefix, entry.name });
76 var subdir = try dir.openDir(entry.name, .{ .follow_symlinks = false });82 var subdir = try dir.openDir(io, entry.name, .{ .follow_symlinks = false });
77 defer subdir.close();83 defer subdir.close(io);
78 try findHeaders(arena, subdir, path, paths);84 try findHeaders(arena, io, subdir, path, paths);
79 },85 },
80 .file, .sym_link => {86 .file, .sym_link => {
81 const ext = std.fs.path.extension(entry.name);87 const ext = std.fs.path.extension(entry.name);
tools/generate_linux_syscalls.zig+7-3
...@@ -175,6 +175,10 @@ pub fn main() !void {...@@ -175,6 +175,10 @@ pub fn main() !void {
175 defer arena.deinit();175 defer arena.deinit();
176 const gpa = arena.allocator();176 const gpa = arena.allocator();
177177
178 var threaded: Io.Threaded = .init(gpa);
179 defer threaded.deinit();
180 const io = threaded.io();
181
178 const args = try std.process.argsAlloc(gpa);182 const args = try std.process.argsAlloc(gpa);
179 if (args.len < 2 or mem.eql(u8, args[1], "--help")) {183 if (args.len < 2 or mem.eql(u8, args[1], "--help")) {
180 const w, _ = std.debug.lockStderrWriter(&.{});184 const w, _ = std.debug.lockStderrWriter(&.{});
...@@ -188,8 +192,8 @@ pub fn main() !void {...@@ -188,8 +192,8 @@ pub fn main() !void {
188 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);192 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
189 const stdout = &stdout_writer.interface;193 const stdout = &stdout_writer.interface;
190194
191 var linux_dir = try std.fs.cwd().openDir(linux_path, .{});195 var linux_dir = try std.fs.cwd().openDir(io, linux_path, .{});
192 defer linux_dir.close();196 defer linux_dir.close(io);
193197
194 // As of 6.11, the largest table is 24195 bytes.198 // As of 6.11, the largest table is 24195 bytes.
195 // 32k should be enough for now.199 // 32k should be enough for now.
...@@ -198,7 +202,7 @@ pub fn main() !void {...@@ -198,7 +202,7 @@ pub fn main() !void {
198202
199 // Fetch the kernel version from the Makefile variables.203 // Fetch the kernel version from the Makefile variables.
200 const version = blk: {204 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]);
202 var lines = mem.tokenizeScalar(u8, head, '\n');206 var lines = mem.tokenizeScalar(u8, head, '\n');
203 _ = lines.next(); // Skip SPDX identifier207 _ = lines.next(); // Skip SPDX identifier
204208
tools/incr-check.zig+54-44
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;2const Io = std.Io;
3const Dir = std.Io.Dir;
3const Allocator = std.mem.Allocator;4const Allocator = std.mem.Allocator;
4const Cache = std.Build.Cache;5const Cache = std.Build.Cache;
56
...@@ -59,7 +60,7 @@ pub fn main() !void {...@@ -59,7 +60,7 @@ pub fn main() !void {
59 const zig_exe = opt_zig_exe orelse fatal("missing path to zig\n{s}", .{usage});60 const zig_exe = opt_zig_exe orelse fatal("missing path to zig\n{s}", .{usage});
60 const input_file_name = opt_input_file_name orelse fatal("missing input file\n{s}", .{usage});61 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)));
63 const case = try Case.parse(arena, io, input_file_bytes);64 const case = try Case.parse(arena, io, input_file_bytes);
6465
65 // Check now: if there are any targets using the `cbe` backend, we need the lib dir.66 // Check now: if there are any targets using the `cbe` backend, we need the lib dir.
...@@ -71,25 +72,25 @@ pub fn main() !void {...@@ -71,25 +72,25 @@ pub fn main() !void {
71 }72 }
72 }73 }
7374
74 const prog_node = std.Progress.start(.{});75 const prog_node = std.Progress.start(io, .{});
75 defer prog_node.end();76 defer prog_node.end();
7677
77 const rand_int = std.crypto.random.int(u64);78 const rand_int = std.crypto.random.int(u64);
78 const tmp_dir_path = "tmp_" ++ std.fmt.hex(rand_int);79 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, .{});
80 defer {81 defer {
81 tmp_dir.close();82 tmp_dir.close(io);
82 if (!preserve_tmp) {83 if (!preserve_tmp) {
83 std.fs.cwd().deleteTree(tmp_dir_path) catch |err| {84 Dir.cwd().deleteTree(io, tmp_dir_path) catch |err| {
84 std.log.warn("failed to delete tree '{s}': {s}", .{ tmp_dir_path, @errorName(err) });85 std.log.warn("failed to delete tree '{s}': {t}", .{ tmp_dir_path, err });
85 };86 };
86 }87 }
87 }88 }
8889
89 // Convert paths to be relative to the cwd of the subprocess.90 // 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);
91 const opt_resolved_lib_dir = if (opt_lib_dir) |lib_dir|92 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)
93 else94 else
94 null;95 null;
9596
...@@ -164,7 +165,7 @@ pub fn main() !void {...@@ -164,7 +165,7 @@ pub fn main() !void {
164 var cc_child_args: std.ArrayList([]const u8) = .empty;165 var cc_child_args: std.ArrayList([]const u8) = .empty;
165 if (target.backend == .cbe) {166 if (target.backend == .cbe) {
166 const resolved_cc_zig_exe = if (opt_cc_zig) |cc_zig_exe|167 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)
168 else169 else
169 resolved_zig_exe;170 resolved_zig_exe;
170171
...@@ -185,6 +186,7 @@ pub fn main() !void {...@@ -185,6 +186,7 @@ pub fn main() !void {
185186
186 var eval: Eval = .{187 var eval: Eval = .{
187 .arena = arena,188 .arena = arena,
189 .io = io,
188 .case = case,190 .case = case,
189 .host = host,191 .host = host,
190 .target = target,192 .target = target,
...@@ -196,9 +198,9 @@ pub fn main() !void {...@@ -196,9 +198,9 @@ pub fn main() !void {
196 .cc_child_args = &cc_child_args,198 .cc_child_args = &cc_child_args,
197 };199 };
198200
199 try child.spawn();201 try child.spawn(io);
200 errdefer {202 errdefer {
201 _ = child.kill() catch {};203 _ = child.kill(io) catch {};
202 }204 }
203205
204 var poller = Io.poll(arena, Eval.StreamEnum, .{206 var poller = Io.poll(arena, Eval.StreamEnum, .{
...@@ -228,10 +230,11 @@ pub fn main() !void {...@@ -228,10 +230,11 @@ pub fn main() !void {
228230
229const Eval = struct {231const Eval = struct {
230 arena: Allocator,232 arena: Allocator,
233 io: Io,
231 host: std.Target,234 host: std.Target,
232 case: Case,235 case: Case,
233 target: Case.Target,236 target: Case.Target,
234 tmp_dir: std.fs.Dir,237 tmp_dir: Dir,
235 tmp_dir_path: []const u8,238 tmp_dir_path: []const u8,
236 child: *std.process.Child,239 child: *std.process.Child,
237 allow_stderr: bool,240 allow_stderr: bool,
...@@ -245,17 +248,18 @@ const Eval = struct {...@@ -245,17 +248,18 @@ const Eval = struct {
245248
246 /// Currently this function assumes the previous updates have already been written.249 /// Currently this function assumes the previous updates have already been written.
247 fn write(eval: *Eval, update: Case.Update) void {250 fn write(eval: *Eval, update: Case.Update) void {
251 const io = eval.io;
248 for (update.changes) |full_contents| {252 for (update.changes) |full_contents| {
249 eval.tmp_dir.writeFile(.{253 eval.tmp_dir.writeFile(io, .{
250 .sub_path = full_contents.name,254 .sub_path = full_contents.name,
251 .data = full_contents.bytes,255 .data = full_contents.bytes,
252 }) catch |err| {256 }) 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 });
254 };258 };
255 }259 }
256 for (update.deletes) |doomed_name| {260 for (update.deletes) |doomed_name| {
257 eval.tmp_dir.deleteFile(doomed_name) catch |err| {261 eval.tmp_dir.deleteFile(io, doomed_name) catch |err| {
258 eval.fatal("failed to delete '{s}': {s}", .{ doomed_name, @errorName(err) });262 eval.fatal("failed to delete '{s}': {t}", .{ doomed_name, err });
259 };263 };
260 }264 }
261 }265 }
...@@ -307,14 +311,14 @@ const Eval = struct {...@@ -307,14 +311,14 @@ const Eval = struct {
307 }311 }
308312
309 const digest = r.takeArray(Cache.bin_digest_len) catch unreachable;313 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
312 const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{316 const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{
313 .root_name = "root", // corresponds to the module name "root"317 .root_name = "root", // corresponds to the module name "root"
314 .target = &eval.target.resolved,318 .target = &eval.target.resolved,
315 .output_mode = .Exe,319 .output_mode = .Exe,
316 });320 });
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
319 try eval.checkSuccessOutcome(update, bin_path, prog_node);323 try eval.checkSuccessOutcome(update, bin_path, prog_node);
320 // This message indicates the end of the update.324 // This message indicates the end of the update.
...@@ -338,11 +342,12 @@ const Eval = struct {...@@ -338,11 +342,12 @@ const Eval = struct {
338 }342 }
339343
340 fn checkErrorOutcome(eval: *Eval, update: Case.Update, error_bundle: std.zig.ErrorBundle) !void {344 fn checkErrorOutcome(eval: *Eval, update: Case.Update, error_bundle: std.zig.ErrorBundle) !void {
345 const io = eval.io;
341 const expected = switch (update.outcome) {346 const expected = switch (update.outcome) {
342 .unknown => return,347 .unknown => return,
343 .compile_errors => |ce| ce,348 .compile_errors => |ce| ce,
344 .stdout, .exit_code => {349 .stdout, .exit_code => {
345 error_bundle.renderToStdErr(.{}, .auto);350 try error_bundle.renderToStderr(io, .{}, .auto);
346 eval.fatal("update '{s}': unexpected compile errors", .{update.name});351 eval.fatal("update '{s}': unexpected compile errors", .{update.name});
347 },352 },
348 };353 };
...@@ -351,7 +356,7 @@ const Eval = struct {...@@ -351,7 +356,7 @@ const Eval = struct {
351356
352 for (error_bundle.getMessages()) |err_idx| {357 for (error_bundle.getMessages()) |err_idx| {
353 if (expected_idx == expected.errors.len) {358 if (expected_idx == expected.errors.len) {
354 error_bundle.renderToStdErr(.{}, .auto);359 try error_bundle.renderToStderr(io, .{}, .auto);
355 eval.fatal("update '{s}': more errors than expected", .{update.name});360 eval.fatal("update '{s}': more errors than expected", .{update.name});
356 }361 }
357 try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], false, err_idx);362 try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], false, err_idx);
...@@ -359,7 +364,7 @@ const Eval = struct {...@@ -359,7 +364,7 @@ const Eval = struct {
359364
360 for (error_bundle.getNotes(err_idx)) |note_idx| {365 for (error_bundle.getNotes(err_idx)) |note_idx| {
361 if (expected_idx == expected.errors.len) {366 if (expected_idx == expected.errors.len) {
362 error_bundle.renderToStdErr(.{}, .auto);367 try error_bundle.renderToStderr(io, .{}, .auto);
363 eval.fatal("update '{s}': more error notes than expected", .{update.name});368 eval.fatal("update '{s}': more error notes than expected", .{update.name});
364 }369 }
365 try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], true, note_idx);370 try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], true, note_idx);
...@@ -368,7 +373,7 @@ const Eval = struct {...@@ -368,7 +373,7 @@ const Eval = struct {
368 }373 }
369374
370 if (!std.mem.eql(u8, error_bundle.getCompileLogOutput(), expected.compile_log_output)) {375 if (!std.mem.eql(u8, error_bundle.getCompileLogOutput(), expected.compile_log_output)) {
371 error_bundle.renderToStdErr(.{}, .auto);376 try error_bundle.renderToStderr(io, .{}, .auto);
372 eval.fatal("update '{s}': unexpected compile log output", .{update.name});377 eval.fatal("update '{s}': unexpected compile log output", .{update.name});
373 }378 }
374 }379 }
...@@ -388,6 +393,8 @@ const Eval = struct {...@@ -388,6 +393,8 @@ const Eval = struct {
388 const src = eb.getSourceLocation(err.src_loc);393 const src = eb.getSourceLocation(err.src_loc);
389 const raw_filename = eb.nullTerminatedString(src.src_path);394 const raw_filename = eb.nullTerminatedString(src.src_path);
390395
396 const io = eval.io;
397
391 // We need to replace backslashes for consistency between platforms.398 // We need to replace backslashes for consistency between platforms.
392 const filename = name: {399 const filename = name: {
393 if (std.mem.indexOfScalar(u8, raw_filename, '\\') == null) break :name raw_filename;400 if (std.mem.indexOfScalar(u8, raw_filename, '\\') == null) break :name raw_filename;
...@@ -402,7 +409,7 @@ const Eval = struct {...@@ -402,7 +409,7 @@ const Eval = struct {
402 expected.column != src.column + 1 or409 expected.column != src.column + 1 or
403 !std.mem.eql(u8, expected.msg, msg))410 !std.mem.eql(u8, expected.msg, msg))
404 {411 {
405 eb.renderToStdErr(.{}, .auto);412 eb.renderToStderr(io, .{}, .auto) catch {};
406 eval.fatal("update '{s}': compile error did not match expected error", .{update.name});413 eval.fatal("update '{s}': compile error did not match expected error", .{update.name});
407 }414 }
408 }415 }
...@@ -429,8 +436,11 @@ const Eval = struct {...@@ -429,8 +436,11 @@ const Eval = struct {
429 },436 },
430 };437 };
431438
439 const io = eval.io;
440
432 var argv_buf: [2][]const u8 = undefined;441 var argv_buf: [2][]const u8 = undefined;
433 const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor(442 const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor(
443 io,
434 &eval.host,444 &eval.host,
435 &eval.target.resolved,445 &eval.target.resolved,
436 .{ .link_libc = eval.target.backend == .cbe },446 .{ .link_libc = eval.target.backend == .cbe },
...@@ -459,8 +469,7 @@ const Eval = struct {...@@ -459,8 +469,7 @@ const Eval = struct {
459 const run_prog_node = prog_node.start("run generated executable", 0);469 const run_prog_node = prog_node.start("run generated executable", 0);
460 defer run_prog_node.end();470 defer run_prog_node.end();
461471
462 const result = std.process.Child.run(.{472 const result = std.process.Child.run(eval.arena, io, .{
463 .allocator = eval.arena,
464 .argv = argv,473 .argv = argv,
465 .cwd_dir = eval.tmp_dir,474 .cwd_dir = eval.tmp_dir,
466 .cwd = eval.tmp_dir_path,475 .cwd = eval.tmp_dir_path,
...@@ -468,17 +477,17 @@ const Eval = struct {...@@ -468,17 +477,17 @@ const Eval = struct {
468 if (is_foreign) {477 if (is_foreign) {
469 // Chances are the foreign executor isn't available. Skip this evaluation.478 // Chances are the foreign executor isn't available. Skip this evaluation.
470 if (eval.allow_stderr) {479 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}", .{
472 update.name,481 update.name,
473 binary_path,482 binary_path,
474 try eval.target.resolved.zigTriple(eval.arena),483 try eval.target.resolved.zigTriple(eval.arena),
475 @errorName(err),484 err,
476 });485 });
477 }486 }
478 return;487 return;
479 }488 }
480 eval.fatal("update '{s}': failed to run the generated executable '{s}': {s}", .{489 eval.fatal("update '{s}': failed to run the generated executable '{s}': {t}", .{
481 update.name, binary_path, @errorName(err),490 update.name, binary_path, err,
482 });491 });
483 };492 };
484493
...@@ -514,11 +523,12 @@ const Eval = struct {...@@ -514,11 +523,12 @@ const Eval = struct {
514 }523 }
515524
516 fn requestUpdate(eval: *Eval) !void {525 fn requestUpdate(eval: *Eval) !void {
526 const io = eval.io;
517 const header: std.zig.Client.Message.Header = .{527 const header: std.zig.Client.Message.Header = .{
518 .tag = .update,528 .tag = .update,
519 .bytes_len = 0,529 .bytes_len = 0,
520 };530 };
521 var w = eval.child.stdin.?.writer(&.{});531 var w = eval.child.stdin.?.writer(io, &.{});
522 w.interface.writeStruct(header, .little) catch |err| switch (err) {532 w.interface.writeStruct(header, .little) catch |err| switch (err) {
523 error.WriteFailed => return w.err.?,533 error.WriteFailed => return w.err.?,
524 };534 };
...@@ -552,16 +562,13 @@ const Eval = struct {...@@ -552,16 +562,13 @@ const Eval = struct {
552 try eval.cc_child_args.appendSlice(eval.arena, &.{ out_path, c_path });562 try eval.cc_child_args.appendSlice(eval.arena, &.{ out_path, c_path });
553 defer eval.cc_child_args.items.len -= 2;563 defer eval.cc_child_args.items.len -= 2;
554564
555 const result = std.process.Child.run(.{565 const result = std.process.Child.run(eval.arena, eval.io, .{
556 .allocator = eval.arena,
557 .argv = eval.cc_child_args.items,566 .argv = eval.cc_child_args.items,
558 .cwd_dir = eval.tmp_dir,567 .cwd_dir = eval.tmp_dir,
559 .cwd = eval.tmp_dir_path,568 .cwd = eval.tmp_dir_path,
560 .progress_node = child_prog_node,569 .progress_node = child_prog_node,
561 }) catch |err| {570 }) catch |err| {
562 eval.fatal("update '{s}': failed to spawn zig cc for '{s}': {s}", .{571 eval.fatal("update '{s}': failed to spawn zig cc for '{s}': {t}", .{ update.name, c_path, err });
563 update.name, c_path, @errorName(err),
564 });
565 };572 };
566 switch (result.term) {573 switch (result.term) {
567 .Exited => |code| if (code != 0) {574 .Exited => |code| if (code != 0) {
...@@ -588,12 +595,13 @@ const Eval = struct {...@@ -588,12 +595,13 @@ const Eval = struct {
588 }595 }
589596
590 fn fatal(eval: *Eval, comptime fmt: []const u8, args: anytype) noreturn {597 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);
592 if (!eval.preserve_tmp_on_fatal) {600 if (!eval.preserve_tmp_on_fatal) {
593 // Kill the child since it holds an open handle to its CWD which is the tmp dir path601 // Kill the child since it holds an open handle to its CWD which is the tmp dir path
594 _ = eval.child.kill() catch {};602 _ = eval.child.kill(io) catch {};
595 std.fs.cwd().deleteTree(eval.tmp_dir_path) catch |err| {603 Dir.cwd().deleteTree(io, eval.tmp_dir_path) catch |err| {
596 std.log.warn("failed to delete tree '{s}': {s}", .{ eval.tmp_dir_path, @errorName(err) });604 std.log.warn("failed to delete tree '{s}': {t}", .{ eval.tmp_dir_path, err });
597 };605 };
598 }606 }
599 std.process.fatal(fmt, args);607 std.process.fatal(fmt, args);
...@@ -759,7 +767,7 @@ const Case = struct {...@@ -759,7 +767,7 @@ const Case = struct {
759 if (last_update.outcome != .unknown) fatal("line {d}: conflicting expect directive", .{line_n});767 if (last_update.outcome != .unknown) fatal("line {d}: conflicting expect directive", .{line_n});
760 last_update.outcome = .{768 last_update.outcome = .{
761 .stdout = std.zig.string_literal.parseAlloc(arena, val) catch |err| {769 .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 });
763 },771 },
764 };772 };
765 } else if (std.mem.eql(u8, key, "expect_error")) {773 } else if (std.mem.eql(u8, key, "expect_error")) {
...@@ -833,27 +841,29 @@ const Case = struct {...@@ -833,27 +841,29 @@ const Case = struct {
833841
834fn requestExit(child: *std.process.Child, eval: *Eval) void {842fn requestExit(child: *std.process.Child, eval: *Eval) void {
835 if (child.stdin == null) return;843 if (child.stdin == null) return;
844 const io = eval.io;
836845
837 const header: std.zig.Client.Message.Header = .{846 const header: std.zig.Client.Message.Header = .{
838 .tag = .exit,847 .tag = .exit,
839 .bytes_len = 0,848 .bytes_len = 0,
840 };849 };
841 var w = eval.child.stdin.?.writer(&.{});850 var w = eval.child.stdin.?.writer(io, &.{});
842 w.interface.writeStruct(header, .little) catch |err| switch (err) {851 w.interface.writeStruct(header, .little) catch |err| switch (err) {
843 error.WriteFailed => switch (w.err.?) {852 error.WriteFailed => switch (w.err.?) {
844 error.BrokenPipe => {},853 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}),
846 },855 },
847 };856 };
848857
849 // Send EOF to stdin.858 // Send EOF to stdin.
850 child.stdin.?.close();859 child.stdin.?.close(io);
851 child.stdin = null;860 child.stdin = null;
852}861}
853862
854fn waitChild(child: *std.process.Child, eval: *Eval) void {863fn waitChild(child: *std.process.Child, eval: *Eval) void {
864 const io = eval.io;
855 requestExit(child, eval);865 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});
857 switch (term) {867 switch (term) {
858 .Exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),868 .Exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),
859 .Signal, .Stopped, .Unknown => eval.fatal("compiler terminated unexpectedly", .{}),869 .Signal, .Stopped, .Unknown => eval.fatal("compiler terminated unexpectedly", .{}),
tools/migrate_langref.zig+14-11
...@@ -1,13 +1,16 @@...@@ -1,13 +1,16 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const fs = std.fs;2
3const std = @import("std");
4const Io = std.Io;
5const Dir = std.Io.Dir;
4const print = std.debug.print;6const print = std.debug.print;
5const mem = std.mem;7const mem = std.mem;
6const testing = std.testing;8const testing = std.testing;
7const Allocator = std.mem.Allocator;9const Allocator = std.mem.Allocator;
8const max_doc_file_size = 10 * 1024 * 1024;
9const fatal = std.process.fatal;10const fatal = std.process.fatal;
1011
12const max_doc_file_size = 10 * 1024 * 1024;
13
11pub fn main() !void {14pub fn main() !void {
12 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);15 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
13 defer arena_instance.deinit();16 defer arena_instance.deinit();
...@@ -23,16 +26,16 @@ pub fn main() !void {...@@ -23,16 +26,16 @@ pub fn main() !void {
23 defer threaded.deinit();26 defer threaded.deinit();
24 const io = threaded.io();27 const io = threaded.io();
2528
26 var in_file = try fs.cwd().openFile(input_file, .{ .mode = .read_only });29 var in_file = try Dir.cwd().openFile(input_file, .{ .mode = .read_only });
27 defer in_file.close();30 defer in_file.close(io);
2831
29 var out_file = try fs.cwd().createFile(output_file, .{});32 var out_file = try Dir.cwd().createFile(output_file, .{});
30 defer out_file.close();33 defer out_file.close(io);
31 var out_file_buffer: [4096]u8 = undefined;34 var out_file_buffer: [4096]u8 = undefined;
32 var out_file_writer = out_file.writer(&out_file_buffer);35 var out_file_writer = out_file.writer(&out_file_buffer);
3336
34 var out_dir = try fs.cwd().openDir(fs.path.dirname(output_file).?, .{});37 var out_dir = try Dir.cwd().openDir(Dir.path.dirname(output_file).?, .{});
35 defer out_dir.close();38 defer out_dir.close(io);
3639
37 var in_file_reader = in_file.reader(io, &.{});40 var in_file_reader = in_file.reader(io, &.{});
38 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .unlimited);41 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .unlimited);
...@@ -266,7 +269,7 @@ const Code = struct {...@@ -266,7 +269,7 @@ const Code = struct {
266 };269 };
267};270};
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 {
270 while (true) {273 while (true) {
271 const token = tokenizer.next();274 const token = tokenizer.next();
272 switch (token.id) {275 switch (token.id) {
...@@ -387,7 +390,7 @@ fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype...@@ -387,7 +390,7 @@ fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype
387 var file = out_dir.createFile(basename, .{ .exclusive = true }) catch |err| {390 var file = out_dir.createFile(basename, .{ .exclusive = true }) catch |err| {
388 fatal("unable to create file '{s}': {s}", .{ name, @errorName(err) });391 fatal("unable to create file '{s}': {s}", .{ name, @errorName(err) });
389 };392 };
390 defer file.close();393 defer file.close(io);
391 var file_buffer: [1024]u8 = undefined;394 var file_buffer: [1024]u8 = undefined;
392 var file_writer = file.writer(&file_buffer);395 var file_writer = file.writer(&file_buffer);
393 const code = &file_writer.interface;396 const code = &file_writer.interface;
tools/process_headers.zig+20-13
...@@ -12,6 +12,8 @@...@@ -12,6 +12,8 @@
12//! You'll then have to manually update Zig source repo with these new files.12//! You'll then have to manually update Zig source repo with these new files.
1313
14const std = @import("std");14const std = @import("std");
15const Io = std.Io;
16const Dir = std.Io.Dir;
15const Arch = std.Target.Cpu.Arch;17const Arch = std.Target.Cpu.Arch;
16const Abi = std.Target.Abi;18const Abi = std.Target.Abi;
17const OsTag = std.Target.Os.Tag;19const OsTag = std.Target.Os.Tag;
...@@ -128,6 +130,11 @@ const LibCVendor = enum {...@@ -128,6 +130,11 @@ const LibCVendor = enum {
128pub fn main() !void {130pub fn main() !void {
129 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);131 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
130 const allocator = arena.allocator();132 const allocator = arena.allocator();
133
134 var threaded: Io.Threaded = .init(allocator);
135 defer threaded.deinit();
136 const io = threaded.io();
137
131 const args = try std.process.argsAlloc(allocator);138 const args = try std.process.argsAlloc(allocator);
132 var search_paths = std.array_list.Managed([]const u8).init(allocator);139 var search_paths = std.array_list.Managed([]const u8).init(allocator);
133 var opt_out_dir: ?[]const u8 = null;140 var opt_out_dir: ?[]const u8 = null;
...@@ -232,28 +239,28 @@ pub fn main() !void {...@@ -232,28 +239,28 @@ pub fn main() !void {
232 => &[_][]const u8{ search_path, libc_dir, "usr", "include" },239 => &[_][]const u8{ search_path, libc_dir, "usr", "include" },
233 .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" },240 .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" },
234 };241 };
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);
236 var dir_stack = std.array_list.Managed([]const u8).init(allocator);243 var dir_stack = std.array_list.Managed([]const u8).init(allocator);
237 try dir_stack.append(target_include_dir);244 try dir_stack.append(target_include_dir);
238245
239 while (dir_stack.pop()) |full_dir_name| {246 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) {
241 error.FileNotFound => continue :search,248 error.FileNotFound => continue :search,
242 error.AccessDenied => continue :search,249 error.AccessDenied => continue :search,
243 else => return err,250 else => return err,
244 };251 };
245 defer dir.close();252 defer dir.close(io);
246253
247 var dir_it = dir.iterate();254 var dir_it = dir.iterate();
248255
249 while (try dir_it.next()) |entry| {256 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 });
251 switch (entry.kind) {258 switch (entry.kind) {
252 .directory => try dir_stack.append(full_path),259 .directory => try dir_stack.append(full_path),
253 .file, .sym_link => {260 .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);
255 const max_size = 2 * 1024 * 1024 * 1024;262 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));
257 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");264 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
258 total_bytes += raw_bytes.len;265 total_bytes += raw_bytes.len;
259 const hash = try allocator.alloc(u8, 32);266 const hash = try allocator.alloc(u8, 32);
...@@ -314,7 +321,7 @@ pub fn main() !void {...@@ -314,7 +321,7 @@ pub fn main() !void {
314 total_bytes,321 total_bytes,
315 total_bytes - max_bytes_saved,322 total_bytes - max_bytes_saved,
316 });323 });
317 try std.fs.cwd().makePath(out_dir);324 try Dir.cwd().createDirPath(io, out_dir);
318325
319 var missed_opportunity_bytes: usize = 0;326 var missed_opportunity_bytes: usize = 0;
320 // iterate path_table. for each path, put all the hashes into a list. sort by hit_count.327 // 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 {...@@ -334,9 +341,9 @@ pub fn main() !void {
334 const best_contents = contents_list.pop().?;341 const best_contents = contents_list.pop().?;
335 if (best_contents.hit_count > 1) {342 if (best_contents.hit_count > 1) {
336 // worth it to make it generic343 // 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.* });344 const full_path = try Dir.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).?);345 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
339 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });346 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes });
340 best_contents.is_generic = true;347 best_contents.is_generic = true;
341 while (contents_list.pop()) |contender| {348 while (contents_list.pop()) |contender| {
342 if (contender.hit_count > 1) {349 if (contender.hit_count > 1) {
...@@ -355,9 +362,9 @@ pub fn main() !void {...@@ -355,9 +362,9 @@ pub fn main() !void {
355 if (contents.is_generic) continue;362 if (contents.is_generic) continue;
356363
357 const dest_target = hash_kv.key_ptr.*;364 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.* });365 const full_path = try Dir.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).?);366 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
360 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });367 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes });
361 }368 }
362 }369 }
363}370}
tools/update-linux-headers.zig+22-15
...@@ -15,6 +15,8 @@...@@ -15,6 +15,8 @@
15//! You'll then have to manually update Zig source repo with these new files.15//! You'll then have to manually update Zig source repo with these new files.
1616
17const std = @import("std");17const std = @import("std");
18const Io = std.Io;
19const Dir = std.Io.Dir;
18const Arch = std.Target.Cpu.Arch;20const Arch = std.Target.Cpu.Arch;
19const Abi = std.Target.Abi;21const Abi = std.Target.Abi;
20const assert = std.debug.assert;22const assert = std.debug.assert;
...@@ -142,6 +144,11 @@ const PathTable = std.StringHashMap(*TargetToHash);...@@ -142,6 +144,11 @@ const PathTable = std.StringHashMap(*TargetToHash);
142pub fn main() !void {144pub fn main() !void {
143 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);145 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
144 const arena = arena_state.allocator();146 const arena = arena_state.allocator();
147
148 var threaded: Io.Threaded = .init(arena);
149 defer threaded.deinit();
150 const io = threaded.io();
151
145 const args = try std.process.argsAlloc(arena);152 const args = try std.process.argsAlloc(arena);
146 var search_paths = std.array_list.Managed([]const u8).init(arena);153 var search_paths = std.array_list.Managed([]const u8).init(arena);
147 var opt_out_dir: ?[]const u8 = null;154 var opt_out_dir: ?[]const u8 = null;
...@@ -183,30 +190,30 @@ pub fn main() !void {...@@ -183,30 +190,30 @@ pub fn main() !void {
183 .arch = linux_target.arch,190 .arch = linux_target.arch,
184 };191 };
185 search: for (search_paths.items) |search_path| {192 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, &.{
187 search_path, linux_target.name, "include",194 search_path, linux_target.name, "include",
188 });195 });
189 var dir_stack = std.array_list.Managed([]const u8).init(arena);196 var dir_stack = std.array_list.Managed([]const u8).init(arena);
190 try dir_stack.append(target_include_dir);197 try dir_stack.append(target_include_dir);
191198
192 while (dir_stack.pop()) |full_dir_name| {199 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) {
194 error.FileNotFound => continue :search,201 error.FileNotFound => continue :search,
195 error.AccessDenied => continue :search,202 error.AccessDenied => continue :search,
196 else => return err,203 else => return err,
197 };204 };
198 defer dir.close();205 defer dir.close(io);
199206
200 var dir_it = dir.iterate();207 var dir_it = dir.iterate();
201208
202 while (try dir_it.next()) |entry| {209 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 });
204 switch (entry.kind) {211 switch (entry.kind) {
205 .directory => try dir_stack.append(full_path),212 .directory => try dir_stack.append(full_path),
206 .file => {213 .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);
208 const max_size = 2 * 1024 * 1024 * 1024;215 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));
210 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");217 const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
211 total_bytes += raw_bytes.len;218 total_bytes += raw_bytes.len;
212 const hash = try arena.alloc(u8, 32);219 const hash = try arena.alloc(u8, 32);
...@@ -253,7 +260,7 @@ pub fn main() !void {...@@ -253,7 +260,7 @@ pub fn main() !void {
253 total_bytes,260 total_bytes,
254 total_bytes - max_bytes_saved,261 total_bytes - max_bytes_saved,
255 });262 });
256 try std.fs.cwd().makePath(out_dir);263 try Dir.cwd().createDirPath(io, out_dir);
257264
258 var missed_opportunity_bytes: usize = 0;265 var missed_opportunity_bytes: usize = 0;
259 // iterate path_table. for each path, put all the hashes into a list. sort by hit_count.266 // 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 {...@@ -273,9 +280,9 @@ pub fn main() !void {
273 const best_contents = contents_list.pop().?;280 const best_contents = contents_list.pop().?;
274 if (best_contents.hit_count > 1) {281 if (best_contents.hit_count > 1) {
275 // worth it to make it generic282 // 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.* });283 const full_path = try Dir.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).?);284 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
278 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });285 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes });
279 best_contents.is_generic = true;286 best_contents.is_generic = true;
280 while (contents_list.pop()) |contender| {287 while (contents_list.pop()) |contender| {
281 if (contender.hit_count > 1) {288 if (contender.hit_count > 1) {
...@@ -299,9 +306,9 @@ pub fn main() !void {...@@ -299,9 +306,9 @@ pub fn main() !void {
299 else => @tagName(dest_target.arch),306 else => @tagName(dest_target.arch),
300 };307 };
301 const out_subpath = try std.fmt.allocPrint(arena, "{s}-linux-any", .{arch_name});308 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.* });309 const full_path = try Dir.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).?);310 try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?);
304 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes });311 try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes });
305 }312 }
306 }313 }
307314
...@@ -316,8 +323,8 @@ pub fn main() !void {...@@ -316,8 +323,8 @@ pub fn main() !void {
316 "any-linux-any/linux/netfilter_ipv6/ip6t_HL.h",323 "any-linux-any/linux/netfilter_ipv6/ip6t_HL.h",
317 };324 };
318 for (bad_files) |bad_file| {325 for (bad_files) |bad_file| {
319 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, bad_file });326 const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, bad_file });
320 try std.fs.cwd().deleteFile(full_path);327 try Dir.cwd().deleteFile(io, full_path);
321 }328 }
322}329}
323330
tools/update_cpu_features.zig+16-14
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const fs = std.fs;2
3const std = @import("std");
4const Io = std.Io;
5const Dir = std.Io.Dir;
4const mem = std.mem;6const mem = std.mem;
5const json = std.json;7const json = std.json;
6const assert = std.debug.assert;8const assert = std.debug.assert;
...@@ -1927,26 +1929,26 @@ pub fn main() anyerror!void {...@@ -1927,26 +1929,26 @@ pub fn main() anyerror!void {
1927 // there shouldn't be any more argument after the optional filter1929 // there shouldn't be any more argument after the optional filter
1928 if (args.skip()) usageAndExit(args0, 1);1930 if (args.skip()) usageAndExit(args0, 1);
19291931
1930 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});1932 var zig_src_dir = try Dir.cwd().openDir(io, zig_src_root, .{});
1931 defer zig_src_dir.close();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 });
1934 defer root_progress.end();1936 defer root_progress.end();
19351937
1936 var group: std.Io.Group = .init;1938 var group: Io.Group = .init;
1937 defer group.cancel(io);1939 defer group.cancel(io);
19381940
1939 for (targets) |target| {1941 for (targets) |target| {
1940 if (filter) |zig_name| {1942 if (filter) |zig_name| {
1941 if (!std.mem.eql(u8, target.zig_name, zig_name)) continue;1943 if (!std.mem.eql(u8, target.zig_name, zig_name)) continue;
1942 }1944 }
1943 group.async(io, processOneTarget, .{.{1945 group.async(io, processOneTarget, .{ io, .{
1944 .llvm_tblgen_exe = llvm_tblgen_exe,1946 .llvm_tblgen_exe = llvm_tblgen_exe,
1945 .llvm_src_root = llvm_src_root,1947 .llvm_src_root = llvm_src_root,
1946 .zig_src_dir = zig_src_dir,1948 .zig_src_dir = zig_src_dir,
1947 .root_progress = root_progress,1949 .root_progress = root_progress,
1948 .target = target,1950 .target = target,
1949 }});1951 } });
1950 }1952 }
19511953
1952 group.wait(io);1954 group.wait(io);
...@@ -1955,12 +1957,12 @@ pub fn main() anyerror!void {...@@ -1955,12 +1957,12 @@ pub fn main() anyerror!void {
1955const Job = struct {1957const Job = struct {
1956 llvm_tblgen_exe: []const u8,1958 llvm_tblgen_exe: []const u8,
1957 llvm_src_root: []const u8,1959 llvm_src_root: []const u8,
1958 zig_src_dir: std.fs.Dir,1960 zig_src_dir: Dir,
1959 root_progress: std.Progress.Node,1961 root_progress: std.Progress.Node,
1960 target: ArchTarget,1962 target: ArchTarget,
1961};1963};
19621964
1963fn processOneTarget(job: Job) void {1965fn processOneTarget(io: Io, job: Job) void {
1964 errdefer |err| std.debug.panic("panic: {s}", .{@errorName(err)});1966 errdefer |err| std.debug.panic("panic: {s}", .{@errorName(err)});
1965 const target = job.target;1967 const target = job.target;
19661968
...@@ -2240,12 +2242,12 @@ fn processOneTarget(job: Job) void {...@@ -2240,12 +2242,12 @@ fn processOneTarget(job: Job) void {
22402242
2241 const render_progress = progress_node.start("rendering Zig code", 0);2243 const render_progress = progress_node.start("rendering Zig code", 0);
22422244
2243 var target_dir = try job.zig_src_dir.openDir("lib/std/Target", .{});2245 var target_dir = try job.zig_src_dir.openDir(io, "lib/std/Target", .{});
2244 defer target_dir.close();2246 defer target_dir.close(io);
22452247
2246 const zig_code_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{target.zig_name});2248 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, .{});2249 var zig_code_file = try target_dir.createFile(io, zig_code_basename, .{});
2248 defer zig_code_file.close();2250 defer zig_code_file.close(io);
22492251
2250 var zig_code_file_buffer: [4096]u8 = undefined;2252 var zig_code_file_buffer: [4096]u8 = undefined;
2251 var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer);2253 var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer);
tools/update_crc_catalog.zig+18-13
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const fs = std.fs;2const Io = std.Io;
3const Dir = std.Io.Dir;
3const mem = std.mem;4const mem = std.mem;
4const ascii = std.ascii;5const ascii = std.ascii;
56
...@@ -10,25 +11,29 @@ pub fn main() anyerror!void {...@@ -10,25 +11,29 @@ pub fn main() anyerror!void {
10 defer arena_state.deinit();11 defer arena_state.deinit();
11 const arena = arena_state.allocator();12 const arena = arena_state.allocator();
1213
14 var threaded: Io.Threaded = .init(arena);
15 defer threaded.deinit();
16 const io = threaded.io();
17
13 const args = try std.process.argsAlloc(arena);18 const args = try std.process.argsAlloc(arena);
14 if (args.len <= 1) printUsageAndExit(args[0]);19 if (args.len <= 1) printUsageAndExit(args[0]);
1520
16 const zig_src_root = args[1];21 const zig_src_root = args[1];
17 if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]);22 if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]);
1823
19 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});24 var zig_src_dir = try Dir.cwd().openDir(io, zig_src_root, .{});
20 defer zig_src_dir.close();25 defer zig_src_dir.close(io);
2126
22 const hash_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash" });27 const hash_sub_path = try Dir.path.join(arena, &.{ "lib", "std", "hash" });
23 var hash_target_dir = try zig_src_dir.makeOpenPath(hash_sub_path, .{});28 var hash_target_dir = try zig_src_dir.createDirPathOpen(io, hash_sub_path, .{});
24 defer hash_target_dir.close();29 defer hash_target_dir.close(io);
2530
26 const crc_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" });31 const crc_sub_path = try Dir.path.join(arena, &.{ "lib", "std", "hash", "crc" });
27 var crc_target_dir = try zig_src_dir.makeOpenPath(crc_sub_path, .{});32 var crc_target_dir = try zig_src_dir.createDirPathOpen(io, crc_sub_path, .{});
28 defer crc_target_dir.close();33 defer crc_target_dir.close(io);
2934
30 var zig_code_file = try hash_target_dir.createFile("crc.zig", .{});35 var zig_code_file = try hash_target_dir.createFile(io, "crc.zig", .{});
31 defer zig_code_file.close();36 defer zig_code_file.close(io);
32 var zig_code_file_buffer: [4096]u8 = undefined;37 var zig_code_file_buffer: [4096]u8 = undefined;
33 var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer);38 var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer);
34 const code_writer = &zig_code_file_writer.interface;39 const code_writer = &zig_code_file_writer.interface;
...@@ -51,8 +56,8 @@ pub fn main() anyerror!void {...@@ -51,8 +56,8 @@ pub fn main() anyerror!void {
51 \\56 \\
52 );57 );
5358
54 var zig_test_file = try crc_target_dir.createFile("test.zig", .{});59 var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{});
55 defer zig_test_file.close();60 defer zig_test_file.close(io);
56 var zig_test_file_buffer: [4096]u8 = undefined;61 var zig_test_file_buffer: [4096]u8 = undefined;
57 var zig_test_file_writer = zig_test_file.writer(&zig_test_file_buffer);62 var zig_test_file_writer = zig_test_file.writer(&zig_test_file_buffer);
58 const test_writer = &zig_test_file_writer.interface;63 const test_writer = &zig_test_file_writer.interface;
tools/update_freebsd_libc.zig+10-7
...@@ -5,6 +5,7 @@...@@ -5,6 +5,7 @@
5//! `zig run tools/update_freebsd_libc.zig -- ~/Downloads/freebsd-src .`5//! `zig run tools/update_freebsd_libc.zig -- ~/Downloads/freebsd-src .`
66
7const std = @import("std");7const std = @import("std");
8const Io = std.Io;
89
9const exempt_files = [_][]const u8{10const exempt_files = [_][]const u8{
10 // This file is maintained by a separate project and does not come from FreeBSD.11 // This file is maintained by a separate project and does not come from FreeBSD.
...@@ -16,22 +17,24 @@ pub fn main() !void {...@@ -16,22 +17,24 @@ pub fn main() !void {
16 defer arena_instance.deinit();17 defer arena_instance.deinit();
17 const arena = arena_instance.allocator();18 const arena = arena_instance.allocator();
1819
20 var threaded: Io.Threaded = .init(arena);
21 defer threaded.deinit();
22 const io = threaded.io();
23
19 const args = try std.process.argsAlloc(arena);24 const args = try std.process.argsAlloc(arena);
20 const freebsd_src_path = args[1];25 const freebsd_src_path = args[1];
21 const zig_src_path = args[2];26 const zig_src_path = args[2];
2227
23 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/freebsd", .{zig_src_path});28 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| {30 var dest_dir = std.fs.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
26 std.log.err("unable to open destination directory '{s}': {s}", .{31 std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
27 dest_dir_path, @errorName(err),
28 });
29 std.process.exit(1);32 std.process.exit(1);
30 };33 };
31 defer dest_dir.close();34 defer dest_dir.close(io);
3235
33 var freebsd_src_dir = try std.fs.cwd().openDir(freebsd_src_path, .{});36 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
36 // Copy updated files from upstream.39 // Copy updated files from upstream.
37 {40 {
...@@ -57,7 +60,7 @@ pub fn main() !void {...@@ -57,7 +60,7 @@ pub fn main() !void {
57 @errorName(err),60 @errorName(err),
58 });61 });
59 if (err == error.FileNotFound) {62 if (err == error.FileNotFound) {
60 try dest_dir.deleteFile(entry.path);63 try dest_dir.deleteFile(io, entry.path);
61 }64 }
62 };65 };
63 }66 }
tools/update_glibc.zig+20-25
...@@ -7,9 +7,11 @@...@@ -7,9 +7,11 @@
7//! `zig run ../tools/update_glibc.zig -- ~/Downloads/glibc ..`7//! `zig run ../tools/update_glibc.zig -- ~/Downloads/glibc ..`
88
9const std = @import("std");9const std = @import("std");
10const Io = std.Io;
11const Dir = std.Io.Dir;
10const mem = std.mem;12const mem = std.mem;
11const log = std.log;13const log = std.log;
12const fs = std.fs;14const fatal = std.process.fatal;
1315
14const exempt_files = [_][]const u8{16const exempt_files = [_][]const u8{
15 // This file is maintained by a separate project and does not come from glibc.17 // This file is maintained by a separate project and does not come from glibc.
...@@ -41,21 +43,23 @@ pub fn main() !void {...@@ -41,21 +43,23 @@ pub fn main() !void {
41 defer arena_instance.deinit();43 defer arena_instance.deinit();
42 const arena = arena_instance.allocator();44 const arena = arena_instance.allocator();
4345
46 var threaded: Io.Threaded = .init(arena);
47 defer threaded.deinit();
48 const io = threaded.io();
49
44 const args = try std.process.argsAlloc(arena);50 const args = try std.process.argsAlloc(arena);
45 const glibc_src_path = args[1];51 const glibc_src_path = args[1];
46 const zig_src_path = args[2];52 const zig_src_path = args[2];
4753
48 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/glibc", .{zig_src_path});54 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| {56 var dest_dir = Dir.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
51 fatal("unable to open destination directory '{s}': {s}", .{57 fatal("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
52 dest_dir_path, @errorName(err),
53 });
54 };58 };
55 defer dest_dir.close();59 defer dest_dir.close(io);
5660
57 var glibc_src_dir = try fs.cwd().openDir(glibc_src_path, .{});61 var glibc_src_dir = try Dir.cwd().openDir(io, glibc_src_path, .{});
58 defer glibc_src_dir.close();62 defer glibc_src_dir.close(io);
5963
60 // Copy updated files from upstream.64 // Copy updated files from upstream.
61 {65 {
...@@ -73,13 +77,11 @@ pub fn main() !void {...@@ -73,13 +77,11 @@ pub fn main() !void {
73 }77 }
7478
75 glibc_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {79 glibc_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {
76 log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{80 log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{
77 glibc_src_path, entry.path,81 glibc_src_path, entry.path, dest_dir_path, entry.path, err,
78 dest_dir_path, entry.path,
79 @errorName(err),
80 });82 });
81 if (err == error.FileNotFound) {83 if (err == error.FileNotFound) {
82 try dest_dir.deleteFile(entry.path);84 try dest_dir.deleteFile(io, entry.path);
83 }85 }
84 };86 };
85 }87 }
...@@ -88,20 +90,18 @@ pub fn main() !void {...@@ -88,20 +90,18 @@ pub fn main() !void {
88 // Warn about duplicated files inside glibc/include/* that can be omitted90 // Warn about duplicated files inside glibc/include/* that can be omitted
89 // because they are already in generic-glibc/*.91 // because they are already in generic-glibc/*.
9092
91 var include_dir = dest_dir.openDir("include", .{ .iterate = true }) catch |err| {93 var include_dir = dest_dir.openDir(io, "include", .{ .iterate = true }) catch |err| {
92 fatal("unable to open directory '{s}/include': {s}", .{94 fatal("unable to open directory '{s}/include': {t}", .{ dest_dir_path, err });
93 dest_dir_path, @errorName(err),
94 });
95 };95 };
96 defer include_dir.close();96 defer include_dir.close(io);
9797
98 const generic_glibc_path = try std.fmt.allocPrint(98 const generic_glibc_path = try std.fmt.allocPrint(
99 arena,99 arena,
100 "{s}/lib/libc/include/generic-glibc",100 "{s}/lib/libc/include/generic-glibc",
101 .{zig_src_path},101 .{zig_src_path},
102 );102 );
103 var generic_glibc_dir = try fs.cwd().openDir(generic_glibc_path, .{});103 var generic_glibc_dir = try Dir.cwd().openDir(io, generic_glibc_path, .{});
104 defer generic_glibc_dir.close();104 defer generic_glibc_dir.close(io);
105105
106 var walker = try include_dir.walk(arena);106 var walker = try include_dir.walk(arena);
107 defer walker.deinit();107 defer walker.deinit();
...@@ -146,8 +146,3 @@ pub fn main() !void {...@@ -146,8 +146,3 @@ pub fn main() !void {
146 }146 }
147 }147 }
148}148}
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 @@...@@ -1,35 +1,41 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
3const Dir = std.Io.Dir;
24
3pub fn main() !void {5pub fn main() !void {
4 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);6 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
5 defer arena_instance.deinit();7 defer arena_instance.deinit();
6 const arena = arena_instance.allocator();8 const arena = arena_instance.allocator();
79
10 var threaded: Io.Threaded = .init(arena);
11 defer threaded.deinit();
12 const io = threaded.io();
13
8 const args = try std.process.argsAlloc(arena);14 const args = try std.process.argsAlloc(arena);
9 const zig_src_lib_path = args[1];15 const zig_src_lib_path = args[1];
10 const mingw_src_path = args[2];16 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, &.{
13 zig_src_lib_path, "libc", "mingw",19 zig_src_lib_path, "libc", "mingw",
14 });20 });
15 const src_mingw_crt_path = try std.fs.path.join(arena, &.{21 const src_mingw_crt_path = try Dir.path.join(arena, &.{
16 mingw_src_path, "mingw-w64-crt",22 mingw_src_path, "mingw-w64-crt",
17 });23 });
1824
19 // Update only the set of existing files we have already chosen to include25 // Update only the set of existing files we have already chosen to include
20 // in zig's installation.26 // 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| {
23 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_crt_path, @errorName(err) });29 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_crt_path, @errorName(err) });
24 std.process.exit(1);30 std.process.exit(1);
25 };31 };
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| {
29 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_crt_path, @errorName(err) });35 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_crt_path, @errorName(err) });
30 std.process.exit(1);36 std.process.exit(1);
31 };37 };
32 defer src_crt_dir.close();38 defer src_crt_dir.close(io);
3339
34 {40 {
35 var walker = try dest_crt_dir.walk(arena);41 var walker = try dest_crt_dir.walk(arena);
...@@ -49,11 +55,11 @@ pub fn main() !void {...@@ -49,11 +55,11 @@ pub fn main() !void {
4955
50 if (!keep) {56 if (!keep) {
51 std.log.warn("deleting {s}", .{entry.path});57 std.log.warn("deleting {s}", .{entry.path});
52 try dest_crt_dir.deleteFile(entry.path);58 try dest_crt_dir.deleteFile(io, entry.path);
53 }59 }
54 },60 },
55 else => {61 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 });
57 fail = true;63 fail = true;
58 },64 },
59 };65 };
...@@ -63,24 +69,24 @@ pub fn main() !void {...@@ -63,24 +69,24 @@ pub fn main() !void {
63 }69 }
6470
65 {71 {
66 const dest_mingw_winpthreads_path = try std.fs.path.join(arena, &.{72 const dest_mingw_winpthreads_path = try Dir.path.join(arena, &.{
67 zig_src_lib_path, "libc", "mingw", "winpthreads",73 zig_src_lib_path, "libc", "mingw", "winpthreads",
68 });74 });
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, &.{
70 mingw_src_path, "mingw-w64-libraries", "winpthreads", "src",76 mingw_src_path, "mingw-w64-libraries", "winpthreads", "src",
71 });77 });
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| {
74 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_winpthreads_path, @errorName(err) });80 std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_winpthreads_path, @errorName(err) });
75 std.process.exit(1);81 std.process.exit(1);
76 };82 };
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| {
80 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_libraries_winpthreads_src_path, @errorName(err) });86 std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_libraries_winpthreads_src_path, @errorName(err) });
81 std.process.exit(1);87 std.process.exit(1);
82 };88 };
83 defer src_winpthreads_dir.close();89 defer src_winpthreads_dir.close(io);
8490
85 {91 {
86 var walker = try dest_winpthreads_dir.walk(arena);92 var walker = try dest_winpthreads_dir.walk(arena);
...@@ -94,10 +100,10 @@ pub fn main() !void {...@@ -94,10 +100,10 @@ pub fn main() !void {
94 src_winpthreads_dir.copyFile(entry.path, dest_winpthreads_dir, entry.path, .{}) catch |err| switch (err) {100 src_winpthreads_dir.copyFile(entry.path, dest_winpthreads_dir, entry.path, .{}) catch |err| switch (err) {
95 error.FileNotFound => {101 error.FileNotFound => {
96 std.log.warn("deleting {s}", .{entry.path});102 std.log.warn("deleting {s}", .{entry.path});
97 try dest_winpthreads_dir.deleteFile(entry.path);103 try dest_winpthreads_dir.deleteFile(io, entry.path);
98 },104 },
99 else => {105 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 });
101 fail = true;107 fail = true;
102 },108 },
103 };109 };
...@@ -164,7 +170,7 @@ pub fn main() !void {...@@ -164,7 +170,7 @@ pub fn main() !void {
164170
165const kept_crt_files = [_][]const u8{171const kept_crt_files = [_][]const u8{
166 "COPYING",172 "COPYING",
167 "include" ++ std.fs.path.sep_str ++ "config.h",173 "include" ++ Dir.path.sep_str ++ "config.h",
168};174};
169175
170const def_exts = [_][]const u8{176const def_exts = [_][]const u8{
tools/update_netbsd_libc.zig+13-12
...@@ -5,6 +5,7 @@...@@ -5,6 +5,7 @@
5//! `zig run tools/update_netbsd_libc.zig -- ~/Downloads/netbsd-src .`5//! `zig run tools/update_netbsd_libc.zig -- ~/Downloads/netbsd-src .`
66
7const std = @import("std");7const std = @import("std");
8const Io = std.Io;
89
9const exempt_files = [_][]const u8{10const exempt_files = [_][]const u8{
10 // This file is maintained by a separate project and does not come from NetBSD.11 // This file is maintained by a separate project and does not come from NetBSD.
...@@ -16,22 +17,24 @@ pub fn main() !void {...@@ -16,22 +17,24 @@ pub fn main() !void {
16 defer arena_instance.deinit();17 defer arena_instance.deinit();
17 const arena = arena_instance.allocator();18 const arena = arena_instance.allocator();
1819
20 var threaded: Io.Threaded = .init(arena);
21 defer threaded.deinit();
22 const io = threaded.io();
23
19 const args = try std.process.argsAlloc(arena);24 const args = try std.process.argsAlloc(arena);
20 const netbsd_src_path = args[1];25 const netbsd_src_path = args[1];
21 const zig_src_path = args[2];26 const zig_src_path = args[2];
2227
23 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/netbsd", .{zig_src_path});28 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| {30 var dest_dir = std.fs.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
26 std.log.err("unable to open destination directory '{s}': {s}", .{31 std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
27 dest_dir_path, @errorName(err),
28 });
29 std.process.exit(1);32 std.process.exit(1);
30 };33 };
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, .{});36 var netbsd_src_dir = try std.fs.cwd().openDir(io, netbsd_src_path, .{});
34 defer netbsd_src_dir.close();37 defer netbsd_src_dir.close(io);
3538
36 // Copy updated files from upstream.39 // Copy updated files from upstream.
37 {40 {
...@@ -51,13 +54,11 @@ pub fn main() !void {...@@ -51,13 +54,11 @@ pub fn main() !void {
51 });54 });
5255
53 netbsd_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {56 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}", .{57 std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{
55 netbsd_src_path, entry.path,58 netbsd_src_path, entry.path, dest_dir_path, entry.path, err,
56 dest_dir_path, entry.path,
57 @errorName(err),
58 });59 });
59 if (err == error.FileNotFound) {60 if (err == error.FileNotFound) {
60 try dest_dir.deleteFile(entry.path);61 try dest_dir.deleteFile(io, entry.path);
61 }62 }
62 };63 };
63 }64 }