authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-08 17:14:31-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:08-08:00
log950d18ef695bb7a28397e080dc3c201559ec4ee2
tree253209139275932ed503a5ea4529594ab70df8cc
parent314c906dba32e72317947a15254519b22745b13f

update all access() to access(io)


33 files changed, 159 insertions(+), 197 deletions(-)

lib/compiler/aro/aro/Driver.zig+3-3
......@@ -1333,7 +1333,7 @@ fn processSource(
13331333 Io.File.stdout();
13341334 defer if (dep_file_name != null) file.close(io);
13351335
1336 var file_writer = file.writer(&writer_buf);
1336 var file_writer = file.writer(io, &writer_buf);
13371337 dep_file.write(&file_writer.interface) catch
13381338 return d.fatal("unable to write dependency file: {s}", .{errorDescription(file_writer.err.?)});
13391339 }
......@@ -1358,7 +1358,7 @@ fn processSource(
13581358 Io.File.stdout();
13591359 defer if (d.output_name != null) file.close(io);
13601360
1361 var file_writer = file.writer(&writer_buf);
1361 var file_writer = file.writer(io, &writer_buf);
13621362 pp.prettyPrintTokens(&file_writer.interface, dump_mode) catch
13631363 return d.fatal("unable to write result: {s}", .{errorDescription(file_writer.err.?)});
13641364
......@@ -1459,7 +1459,7 @@ fn processSource(
14591459 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
14601460 defer out_file.close(io);
14611461
1462 var file_writer = out_file.writer(&writer_buf);
1462 var file_writer = out_file.writer(io, &writer_buf);
14631463 obj.finish(&file_writer.interface) catch
14641464 return d.fatal("could not output to object file '{s}': {s}", .{ out_file_name, errorDescription(file_writer.err.?) });
14651465 }
lib/compiler/aro/aro/Driver/Filesystem.zig+4-4
......@@ -57,8 +57,8 @@ fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool {
5757 return false;
5858}
5959
60fn canExecutePosix(path: []const u8) bool {
61 std.posix.access(path, std.posix.X_OK) catch return false;
60fn canExecutePosix(io: Io, path: []const u8) bool {
61 Io.Dir.accessAbsolute(io, path, .{ .execute = true }) catch return false;
6262 // Todo: ensure path is not a directory
6363 return true;
6464}
......@@ -172,10 +172,10 @@ pub const Filesystem = union(enum) {
172172 }
173173 };
174174
175 pub fn exists(fs: Filesystem, path: []const u8) bool {
175 pub fn exists(fs: Filesystem, io: Io, path: []const u8) bool {
176176 switch (fs) {
177177 .real => |cwd| {
178 cwd.access(path, .{}) catch return false;
178 cwd.access(io, path, .{}) catch return false;
179179 return true;
180180 },
181181 .fake => |paths| return existsFake(paths, path),
lib/compiler/aro/aro/Toolchain.zig+8-5
......@@ -501,7 +501,7 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
501501 try d.includes.ensureUnusedCapacity(gpa, 1);
502502 if (d.resource_dir) |resource_dir| {
503503 const path = try std.fs.path.join(arena, &.{ resource_dir, "include" });
504 comp.cwd.access(path, .{}) catch {
504 comp.cwd.access(io, path, .{}) catch {
505505 return d.fatal("Aro builtin headers not found in provided -resource-dir", .{});
506506 };
507507 d.includes.appendAssumeCapacity(.{ .kind = .system, .path = path });
......@@ -512,7 +512,7 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
512512 var base_dir = d.comp.cwd.openDir(io, dirname, .{}) catch continue;
513513 defer base_dir.close(io);
514514
515 base_dir.access("include/stddef.h", .{}) catch continue;
515 base_dir.access(io, "include/stddef.h", .{}) catch continue;
516516 const path = try std.fs.path.join(arena, &.{ dirname, "include" });
517517 d.includes.appendAssumeCapacity(.{ .kind = .system, .path = path });
518518 break;
......@@ -524,12 +524,14 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
524524/// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned
525525pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 {
526526 const comp = tc.driver.comp;
527 return comp.cwd.readFile(comp.io, path, buf) catch null;
527 const io = comp.io;
528 return comp.cwd.readFile(io, path, buf) catch null;
528529}
529530
530531pub fn exists(tc: *const Toolchain, path: []const u8) bool {
531532 const comp = tc.driver.comp;
532 comp.cwd.access(comp.io, path, .{}) catch return false;
533 const io = comp.io;
534 comp.cwd.access(io, path, .{}) catch return false;
533535 return true;
534536}
535537
......@@ -547,7 +549,8 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool {
547549 }
548550
549551 const comp = tc.driver.comp;
550 comp.cwd.access(comp.io, path, .{ .execute = true }) catch return false;
552 const io = comp.io;
553 comp.cwd.access(io, path, .{ .execute = true }) catch return false;
551554 // Todo: ensure path is not a directory
552555 return true;
553556}
lib/compiler/aro/backend/Assembly.zig+2-2
......@@ -12,8 +12,8 @@ pub fn deinit(self: *const Assembly, gpa: Allocator) void {
1212 gpa.free(self.text);
1313}
1414
15pub fn writeToFile(self: Assembly, file: Io.File) !void {
16 var file_writer = file.writer(&.{});
15pub fn writeToFile(self: Assembly, io: Io, file: Io.File) !void {
16 var file_writer = file.writer(io, &.{});
1717
1818 var buffers = [_][]const u8{ self.data, self.text };
1919 try file_writer.interface.writeSplatAll(&buffers, 1);
lib/compiler/resinator/cli.zig+5-5
......@@ -250,13 +250,13 @@ pub const Options = struct {
250250 /// worlds' situation where we'll be compatible with most use-cases
251251 /// of the .rc extension being omitted from the CLI args, but still
252252 /// work fine if the file itself does not have an extension.
253 pub fn maybeAppendRC(options: *Options, cwd: Io.Dir) !void {
253 pub fn maybeAppendRC(options: *Options, io: Io, cwd: Io.Dir) !void {
254254 switch (options.input_source) {
255255 .stdio => return,
256256 .filename => {},
257257 }
258258 if (options.input_format == .rc and std.fs.path.extension(options.input_source.filename).len == 0) {
259 cwd.access(options.input_source.filename, .{}) catch |err| switch (err) {
259 cwd.access(io, options.input_source.filename, .{}) catch |err| switch (err) {
260260 error.FileNotFound => {
261261 var filename_bytes = try options.allocator.alloc(u8, options.input_source.filename.len + 3);
262262 @memcpy(filename_bytes[0..options.input_source.filename.len], options.input_source.filename);
......@@ -2005,19 +2005,19 @@ test "maybeAppendRC" {
20052005 // appended.
20062006 var file = try tmp.dir.createFile(io, "foo", .{});
20072007 file.close(io);
2008 try options.maybeAppendRC(tmp.dir);
2008 try options.maybeAppendRC(io, tmp.dir);
20092009 try std.testing.expectEqualStrings("foo", options.input_source.filename);
20102010
20112011 // Now delete the file and try again. But this time change the input format
20122012 // to non-rc.
20132013 try tmp.dir.deleteFile("foo");
20142014 options.input_format = .res;
2015 try options.maybeAppendRC(tmp.dir);
2015 try options.maybeAppendRC(io, tmp.dir);
20162016 try std.testing.expectEqualStrings("foo", options.input_source.filename);
20172017
20182018 // Finally, reset the input format to rc. Since the verbatim name is no longer found
20192019 // and the input filename does not have an extension, .rc should get appended.
20202020 options.input_format = .rc;
2021 try options.maybeAppendRC(tmp.dir);
2021 try options.maybeAppendRC(io, tmp.dir);
20222022 try std.testing.expectEqualStrings("foo.rc", options.input_source.filename);
20232023}
lib/compiler/resinator/main.zig+3-3
......@@ -318,7 +318,7 @@ pub fn main() !void {
318318 defer depfile.close(io);
319319
320320 var depfile_buffer: [1024]u8 = undefined;
321 var depfile_writer = depfile.writer(&depfile_buffer);
321 var depfile_writer = depfile.writer(io, &depfile_buffer);
322322 switch (options.depfile_fmt) {
323323 .json => {
324324 var write_stream: std.json.Stringify = .{
......@@ -521,9 +521,9 @@ const IoStream = struct {
521521 }
522522 };
523523
524 pub fn writer(source: *Source, allocator: Allocator, buffer: []u8) Writer {
524 pub fn writer(source: *Source, allocator: Allocator, io: Io, buffer: []u8) Writer {
525525 return switch (source.*) {
526 .file, .stdio => |file| .{ .file = file.writer(buffer) },
526 .file, .stdio => |file| .{ .file = file.writer(io, buffer) },
527527 .memory => |*list| .{ .allocating = .fromArrayList(allocator, list) },
528528 .closed => unreachable,
529529 };
lib/compiler/std-docs.zig+4-4
......@@ -334,8 +334,8 @@ fn buildWasmBinary(
334334 });
335335 defer poller.deinit();
336336
337 try sendMessage(child.stdin.?, .update);
338 try sendMessage(child.stdin.?, .exit);
337 try sendMessage(io, child.stdin.?, .update);
338 try sendMessage(io, child.stdin.?, .exit);
339339
340340 var result: ?Cache.Path = null;
341341 var result_error_bundle = std.zig.ErrorBundle.empty;
......@@ -421,12 +421,12 @@ fn buildWasmBinary(
421421 };
422422}
423423
424fn sendMessage(file: std.Io.File, tag: std.zig.Client.Message.Tag) !void {
424fn sendMessage(io: Io, file: std.Io.File, tag: std.zig.Client.Message.Tag) !void {
425425 const header: std.zig.Client.Message.Header = .{
426426 .tag = tag,
427427 .bytes_len = 0,
428428 };
429 var w = file.writer(&.{});
429 var w = file.writer(io, &.{});
430430 w.interface.writeStruct(header, .little) catch |err| switch (err) {
431431 error.WriteFailed => return w.err.?,
432432 };
lib/compiler/translate-c/main.zig+2-2
......@@ -232,7 +232,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
232232 Io.File.stdout();
233233 defer if (dep_file_name != null) file.close(io);
234234
235 var file_writer = file.writer(&out_buf);
235 var file_writer = file.writer(io, &out_buf);
236236 dep_file.write(&file_writer.interface) catch
237237 return d.fatal("unable to write dependency file: {s}", .{aro.Driver.errorDescription(file_writer.err.?)});
238238 }
......@@ -263,7 +263,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
263263 out_file_path = path;
264264 }
265265
266 var out_writer = out_file.writer(&out_buf);
266 var out_writer = out_file.writer(io, &out_buf);
267267 out_writer.interface.writeAll(rendered_zig) catch {};
268268 out_writer.interface.flush() catch {};
269269 if (out_writer.err) |write_err|
lib/std/Build.zig+1-1
......@@ -1699,7 +1699,7 @@ pub fn addCheckFile(
16991699 return Step.CheckFile.create(b, file_source, options);
17001700}
17011701
1702pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatFileError)!void {
1702pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatPathError)!void {
17031703 const io = b.graph.io;
17041704 if (b.verbose) log.info("truncate {s}", .{dest_path});
17051705 const cwd = Io.Dir.cwd();
lib/std/Build/Cache/Path.zig+2-2
......@@ -118,14 +118,14 @@ pub fn atomicFile(
118118 return p.root_dir.handle.atomicFile(joined_path, options);
119119}
120120
121pub fn access(p: Path, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
121pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
122122 var buf: [fs.max_path_bytes]u8 = undefined;
123123 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
124124 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
125125 p.sub_path, sub_path,
126126 }) catch return error.NameTooLong;
127127 };
128 return p.root_dir.handle.access(joined_path, flags);
128 return p.root_dir.handle.access(io, joined_path, flags);
129129}
130130
131131pub fn makePath(p: Path, io: Io, sub_path: []const u8) !void {
lib/std/Build/Step.zig+7-5
......@@ -519,19 +519,21 @@ pub fn installFile(s: *Step, src_lazy_path: Build.LazyPath, dest_path: []const u
519519/// Wrapper around `Io.Dir.makePathStatus` that handles verbose and error output.
520520pub fn installDir(s: *Step, dest_path: []const u8) !Io.Dir.MakePathStatus {
521521 const b = s.owner;
522 const io = b.graph.io;
522523 try handleVerbose(b, null, &.{ "install", "-d", dest_path });
523 return Io.Dir.cwd().makePathStatus(dest_path) catch |err|
524 return Io.Dir.cwd().makePathStatus(io, dest_path, .default_dir) catch |err|
524525 return s.fail("unable to create dir '{s}': {t}", .{ dest_path, err });
525526}
526527
527528fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool, web_server: ?*Build.WebServer, gpa: Allocator) !?Path {
528529 const b = s.owner;
529530 const arena = b.allocator;
531 const io = b.graph.io;
530532
531533 var timer = try std.time.Timer.start();
532534
533 try sendMessage(zp.child.stdin.?, .update);
534 if (!watch) try sendMessage(zp.child.stdin.?, .exit);
535 try sendMessage(io, zp.child.stdin.?, .update);
536 if (!watch) try sendMessage(io, zp.child.stdin.?, .exit);
535537
536538 var result: ?Path = null;
537539
......@@ -668,12 +670,12 @@ fn clearZigProcess(s: *Step, gpa: Allocator) void {
668670 }
669671}
670672
671fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void {
673fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void {
672674 const header: std.zig.Client.Message.Header = .{
673675 .tag = tag,
674676 .bytes_len = 0,
675677 };
676 var w = file.writer(&.{});
678 var w = file.writer(io, &.{});
677679 w.interface.writeStruct(header, .little) catch |err| switch (err) {
678680 error.WriteFailed => return w.err.?,
679681 };
lib/std/Build/Step/InstallDir.zig+1-1
......@@ -71,7 +71,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
7171 defer src_dir.close(io);
7272 var it = try src_dir.walk(arena);
7373 var all_cached = true;
74 next_entry: while (try it.next()) |entry| {
74 next_entry: while (try it.next(io)) |entry| {
7575 for (install_dir.options.exclude_extensions) |ext| {
7676 if (mem.endsWith(u8, entry.path, ext)) continue :next_entry;
7777 }
lib/std/Build/Step/Run.zig+25-22
......@@ -1310,7 +1310,7 @@ fn runCommand(
13101310 const need_cross_libc = exe.is_linking_libc and
13111311 (root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
13121312 const other_target = exe.root_module.resolved_target.?.result;
1313 switch (std.zig.system.getExternalExecutor(&b.graph.host.result, &other_target, .{
1313 switch (std.zig.system.getExternalExecutor(io, &b.graph.host.result, &other_target, .{
13141314 .qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
13151315 .link_libc = exe.is_linking_libc,
13161316 })) {
......@@ -1702,7 +1702,7 @@ fn evalZigTest(
17021702 });
17031703 var child_killed = false;
17041704 defer if (!child_killed) {
1705 _ = child.kill() catch {};
1705 _ = child.kill(io) catch {};
17061706 poller.deinit();
17071707 run.step.result_peak_rss = @max(
17081708 run.step.result_peak_rss,
......@@ -1732,7 +1732,7 @@ fn evalZigTest(
17321732 child.stdin = null;
17331733 poller.deinit();
17341734 child_killed = true;
1735 const term = try child.wait();
1735 const term = try child.wait(io);
17361736 run.step.result_peak_rss = @max(
17371737 run.step.result_peak_rss,
17381738 child.resource_usage_statistics.getMaxRss() orelse 0,
......@@ -1752,7 +1752,7 @@ fn evalZigTest(
17521752 child.stdin = null;
17531753 poller.deinit();
17541754 child_killed = true;
1755 const term = try child.wait();
1755 const term = try child.wait(io);
17561756 run.step.result_peak_rss = @max(
17571757 run.step.result_peak_rss,
17581758 child.resource_usage_statistics.getMaxRss() orelse 0,
......@@ -1840,6 +1840,7 @@ fn pollZigTest(
18401840 switch (ctx.fuzz.mode) {
18411841 .forever => {
18421842 sendRunFuzzTestMessage(
1843 io,
18431844 child.stdin.?,
18441845 ctx.unit_test_index,
18451846 .forever,
......@@ -1848,6 +1849,7 @@ fn pollZigTest(
18481849 },
18491850 .limit => |limit| {
18501851 sendRunFuzzTestMessage(
1852 io,
18511853 child.stdin.?,
18521854 ctx.unit_test_index,
18531855 .iterations,
......@@ -1857,11 +1859,11 @@ fn pollZigTest(
18571859 }
18581860 } else if (opt_metadata.*) |*md| {
18591861 // Previous unit test process died or was killed; we're continuing where it left off
1860 requestNextTest(child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
1862 requestNextTest(io, child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
18611863 } else {
18621864 // Running unit tests normally
18631865 run.fuzz_tests.clearRetainingCapacity();
1864 sendMessage(child.stdin.?, .query_test_metadata) catch |err| return .{ .write_failed = err };
1866 sendMessage(io, child.stdin.?, .query_test_metadata) catch |err| return .{ .write_failed = err };
18651867 }
18661868
18671869 var active_test_index: ?u32 = null;
......@@ -1977,7 +1979,7 @@ fn pollZigTest(
19771979 active_test_index = null;
19781980 if (timer) |*t| t.reset();
19791981
1980 requestNextTest(child.stdin.?, &opt_metadata.*.?, &sub_prog_node) catch |err| return .{ .write_failed = err };
1982 requestNextTest(io, child.stdin.?, &opt_metadata.*.?, &sub_prog_node) catch |err| return .{ .write_failed = err };
19811983 },
19821984 .test_started => {
19831985 active_test_index = opt_metadata.*.?.next_index - 1;
......@@ -2026,7 +2028,7 @@ fn pollZigTest(
20262028 active_test_index = null;
20272029 if (timer) |*t| md.ns_per_test[tr_hdr.index] = t.lap();
20282030
2029 requestNextTest(child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
2031 requestNextTest(io, child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
20302032 },
20312033 .coverage_id => {
20322034 coverage_id = body_r.takeInt(u64, .little) catch unreachable;
......@@ -2097,7 +2099,7 @@ pub const CachedTestMetadata = struct {
20972099 }
20982100};
20992101
2100fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void {
2102fn requestNextTest(io: Io, in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void {
21012103 while (metadata.next_index < metadata.names.len) {
21022104 const i = metadata.next_index;
21032105 metadata.next_index += 1;
......@@ -2108,31 +2110,31 @@ fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Pr
21082110 if (sub_prog_node.*) |n| n.end();
21092111 sub_prog_node.* = metadata.prog_node.start(name, 0);
21102112
2111 try sendRunTestMessage(in, .run_test, i);
2113 try sendRunTestMessage(io, in, .run_test, i);
21122114 return;
21132115 } else {
21142116 metadata.next_index = std.math.maxInt(u32); // indicate that all tests are done
2115 try sendMessage(in, .exit);
2117 try sendMessage(io, in, .exit);
21162118 }
21172119}
21182120
2119fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void {
2121fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void {
21202122 const header: std.zig.Client.Message.Header = .{
21212123 .tag = tag,
21222124 .bytes_len = 0,
21232125 };
2124 var w = file.writer(&.{});
2126 var w = file.writer(io, &.{});
21252127 w.interface.writeStruct(header, .little) catch |err| switch (err) {
21262128 error.WriteFailed => return w.err.?,
21272129 };
21282130}
21292131
2130fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void {
2132fn sendRunTestMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void {
21312133 const header: std.zig.Client.Message.Header = .{
21322134 .tag = tag,
21332135 .bytes_len = 4,
21342136 };
2135 var w = file.writer(&.{});
2137 var w = file.writer(io, &.{});
21362138 w.interface.writeStruct(header, .little) catch |err| switch (err) {
21372139 error.WriteFailed => return w.err.?,
21382140 };
......@@ -2142,6 +2144,7 @@ fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32
21422144}
21432145
21442146fn sendRunFuzzTestMessage(
2147 io: Io,
21452148 file: Io.File,
21462149 index: u32,
21472150 kind: std.Build.abi.fuzz.LimitKind,
......@@ -2151,7 +2154,7 @@ fn sendRunFuzzTestMessage(
21512154 .tag = .start_fuzzing,
21522155 .bytes_len = 4 + 1 + 8,
21532156 };
2154 var w = file.writer(&.{});
2157 var w = file.writer(io, &.{});
21552158 w.interface.writeStruct(header, .little) catch |err| switch (err) {
21562159 error.WriteFailed => return w.err.?,
21572160 };
......@@ -2172,14 +2175,14 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
21722175 const arena = b.allocator;
21732176
21742177 try child.spawn();
2175 errdefer _ = child.kill() catch {};
2178 errdefer _ = child.kill(io) catch {};
21762179
21772180 try child.waitForSpawn();
21782181
21792182 switch (run.stdin) {
21802183 .bytes => |bytes| {
2181 child.stdin.?.writeAll(bytes) catch |err| {
2182 return run.step.fail("unable to write stdin: {s}", .{@errorName(err)});
2184 child.stdin.?.writeStreamingAll(io, bytes) catch |err| {
2185 return run.step.fail("unable to write stdin: {t}", .{err});
21832186 };
21842187 child.stdin.?.close(io);
21852188 child.stdin = null;
......@@ -2187,14 +2190,14 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
21872190 .lazy_path => |lazy_path| {
21882191 const path = lazy_path.getPath3(b, &run.step);
21892192 const file = path.root_dir.handle.openFile(io, path.subPathOrDot(), .{}) catch |err| {
2190 return run.step.fail("unable to open stdin file: {s}", .{@errorName(err)});
2193 return run.step.fail("unable to open stdin file: {t}", .{err});
21912194 };
21922195 defer file.close(io);
21932196 // TODO https://github.com/ziglang/zig/issues/23955
21942197 var read_buffer: [1024]u8 = undefined;
21952198 var file_reader = file.reader(io, &read_buffer);
21962199 var write_buffer: [1024]u8 = undefined;
2197 var stdin_writer = child.stdin.?.writer(&write_buffer);
2200 var stdin_writer = child.stdin.?.writer(io, &write_buffer);
21982201 _ = stdin_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) {
21992202 error.ReadFailed => return run.step.fail("failed to read from {f}: {t}", .{
22002203 path, file_reader.err.?,
......@@ -2267,7 +2270,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
22672270 run.step.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;
22682271
22692272 return .{
2270 .term = try child.wait(),
2273 .term = try child.wait(io),
22712274 .stdout = stdout_bytes,
22722275 .stderr = stderr_bytes,
22732276 };
lib/std/Build/Step/WriteFile.zig+3-6
......@@ -228,7 +228,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
228228
229229 var it = try src_dir.walk(gpa);
230230 defer it.deinit();
231 while (try it.next()) |entry| {
231 while (try it.next(io)) |entry| {
232232 if (!dir.options.pathIncluded(entry.path)) continue;
233233
234234 switch (entry.kind) {
......@@ -259,11 +259,8 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
259259
260260 write_file.generated_directory.path = try b.cache_root.join(arena, &.{ "o", &digest });
261261
262 var cache_dir = b.cache_root.handle.makeOpenPath(cache_path, .{}) catch |err| {
263 return step.fail("unable to make path '{f}{s}': {s}", .{
264 b.cache_root, cache_path, @errorName(err),
265 });
266 };
262 var cache_dir = b.cache_root.handle.makeOpenPath(io, cache_path, .{}) catch |err|
263 return step.fail("unable to make path '{f}{s}': {t}", .{ b.cache_root, cache_path, err });
267264 defer cache_dir.close(io);
268265
269266 for (write_file.files.items) |file| {
lib/std/Io.zig+2-2
......@@ -664,13 +664,13 @@ pub const VTable = struct {
664664
665665 dirMake: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions) Dir.MakeError!void,
666666 dirMakePath: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions) Dir.MakePathError!Dir.MakePathStatus,
667 dirMakeOpenPath: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.MakeOpenPathError!Dir,
667 dirMakeOpenPath: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions, Dir.OpenOptions) Dir.MakeOpenPathError!Dir,
668 dirOpenDir: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.OpenError!Dir,
668669 dirStat: *const fn (?*anyopaque, Dir) Dir.StatError!Dir.Stat,
669670 dirStatPath: *const fn (?*anyopaque, Dir, []const u8, Dir.StatPathOptions) Dir.StatPathError!File.Stat,
670671 dirAccess: *const fn (?*anyopaque, Dir, []const u8, Dir.AccessOptions) Dir.AccessError!void,
671672 dirCreateFile: *const fn (?*anyopaque, Dir, []const u8, File.CreateFlags) File.OpenError!File,
672673 dirOpenFile: *const fn (?*anyopaque, Dir, []const u8, File.OpenFlags) File.OpenError!File,
673 dirOpenDir: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.OpenError!Dir,
674674 dirClose: *const fn (?*anyopaque, []const Dir) void,
675675 dirRead: *const fn (?*anyopaque, *Dir.Reader, []Dir.Entry) Dir.Reader.Error!usize,
676676 dirRealPath: *const fn (?*anyopaque, Dir, path_name: []const u8, out_buffer: []u8) Dir.RealPathError!usize,
lib/std/Io/Dir.zig+8-8
......@@ -191,7 +191,7 @@ pub const SelectiveWalker = struct {
191191 while (self.stack.items.len > 0) {
192192 const top = &self.stack.items[self.stack.items.len - 1];
193193 var dirname_len = top.dirname_len;
194 if (top.iter.next() catch |err| {
194 if (top.iter.next(io) catch |err| {
195195 // If we get an error, then we want the user to be able to continue
196196 // walking if they want, which means that we need to pop the directory
197197 // that errored from the stack. Otherwise, all future `next` calls would
......@@ -302,7 +302,7 @@ pub const Walker = struct {
302302 dir: Dir,
303303 basename: [:0]const u8,
304304 path: [:0]const u8,
305 kind: Dir.Entry.Kind,
305 kind: File.Kind,
306306
307307 /// Returns the depth of the entry relative to the initial directory.
308308 /// Returns 1 for a direct child of the initial directory, 2 for an entry
......@@ -320,10 +320,10 @@ pub const Walker = struct {
320320 /// After each call to this function, and on deinit(), the memory returned
321321 /// from this function becomes invalid. A copy must be made in order to keep
322322 /// a reference to the path.
323 pub fn next(self: *Walker) !?Walker.Entry {
324 const entry = try self.inner.next();
323 pub fn next(self: *Walker, io: Io) !?Walker.Entry {
324 const entry = try self.inner.next(io);
325325 if (entry != null and entry.?.kind == .directory) {
326 try self.inner.enter(entry.?);
326 try self.inner.enter(io, entry.?);
327327 }
328328 return entry;
329329 }
......@@ -495,7 +495,7 @@ pub const WriteFileOptions = struct {
495495 flags: File.CreateFlags = .{},
496496};
497497
498pub const WriteFileError = File.WriteError || File.OpenError;
498pub const WriteFileError = File.Writer.Error || File.OpenError;
499499
500500/// Writes content to the file system, using the file creation flags provided.
501501pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void {
......@@ -556,11 +556,11 @@ pub fn updateFile(
556556 }
557557
558558 if (path.dirname(dest_path)) |dirname| {
559 try dest_dir.makePath(io, dirname, .default_dir);
559 try dest_dir.makePath(io, dirname);
560560 }
561561
562562 var buffer: [1000]u8 = undefined; // Used only when direct fd-to-fd is not available.
563 var atomic_file = try Dir.atomicFile(dest_dir, dest_path, .{
563 var atomic_file = try dest_dir.atomicFile(io, dest_path, .{
564564 .permissions = actual_permissions,
565565 .write_buffer = &buffer,
566566 });
lib/std/Io/Threaded.zig+9-4
......@@ -12,7 +12,7 @@ const std = @import("../std.zig");
1212const Io = std.Io;
1313const net = std.Io.net;
1414const File = std.Io.File;
15const Dir = std.Dir;
15const Dir = std.Io.Dir;
1616const HostName = std.Io.net.HostName;
1717const IpAddress = std.Io.net.IpAddress;
1818const Allocator = std.mem.Allocator;
......@@ -1614,13 +1614,14 @@ fn dirMakeOpenPathPosix(
16141614 userdata: ?*anyopaque,
16151615 dir: Dir,
16161616 sub_path: []const u8,
1617 permissions: Dir.Permissions,
16171618 options: Dir.OpenOptions,
16181619) Dir.MakeOpenPathError!Dir {
16191620 const t: *Threaded = @ptrCast(@alignCast(userdata));
16201621 const t_io = ioBasic(t);
1621 return dirOpenDirPosix(t, dir, sub_path, options) catch |err| switch (err) {
1622 return dirOpenDirPosix(t, dir, sub_path, permissions, options) catch |err| switch (err) {
16221623 error.FileNotFound => {
1623 try dir.makePath(t_io, sub_path);
1624 _ = try dir.makePathStatus(t_io, sub_path, permissions);
16241625 return dirOpenDirPosix(t, dir, sub_path, options);
16251626 },
16261627 else => |e| return e,
......@@ -1631,12 +1632,15 @@ fn dirMakeOpenPathWindows(
16311632 userdata: ?*anyopaque,
16321633 dir: Dir,
16331634 sub_path: []const u8,
1635 permissions: Dir.Permissions,
16341636 options: Dir.OpenOptions,
16351637) Dir.MakeOpenPathError!Dir {
16361638 const t: *Threaded = @ptrCast(@alignCast(userdata));
16371639 const current_thread = Thread.getCurrent(t);
16381640 const w = windows;
16391641
1642 _ = permissions; // TODO apply these permissions
1643
16401644 var it = std.fs.path.componentIterator(sub_path);
16411645 // If there are no components in the path, then create a dummy component with the full path.
16421646 var component: std.fs.path.NativeComponentIterator.Component = it.last() orelse .{
......@@ -1746,13 +1750,14 @@ fn dirMakeOpenPathWasi(
17461750 userdata: ?*anyopaque,
17471751 dir: Dir,
17481752 sub_path: []const u8,
1753 permissions: Dir.Permissions,
17491754 options: Dir.OpenOptions,
17501755) Dir.MakeOpenPathError!Dir {
17511756 const t: *Threaded = @ptrCast(@alignCast(userdata));
17521757 const t_io = ioBasic(t);
17531758 return dirOpenDirWasi(t, dir, sub_path, options) catch |err| switch (err) {
17541759 error.FileNotFound => {
1755 try dir.makePath(t_io, sub_path);
1760 _ = try dir.makePathStatus(t_io, sub_path, permissions);
17561761 return dirOpenDirWasi(t, dir, sub_path, options);
17571762 },
17581763 else => |e| return e,
lib/std/Io/test.zig+1-1
......@@ -30,7 +30,7 @@ test "write a file, read it, then delete it" {
3030 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
3131 defer file.close(io);
3232
33 var file_writer = file.writer(&.{});
33 var file_writer = file.writer(io, &.{});
3434 const st = &file_writer.interface;
3535 try st.print("begin", .{});
3636 try st.writeAll(&data);
lib/std/debug.zig+4-4
......@@ -1279,7 +1279,7 @@ test printLineFromFile {
12791279
12801280 const overlap = 10;
12811281 var buf: [16]u8 = undefined;
1282 var file_writer = file.writer(&buf);
1282 var file_writer = file.writer(io, &buf);
12831283 const writer = &file_writer.interface;
12841284 try writer.splatByteAll('a', std.heap.page_size_min - overlap);
12851285 try writer.writeByte('\n');
......@@ -1296,7 +1296,7 @@ test printLineFromFile {
12961296 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_ends_on_page_boundary.zig" });
12971297 defer gpa.free(path);
12981298
1299 var file_writer = file.writer(&.{});
1299 var file_writer = file.writer(io, &.{});
13001300 const writer = &file_writer.interface;
13011301 try writer.splatByteAll('a', std.heap.page_size_max);
13021302
......@@ -1310,7 +1310,7 @@ test printLineFromFile {
13101310 const path = try fs.path.join(gpa, &.{ test_dir_path, "very_long_first_line_spanning_multiple_pages.zig" });
13111311 defer gpa.free(path);
13121312
1313 var file_writer = file.writer(&.{});
1313 var file_writer = file.writer(io, &.{});
13141314 const writer = &file_writer.interface;
13151315 try writer.splatByteAll('a', 3 * std.heap.page_size_max);
13161316
......@@ -1336,7 +1336,7 @@ test printLineFromFile {
13361336 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_of_newlines.zig" });
13371337 defer gpa.free(path);
13381338
1339 var file_writer = file.writer(&.{});
1339 var file_writer = file.writer(io, &.{});
13401340 const writer = &file_writer.interface;
13411341 const real_file_start = 3 * std.heap.page_size_min;
13421342 try writer.splatByteAll('\n', real_file_start);
lib/std/fs/test.zig+12-12
......@@ -1206,8 +1206,8 @@ test "deleteTree does not follow symlinks" {
12061206
12071207 try tmp.dir.deleteTree("a");
12081208
1209 try testing.expectError(error.FileNotFound, tmp.dir.access("a", .{}));
1210 try tmp.dir.access("b", .{});
1209 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "a", .{}));
1210 try tmp.dir.access(io, "b", .{});
12111211}
12121212
12131213test "deleteTree on a symlink" {
......@@ -1221,16 +1221,16 @@ test "deleteTree on a symlink" {
12211221 try setupSymlink(tmp.dir, "file", "filelink", .{});
12221222
12231223 try tmp.dir.deleteTree("filelink");
1224 try testing.expectError(error.FileNotFound, tmp.dir.access("filelink", .{}));
1225 try tmp.dir.access("file", .{});
1224 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "filelink", .{}));
1225 try tmp.dir.access(io, "file", .{});
12261226
12271227 // Symlink to a directory
12281228 try tmp.dir.makePath(io, "dir");
12291229 try setupSymlink(tmp.dir, "dir", "dirlink", .{ .is_directory = true });
12301230
12311231 try tmp.dir.deleteTree("dirlink");
1232 try testing.expectError(error.FileNotFound, tmp.dir.access("dirlink", .{}));
1233 try tmp.dir.access("dir", .{});
1232 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "dirlink", .{}));
1233 try tmp.dir.access(io, "dir", .{});
12341234}
12351235
12361236test "makePath, put some files in it, deleteTree" {
......@@ -1358,8 +1358,8 @@ test "makepath relative walks" {
13581358 // On Windows, .. is resolved before passing the path to NtCreateFile,
13591359 // meaning everything except `first/C` drops out.
13601360 try expectDir(io, tmp.dir, "first" ++ fs.path.sep_str ++ "C");
1361 try testing.expectError(error.FileNotFound, tmp.dir.access("second", .{}));
1362 try testing.expectError(error.FileNotFound, tmp.dir.access("third", .{}));
1361 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "second", .{}));
1362 try testing.expectError(error.FileNotFound, tmp.dir.access(io, "third", .{}));
13631363 },
13641364 else => {
13651365 try expectDir(io, tmp.dir, "first" ++ fs.path.sep_str ++ "A");
......@@ -1561,10 +1561,10 @@ test "access file" {
15611561 const file_path = try ctx.transformPath("os_test_tmp" ++ fs.path.sep_str ++ "file.txt");
15621562
15631563 try ctx.dir.makePath(io, dir_path);
1564 try testing.expectError(error.FileNotFound, ctx.dir.access(file_path, .{}));
1564 try testing.expectError(error.FileNotFound, ctx.dir.access(io, file_path, .{}));
15651565
15661566 try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "" });
1567 try ctx.dir.access(file_path, .{});
1567 try ctx.dir.access(io, file_path, .{});
15681568 try ctx.dir.deleteTree(dir_path);
15691569 }
15701570 }.impl);
......@@ -2036,13 +2036,13 @@ test "'.' and '..' in Io.Dir functions" {
20362036 const update_path = try ctx.transformPath("./subdir/../update");
20372037
20382038 try ctx.dir.makeDir(subdir_path);
2039 try ctx.dir.access(subdir_path, .{});
2039 try ctx.dir.access(io, subdir_path, .{});
20402040 var created_subdir = try ctx.dir.openDir(io, subdir_path, .{});
20412041 created_subdir.close(io);
20422042
20432043 const created_file = try ctx.dir.createFile(io, file_path, .{});
20442044 created_file.close(io);
2045 try ctx.dir.access(file_path, .{});
2045 try ctx.dir.access(io, file_path, .{});
20462046
20472047 try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});
20482048 try ctx.dir.rename(copy_path, rename_path);
lib/std/posix.zig-61
......@@ -2842,67 +2842,6 @@ pub fn msync(memory: []align(page_size_min) u8, flags: i32) MSyncError!void {
28422842 }
28432843}
28442844
2845pub const AccessError = error{
2846 AccessDenied,
2847 PermissionDenied,
2848 FileNotFound,
2849 NameTooLong,
2850 InputOutput,
2851 SystemResources,
2852 FileBusy,
2853 SymLinkLoop,
2854 ReadOnlyFileSystem,
2855 /// WASI: file paths must be valid UTF-8.
2856 /// Windows: file paths provided by the user must be valid WTF-8.
2857 /// https://wtf-8.codeberg.page/
2858 BadPathName,
2859 Canceled,
2860} || UnexpectedError;
2861
2862/// check user's permissions for a file
2863///
2864/// * On Windows, asserts `path` is valid [WTF-8](https://wtf-8.codeberg.page/).
2865/// * On WASI, invalid UTF-8 passed to `path` causes `error.BadPathName`.
2866/// * On other platforms, `path` is an opaque sequence of bytes with no particular encoding.
2867///
2868/// On Windows, `mode` is ignored. This is a POSIX API that is only partially supported by
2869/// Windows. See `fs` for the cross-platform file system API.
2870pub fn access(path: []const u8, mode: u32) AccessError!void {
2871 if (native_os == .windows) {
2872 @compileError("use std.Io instead");
2873 } else if (native_os == .wasi and !builtin.link_libc) {
2874 @compileError("wasi doesn't support absolute paths");
2875 }
2876 const path_c = try toPosixPath(path);
2877 return accessZ(&path_c, mode);
2878}
2879
2880/// Same as `access` except `path` is null-terminated.
2881pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
2882 if (native_os == .windows) {
2883 @compileError("use std.Io instead");
2884 } else if (native_os == .wasi and !builtin.link_libc) {
2885 return access(mem.sliceTo(path, 0), mode);
2886 }
2887 switch (errno(system.access(path, mode))) {
2888 .SUCCESS => return,
2889 .ACCES => return error.AccessDenied,
2890 .PERM => return error.PermissionDenied,
2891 .ROFS => return error.ReadOnlyFileSystem,
2892 .LOOP => return error.SymLinkLoop,
2893 .TXTBSY => return error.FileBusy,
2894 .NOTDIR => return error.FileNotFound,
2895 .NOENT => return error.FileNotFound,
2896 .NAMETOOLONG => return error.NameTooLong,
2897 .INVAL => unreachable,
2898 .FAULT => unreachable,
2899 .IO => return error.InputOutput,
2900 .NOMEM => return error.SystemResources,
2901 .ILSEQ => return error.BadPathName,
2902 else => |err| return unexpectedErrno(err),
2903 }
2904}
2905
29062845pub const PipeError = error{
29072846 SystemFdQuotaExceeded,
29082847 ProcessFdQuotaExceeded,
lib/std/posix/test.zig+7-5
......@@ -376,7 +376,7 @@ test "mmap" {
376376 const file = try tmp.dir.createFile(io, test_out_file, .{});
377377 defer file.close(io);
378378
379 var stream = file.writer(&.{});
379 var stream = file.writer(io, &.{});
380380
381381 var i: usize = 0;
382382 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
......@@ -741,6 +741,8 @@ test "access smoke test" {
741741 if (native_os == .windows) return error.SkipZigTest;
742742 if (native_os == .openbsd) return error.SkipZigTest;
743743
744 const io = testing.io;
745
744746 var tmp = tmpDir(.{});
745747 defer tmp.cleanup();
746748
......@@ -761,9 +763,9 @@ test "access smoke test" {
761763 const file_path = try fs.path.join(a, &.{ base_path, "some_file" });
762764 defer a.free(file_path);
763765 if (native_os == .windows) {
764 try posix.access(file_path, posix.F_OK);
766 try posix.access(io, file_path, posix.F_OK);
765767 } else {
766 try posix.access(file_path, posix.F_OK | posix.W_OK | posix.R_OK);
768 try posix.access(io, file_path, posix.F_OK | posix.W_OK | posix.R_OK);
767769 }
768770 }
769771
......@@ -771,7 +773,7 @@ test "access smoke test" {
771773 // Try to access() a non-existent file - should fail with error.FileNotFound
772774 const file_path = try fs.path.join(a, &.{ base_path, "some_other_file" });
773775 defer a.free(file_path);
774 try expectError(error.FileNotFound, posix.access(file_path, posix.F_OK));
776 try expectError(error.FileNotFound, posix.access(io, file_path, posix.F_OK));
775777 }
776778
777779 {
......@@ -786,7 +788,7 @@ test "access smoke test" {
786788 const file_path = try fs.path.join(a, &.{ base_path, "some_dir" });
787789 defer a.free(file_path);
788790
789 try posix.access(file_path, posix.F_OK);
791 try posix.access(io, file_path, posix.F_OK);
790792 }
791793}
792794
lib/std/zig/LibCInstallation.zig+5-5
......@@ -357,7 +357,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F
357357 }
358358
359359 if (self.sys_include_dir == null) {
360 if (search_dir.access(sys_include_dir_example_file, .{})) |_| {
360 if (search_dir.access(io, sys_include_dir_example_file, .{})) |_| {
361361 self.sys_include_dir = try allocator.dupeZ(u8, search_path);
362362 } else |err| switch (err) {
363363 error.FileNotFound => {},
......@@ -402,7 +402,7 @@ fn findNativeIncludeDirWindows(
402402 };
403403 defer dir.close(io);
404404
405 dir.access("stdlib.h", .{}) catch |err| switch (err) {
405 dir.access(io, "stdlib.h", .{}) catch |err| switch (err) {
406406 error.FileNotFound => continue,
407407 else => return error.FileSystem,
408408 };
......@@ -450,7 +450,7 @@ fn findNativeCrtDirWindows(
450450 };
451451 defer dir.close(io);
452452
453 dir.access("ucrt.lib", .{}) catch |err| switch (err) {
453 dir.access(io, "ucrt.lib", .{}) catch |err| switch (err) {
454454 error.FileNotFound => continue,
455455 else => return error.FileSystem,
456456 };
......@@ -518,7 +518,7 @@ fn findNativeKernel32LibDir(
518518 };
519519 defer dir.close(io);
520520
521 dir.access("kernel32.lib", .{}) catch |err| switch (err) {
521 dir.access(io, "kernel32.lib", .{}) catch |err| switch (err) {
522522 error.FileNotFound => continue,
523523 else => return error.FileSystem,
524524 };
......@@ -554,7 +554,7 @@ fn findNativeMsvcIncludeDir(
554554 };
555555 defer dir.close(io);
556556
557 dir.access("vcruntime.h", .{}) catch |err| switch (err) {
557 dir.access(io, "vcruntime.h", .{}) catch |err| switch (err) {
558558 error.FileNotFound => return error.LibCStdLibHeaderNotFound,
559559 else => return error.FileSystem,
560560 };
lib/std/zig/llvm/Builder.zig+2-2
......@@ -9589,8 +9589,8 @@ pub fn printToFilePath(b: *Builder, io: Io, dir: Io.Dir, path: []const u8) !void
95899589 try b.printToFile(io, file, &buffer);
95909590}
95919591
9592pub fn printToFile(b: *Builder, file: Io.File, buffer: []u8) !void {
9593 var fw = file.writer(buffer);
9592pub fn printToFile(b: *Builder, io: Io, file: Io.File, buffer: []u8) !void {
9593 var fw = file.writer(io, buffer);
95949594 try print(b, &fw.interface);
95959595 try fw.interface.flush();
95969596}
lib/std/zig/system.zig+2-1
......@@ -40,6 +40,7 @@ pub const GetExternalExecutorOptions = struct {
4040/// Return whether or not the given host is capable of running executables of
4141/// the other target.
4242pub fn getExternalExecutor(
43 io: Io,
4344 host: *const std.Target,
4445 candidate: *const std.Target,
4546 options: GetExternalExecutorOptions,
......@@ -70,7 +71,7 @@ pub fn getExternalExecutor(
7071 if (os_match and cpu_ok) native: {
7172 if (options.link_libc) {
7273 if (candidate.dynamic_linker.get()) |candidate_dl| {
73 Io.Dir.cwd().access(candidate_dl, .{}) catch {
74 Io.Dir.cwd().access(io, candidate_dl, .{}) catch {
7475 bad_result = .{ .bad_dl = candidate_dl };
7576 break :native;
7677 };
src/Compilation.zig+1-1
......@@ -788,7 +788,7 @@ pub const Directories = struct {
788788 const local_cache: Cache.Directory = switch (local_cache_strat) {
789789 .override => |path| openUnresolved(arena, io, cwd, path, .@"local cache"),
790790 .search => d: {
791 const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, cwd) catch |err| {
791 const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, io, cwd) catch |err| {
792792 fatal("unable to resolve zig cache directory: {s}", .{@errorName(err)});
793793 };
794794 const path = maybe_path orelse break :d global_cache;
src/Package/Fetch.zig+3-2
......@@ -418,7 +418,7 @@ pub fn run(f: *Fetch) RunError!void {
418418 const prefixed_pkg_sub_path = prefixed_pkg_sub_path_buffer[0 .. 2 + hash_slice.len];
419419 const prefix_len: usize = if (f.job_queue.read_only) "p/".len else 0;
420420 const pkg_sub_path = prefixed_pkg_sub_path[prefix_len..];
421 if (cache_root.handle.access(pkg_sub_path, .{})) |_| {
421 if (cache_root.handle.access(io, pkg_sub_path, .{})) |_| {
422422 assert(f.lazy_status != .unavailable);
423423 f.package_root = .{
424424 .root_dir = cache_root,
......@@ -637,8 +637,9 @@ pub fn computedPackageHash(f: *const Fetch) Package.Hash {
637637/// `computeHash` gets a free check for the existence of `build.zig`, but when
638638/// not computing a hash, we need to do a syscall to check for it.
639639fn checkBuildFileExistence(f: *Fetch) RunError!void {
640 const io = f.job_queue.io;
640641 const eb = &f.error_bundle;
641 if (f.package_root.access(Package.build_zig_basename, .{})) |_| {
642 if (f.package_root.access(io, Package.build_zig_basename, .{})) |_| {
642643 f.has_build_zig = true;
643644 } else |err| switch (err) {
644645 error.FileNotFound => {},
src/introspect.zig+2-2
......@@ -202,11 +202,11 @@ pub const default_local_zig_cache_basename = ".zig-cache";
202202/// Searches upwards from `cwd` for a directory containing a `build.zig` file.
203203/// If such a directory is found, returns the path to it joined to the `.zig_cache` name.
204204/// Otherwise, returns `null`, indicating no suitable local cache location.
205pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator.Error!?[]u8 {
205pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 {
206206 var cur_dir = cwd;
207207 while (true) {
208208 const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
209 if (Io.Dir.cwd().access(joined, .{})) |_| {
209 if (Io.Dir.cwd().access(io, joined, .{})) |_| {
210210 return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
211211 } else |err| switch (err) {
212212 error.FileNotFound => {
src/libs/mingw.zig+7-5
......@@ -242,7 +242,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
242242 defer arena_allocator.deinit();
243243 const arena = arena_allocator.allocator();
244244
245 const def_file_path = findDef(arena, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) {
245 const def_file_path = findDef(arena, io, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) {
246246 error.FileNotFound => {
247247 log.debug("no {s}.def file available to make a DLL import {s}.lib", .{ lib_name, lib_name });
248248 // In this case we will end up putting foo.lib onto the linker line and letting the linker
......@@ -402,11 +402,12 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
402402
403403pub fn libExists(
404404 allocator: Allocator,
405 io: Io,
405406 target: *const std.Target,
406407 zig_lib_directory: Cache.Directory,
407408 lib_name: []const u8,
408409) !bool {
409 const s = findDef(allocator, target, zig_lib_directory, lib_name) catch |err| switch (err) {
410 const s = findDef(allocator, io, target, zig_lib_directory, lib_name) catch |err| switch (err) {
410411 error.FileNotFound => return false,
411412 else => |e| return e,
412413 };
......@@ -418,6 +419,7 @@ pub fn libExists(
418419/// see if a .def file exists.
419420fn findDef(
420421 allocator: Allocator,
422 io: Io,
421423 target: *const std.Target,
422424 zig_lib_directory: Cache.Directory,
423425 lib_name: []const u8,
......@@ -443,7 +445,7 @@ fn findDef(
443445 } else {
444446 try override_path.print(fmt_path, .{ lib_path, lib_name });
445447 }
446 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
448 if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| {
447449 return override_path.toOwnedSlice();
448450 } else |err| switch (err) {
449451 error.FileNotFound => {},
......@@ -460,7 +462,7 @@ fn findDef(
460462 } else {
461463 try override_path.print(fmt_path, .{lib_name});
462464 }
463 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
465 if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| {
464466 return override_path.toOwnedSlice();
465467 } else |err| switch (err) {
466468 error.FileNotFound => {},
......@@ -477,7 +479,7 @@ fn findDef(
477479 } else {
478480 try override_path.print(fmt_path, .{lib_name});
479481 }
480 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
482 if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| {
481483 return override_path.toOwnedSlice();
482484 } else |err| switch (err) {
483485 error.FileNotFound => {},
src/link/C.zig+2-1
......@@ -371,6 +371,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P
371371 const comp = self.base.comp;
372372 const diags = &comp.link_diags;
373373 const gpa = comp.gpa;
374 const io = comp.io;
374375 const zcu = self.base.comp.zcu.?;
375376 const ip = &zcu.intern_pool;
376377 const pt: Zcu.PerThread = .activate(zcu, tid);
......@@ -509,7 +510,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P
509510
510511 const file = self.base.file.?;
511512 file.setEndPos(f.file_size) catch |err| return diags.fail("failed to allocate file: {s}", .{@errorName(err)});
512 var fw = file.writer(&.{});
513 var fw = file.writer(io, &.{});
513514 var w = &fw.interface;
514515 w.writeVecAll(f.all_buffers.items) catch |err| switch (err) {
515516 error.WriteFailed => return diags.fail("failed to write to '{f}': {s}", .{
src/link/Lld.zig+5-4
......@@ -359,6 +359,7 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {
359359fn coffLink(lld: *Lld, arena: Allocator) !void {
360360 const comp = lld.base.comp;
361361 const gpa = comp.gpa;
362 const io = comp.io;
362363 const base = &lld.base;
363364 const coff = &lld.ofmt.coff;
364365
......@@ -718,13 +719,13 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
718719 argv.appendAssumeCapacity(try crt_file.full_object_path.toString(arena));
719720 continue;
720721 }
721 if (try findLib(arena, lib_basename, coff.lib_directories)) |full_path| {
722 if (try findLib(arena, io, lib_basename, coff.lib_directories)) |full_path| {
722723 argv.appendAssumeCapacity(full_path);
723724 continue;
724725 }
725726 if (target.abi.isGnu()) {
726727 const fallback_name = try allocPrint(arena, "lib{s}.dll.a", .{key});
727 if (try findLib(arena, fallback_name, coff.lib_directories)) |full_path| {
728 if (try findLib(arena, io, fallback_name, coff.lib_directories)) |full_path| {
728729 argv.appendAssumeCapacity(full_path);
729730 continue;
730731 }
......@@ -741,9 +742,9 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
741742 try spawnLld(comp, arena, argv.items);
742743 }
743744}
744fn findLib(arena: Allocator, name: []const u8, lib_directories: []const Cache.Directory) !?[]const u8 {
745fn findLib(arena: Allocator, io: Io, name: []const u8, lib_directories: []const Cache.Directory) !?[]const u8 {
745746 for (lib_directories) |lib_directory| {
746 lib_directory.handle.access(name, .{}) catch |err| switch (err) {
747 lib_directory.handle.access(io, name, .{}) catch |err| switch (err) {
747748 error.FileNotFound => continue,
748749 else => |e| return e,
749750 };
src/link/MachO.zig+12-9
......@@ -829,7 +829,8 @@ pub fn resolveLibSystem(
829829 comp: *Compilation,
830830 out_libs: anytype,
831831) !void {
832 const diags = &self.base.comp.link_diags;
832 const io = comp.io;
833 const diags = &comp.link_diags;
833834
834835 var test_path = std.array_list.Managed(u8).init(arena);
835836 var checked_paths = std.array_list.Managed([]const u8).init(arena);
......@@ -838,16 +839,16 @@ pub fn resolveLibSystem(
838839 if (self.sdk_layout) |sdk_layout| switch (sdk_layout) {
839840 .sdk => {
840841 const dir = try fs.path.join(arena, &.{ comp.sysroot.?, "usr", "lib" });
841 if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
842 if (try accessLibPath(arena, io, &test_path, &checked_paths, dir, "System")) break :success;
842843 },
843844 .vendored => {
844845 const dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "darwin" });
845 if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
846 if (try accessLibPath(arena, io, &test_path, &checked_paths, dir, "System")) break :success;
846847 },
847848 };
848849
849850 for (self.lib_directories) |directory| {
850 if (try accessLibPath(arena, &test_path, &checked_paths, directory.path orelse ".", "System")) break :success;
851 if (try accessLibPath(arena, io, &test_path, &checked_paths, directory.path orelse ".", "System")) break :success;
851852 }
852853
853854 diags.addMissingLibraryError(checked_paths.items, "unable to find libSystem system library", .{});
......@@ -1074,6 +1075,7 @@ fn isHoisted(self: *MachO, install_name: []const u8) bool {
10741075/// TODO delete this, libraries must be instead resolved when instantiating the compilation pipeline
10751076fn accessLibPath(
10761077 arena: Allocator,
1078 io: Io,
10771079 test_path: *std.array_list.Managed(u8),
10781080 checked_paths: *std.array_list.Managed([]const u8),
10791081 search_dir: []const u8,
......@@ -1085,7 +1087,7 @@ fn accessLibPath(
10851087 test_path.clearRetainingCapacity();
10861088 try test_path.print("{s}" ++ sep ++ "lib{s}{s}", .{ search_dir, name, ext });
10871089 try checked_paths.append(try arena.dupe(u8, test_path.items));
1088 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1090 Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
10891091 error.FileNotFound => continue,
10901092 else => |e| return e,
10911093 };
......@@ -1097,6 +1099,7 @@ fn accessLibPath(
10971099
10981100fn accessFrameworkPath(
10991101 arena: Allocator,
1102 io: Io,
11001103 test_path: *std.array_list.Managed(u8),
11011104 checked_paths: *std.array_list.Managed([]const u8),
11021105 search_dir: []const u8,
......@@ -1113,7 +1116,7 @@ fn accessFrameworkPath(
11131116 ext,
11141117 });
11151118 try checked_paths.append(try arena.dupe(u8, test_path.items));
1116 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1119 Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
11171120 error.FileNotFound => continue,
11181121 else => |e| return e,
11191122 };
......@@ -1172,14 +1175,14 @@ fn parseDependentDylibs(self: *MachO) !void {
11721175 // Framework
11731176 for (framework_dirs) |dir| {
11741177 test_path.clearRetainingCapacity();
1175 if (try accessFrameworkPath(arena, &test_path, &checked_paths, dir, stem)) break :full_path test_path.items;
1178 if (try accessFrameworkPath(arena, io, &test_path, &checked_paths, dir, stem)) break :full_path test_path.items;
11761179 }
11771180
11781181 // Library
11791182 const lib_name = eatPrefix(stem, "lib") orelse stem;
11801183 for (lib_directories) |lib_directory| {
11811184 test_path.clearRetainingCapacity();
1182 if (try accessLibPath(arena, &test_path, &checked_paths, lib_directory.path orelse ".", lib_name)) break :full_path test_path.items;
1185 if (try accessLibPath(arena, io, &test_path, &checked_paths, lib_directory.path orelse ".", lib_name)) break :full_path test_path.items;
11831186 }
11841187 }
11851188
......@@ -1194,7 +1197,7 @@ fn parseDependentDylibs(self: *MachO) !void {
11941197 try test_path.print("{s}{s}", .{ path, ext });
11951198 }
11961199 try checked_paths.append(try arena.dupe(u8, test_path.items));
1197 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1200 Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
11981201 error.FileNotFound => continue,
11991202 else => |e| return e,
12001203 };
src/main.zig+5-3
......@@ -3208,6 +3208,7 @@ fn buildOutputType(
32083208
32093209 for (create_module.framework_dirs.items) |framework_dir_path| {
32103210 if (try accessFrameworkPath(
3211 io,
32113212 &test_path,
32123213 &checked_paths,
32133214 framework_dir_path,
......@@ -6626,7 +6627,7 @@ fn warnAboutForeignBinaries(
66266627 const host_query: std.Target.Query = .{};
66276628 const host_target = std.zig.resolveTargetQueryOrFatal(io, host_query);
66286629
6629 switch (std.zig.system.getExternalExecutor(&host_target, target, .{ .link_libc = link_libc })) {
6630 switch (std.zig.system.getExternalExecutor(io, &host_target, target, .{ .link_libc = link_libc })) {
66306631 .native => return,
66316632 .rosetta => {
66326633 const host_name = try host_target.zigTriple(arena);
......@@ -6832,6 +6833,7 @@ const ClangSearchSanitizer = struct {
68326833};
68336834
68346835fn accessFrameworkPath(
6836 io: Io,
68356837 test_path: *std.array_list.Managed(u8),
68366838 checked_paths: *std.array_list.Managed(u8),
68376839 framework_dir_path: []const u8,
......@@ -6845,7 +6847,7 @@ fn accessFrameworkPath(
68456847 framework_dir_path, framework_name, framework_name, ext,
68466848 });
68476849 try checked_paths.print("\n {s}", .{test_path.items});
6848 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
6850 Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
68496851 error.FileNotFound => continue,
68506852 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{
68516853 ext, test_path.items, @errorName(e),
......@@ -7280,7 +7282,7 @@ fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) !Build
72807282 var dirname: []const u8 = cwd_path;
72817283 while (true) {
72827284 const joined_path = try fs.path.join(arena, &[_][]const u8{ dirname, build_zig_basename });
7283 if (Io.Dir.cwd().access(joined_path, .{})) |_| {
7285 if (Io.Dir.cwd().access(io, joined_path, .{})) |_| {
72847286 const dir = Io.Dir.cwd().openDir(io, dirname, .{}) catch |err| {
72857287 fatal("unable to open directory while searching for build.zig file, '{s}': {s}", .{ dirname, @errorName(err) });
72867288 };