| author | |
| committer | |
| log | 950d18ef695bb7a28397e080dc3c201559ec4ee2 |
| tree | 253209139275932ed503a5ea4529594ab70df8cc |
| parent | 314c906dba32e72317947a15254519b22745b13f |
33 files changed, 159 insertions(+), 197 deletions(-)
lib/compiler/aro/aro/Driver.zig+3-3| ... | ... | @@ -1333,7 +1333,7 @@ fn processSource( |
| 1333 | 1333 | Io.File.stdout(); |
| 1334 | 1334 | defer if (dep_file_name != null) file.close(io); |
| 1335 | 1335 | |
| 1336 | var file_writer = file.writer(&writer_buf); | |
| 1336 | var file_writer = file.writer(io, &writer_buf); | |
| 1337 | 1337 | dep_file.write(&file_writer.interface) catch |
| 1338 | 1338 | return d.fatal("unable to write dependency file: {s}", .{errorDescription(file_writer.err.?)}); |
| 1339 | 1339 | } |
| ... | ... | @@ -1358,7 +1358,7 @@ fn processSource( |
| 1358 | 1358 | Io.File.stdout(); |
| 1359 | 1359 | defer if (d.output_name != null) file.close(io); |
| 1360 | 1360 | |
| 1361 | var file_writer = file.writer(&writer_buf); | |
| 1361 | var file_writer = file.writer(io, &writer_buf); | |
| 1362 | 1362 | pp.prettyPrintTokens(&file_writer.interface, dump_mode) catch |
| 1363 | 1363 | return d.fatal("unable to write result: {s}", .{errorDescription(file_writer.err.?)}); |
| 1364 | 1364 | |
| ... | ... | @@ -1459,7 +1459,7 @@ fn processSource( |
| 1459 | 1459 | return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) }); |
| 1460 | 1460 | defer out_file.close(io); |
| 1461 | 1461 | |
| 1462 | var file_writer = out_file.writer(&writer_buf); | |
| 1462 | var file_writer = out_file.writer(io, &writer_buf); | |
| 1463 | 1463 | obj.finish(&file_writer.interface) catch |
| 1464 | 1464 | return d.fatal("could not output to object file '{s}': {s}", .{ out_file_name, errorDescription(file_writer.err.?) }); |
| 1465 | 1465 | } |
lib/compiler/aro/aro/Driver/Filesystem.zig+4-4| ... | ... | @@ -57,8 +57,8 @@ fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool { |
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | fn canExecutePosix(path: []const u8) bool { | |
| 61 | std.posix.access(path, std.posix.X_OK) catch return false; | |
| 60 | fn canExecutePosix(io: Io, path: []const u8) bool { | |
| 61 | Io.Dir.accessAbsolute(io, path, .{ .execute = true }) catch return false; | |
| 62 | 62 | // Todo: ensure path is not a directory |
| 63 | 63 | return true; |
| 64 | 64 | } |
| ... | ... | @@ -172,10 +172,10 @@ pub const Filesystem = union(enum) { |
| 172 | 172 | } |
| 173 | 173 | }; |
| 174 | 174 | |
| 175 | pub fn exists(fs: Filesystem, path: []const u8) bool { | |
| 175 | pub fn exists(fs: Filesystem, io: Io, path: []const u8) bool { | |
| 176 | 176 | switch (fs) { |
| 177 | 177 | .real => |cwd| { |
| 178 | cwd.access(path, .{}) catch return false; | |
| 178 | cwd.access(io, path, .{}) catch return false; | |
| 179 | 179 | return true; |
| 180 | 180 | }, |
| 181 | 181 | .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 { |
| 501 | 501 | try d.includes.ensureUnusedCapacity(gpa, 1); |
| 502 | 502 | if (d.resource_dir) |resource_dir| { |
| 503 | 503 | const path = try std.fs.path.join(arena, &.{ resource_dir, "include" }); |
| 504 | comp.cwd.access(path, .{}) catch { | |
| 504 | comp.cwd.access(io, path, .{}) catch { | |
| 505 | 505 | return d.fatal("Aro builtin headers not found in provided -resource-dir", .{}); |
| 506 | 506 | }; |
| 507 | 507 | d.includes.appendAssumeCapacity(.{ .kind = .system, .path = path }); |
| ... | ... | @@ -512,7 +512,7 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void { |
| 512 | 512 | var base_dir = d.comp.cwd.openDir(io, dirname, .{}) catch continue; |
| 513 | 513 | defer base_dir.close(io); |
| 514 | 514 | |
| 515 | base_dir.access("include/stddef.h", .{}) catch continue; | |
| 515 | base_dir.access(io, "include/stddef.h", .{}) catch continue; | |
| 516 | 516 | const path = try std.fs.path.join(arena, &.{ dirname, "include" }); |
| 517 | 517 | d.includes.appendAssumeCapacity(.{ .kind = .system, .path = path }); |
| 518 | 518 | break; |
| ... | ... | @@ -524,12 +524,14 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void { |
| 524 | 524 | /// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned |
| 525 | 525 | pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 { |
| 526 | 526 | 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; | |
| 528 | 529 | } |
| 529 | 530 | |
| 530 | 531 | pub fn exists(tc: *const Toolchain, path: []const u8) bool { |
| 531 | 532 | 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; | |
| 533 | 535 | return true; |
| 534 | 536 | } |
| 535 | 537 | |
| ... | ... | @@ -547,7 +549,8 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool { |
| 547 | 549 | } |
| 548 | 550 | |
| 549 | 551 | 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; | |
| 551 | 554 | // Todo: ensure path is not a directory |
| 552 | 555 | return true; |
| 553 | 556 | } |
lib/compiler/aro/backend/Assembly.zig+2-2| ... | ... | @@ -12,8 +12,8 @@ pub fn deinit(self: *const Assembly, gpa: Allocator) void { |
| 12 | 12 | gpa.free(self.text); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | pub fn writeToFile(self: Assembly, file: Io.File) !void { | |
| 16 | var file_writer = file.writer(&.{}); | |
| 15 | pub fn writeToFile(self: Assembly, io: Io, file: Io.File) !void { | |
| 16 | var file_writer = file.writer(io, &.{}); | |
| 17 | 17 | |
| 18 | 18 | var buffers = [_][]const u8{ self.data, self.text }; |
| 19 | 19 | try file_writer.interface.writeSplatAll(&buffers, 1); |
lib/compiler/resinator/cli.zig+5-5| ... | ... | @@ -250,13 +250,13 @@ pub const Options = struct { |
| 250 | 250 | /// worlds' situation where we'll be compatible with most use-cases |
| 251 | 251 | /// of the .rc extension being omitted from the CLI args, but still |
| 252 | 252 | /// 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 { | |
| 254 | 254 | switch (options.input_source) { |
| 255 | 255 | .stdio => return, |
| 256 | 256 | .filename => {}, |
| 257 | 257 | } |
| 258 | 258 | 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) { | |
| 260 | 260 | error.FileNotFound => { |
| 261 | 261 | var filename_bytes = try options.allocator.alloc(u8, options.input_source.filename.len + 3); |
| 262 | 262 | @memcpy(filename_bytes[0..options.input_source.filename.len], options.input_source.filename); |
| ... | ... | @@ -2005,19 +2005,19 @@ test "maybeAppendRC" { |
| 2005 | 2005 | // appended. |
| 2006 | 2006 | var file = try tmp.dir.createFile(io, "foo", .{}); |
| 2007 | 2007 | file.close(io); |
| 2008 | try options.maybeAppendRC(tmp.dir); | |
| 2008 | try options.maybeAppendRC(io, tmp.dir); | |
| 2009 | 2009 | try std.testing.expectEqualStrings("foo", options.input_source.filename); |
| 2010 | 2010 | |
| 2011 | 2011 | // Now delete the file and try again. But this time change the input format |
| 2012 | 2012 | // to non-rc. |
| 2013 | 2013 | try tmp.dir.deleteFile("foo"); |
| 2014 | 2014 | options.input_format = .res; |
| 2015 | try options.maybeAppendRC(tmp.dir); | |
| 2015 | try options.maybeAppendRC(io, tmp.dir); | |
| 2016 | 2016 | try std.testing.expectEqualStrings("foo", options.input_source.filename); |
| 2017 | 2017 | |
| 2018 | 2018 | // Finally, reset the input format to rc. Since the verbatim name is no longer found |
| 2019 | 2019 | // and the input filename does not have an extension, .rc should get appended. |
| 2020 | 2020 | options.input_format = .rc; |
| 2021 | try options.maybeAppendRC(tmp.dir); | |
| 2021 | try options.maybeAppendRC(io, tmp.dir); | |
| 2022 | 2022 | try std.testing.expectEqualStrings("foo.rc", options.input_source.filename); |
| 2023 | 2023 | } |
lib/compiler/resinator/main.zig+3-3| ... | ... | @@ -318,7 +318,7 @@ pub fn main() !void { |
| 318 | 318 | defer depfile.close(io); |
| 319 | 319 | |
| 320 | 320 | var depfile_buffer: [1024]u8 = undefined; |
| 321 | var depfile_writer = depfile.writer(&depfile_buffer); | |
| 321 | var depfile_writer = depfile.writer(io, &depfile_buffer); | |
| 322 | 322 | switch (options.depfile_fmt) { |
| 323 | 323 | .json => { |
| 324 | 324 | var write_stream: std.json.Stringify = .{ |
| ... | ... | @@ -521,9 +521,9 @@ const IoStream = struct { |
| 521 | 521 | } |
| 522 | 522 | }; |
| 523 | 523 | |
| 524 | pub fn writer(source: *Source, allocator: Allocator, buffer: []u8) Writer { | |
| 524 | pub fn writer(source: *Source, allocator: Allocator, io: Io, buffer: []u8) Writer { | |
| 525 | 525 | return switch (source.*) { |
| 526 | .file, .stdio => |file| .{ .file = file.writer(buffer) }, | |
| 526 | .file, .stdio => |file| .{ .file = file.writer(io, buffer) }, | |
| 527 | 527 | .memory => |*list| .{ .allocating = .fromArrayList(allocator, list) }, |
| 528 | 528 | .closed => unreachable, |
| 529 | 529 | }; |
lib/compiler/std-docs.zig+4-4| ... | ... | @@ -334,8 +334,8 @@ fn buildWasmBinary( |
| 334 | 334 | }); |
| 335 | 335 | defer poller.deinit(); |
| 336 | 336 | |
| 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); | |
| 339 | 339 | |
| 340 | 340 | var result: ?Cache.Path = null; |
| 341 | 341 | var result_error_bundle = std.zig.ErrorBundle.empty; |
| ... | ... | @@ -421,12 +421,12 @@ fn buildWasmBinary( |
| 421 | 421 | }; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | fn sendMessage(file: std.Io.File, tag: std.zig.Client.Message.Tag) !void { | |
| 424 | fn sendMessage(io: Io, file: std.Io.File, tag: std.zig.Client.Message.Tag) !void { | |
| 425 | 425 | const header: std.zig.Client.Message.Header = .{ |
| 426 | 426 | .tag = tag, |
| 427 | 427 | .bytes_len = 0, |
| 428 | 428 | }; |
| 429 | var w = file.writer(&.{}); | |
| 429 | var w = file.writer(io, &.{}); | |
| 430 | 430 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 431 | 431 | error.WriteFailed => return w.err.?, |
| 432 | 432 | }; |
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 |
| 232 | 232 | Io.File.stdout(); |
| 233 | 233 | defer if (dep_file_name != null) file.close(io); |
| 234 | 234 | |
| 235 | var file_writer = file.writer(&out_buf); | |
| 235 | var file_writer = file.writer(io, &out_buf); | |
| 236 | 236 | dep_file.write(&file_writer.interface) catch |
| 237 | 237 | return d.fatal("unable to write dependency file: {s}", .{aro.Driver.errorDescription(file_writer.err.?)}); |
| 238 | 238 | } |
| ... | ... | @@ -263,7 +263,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration |
| 263 | 263 | out_file_path = path; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | var out_writer = out_file.writer(&out_buf); | |
| 266 | var out_writer = out_file.writer(io, &out_buf); | |
| 267 | 267 | out_writer.interface.writeAll(rendered_zig) catch {}; |
| 268 | 268 | out_writer.interface.flush() catch {}; |
| 269 | 269 | if (out_writer.err) |write_err| |
lib/std/Build.zig+1-1| ... | ... | @@ -1699,7 +1699,7 @@ pub fn addCheckFile( |
| 1699 | 1699 | return Step.CheckFile.create(b, file_source, options); |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatFileError)!void { | |
| 1702 | pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatPathError)!void { | |
| 1703 | 1703 | const io = b.graph.io; |
| 1704 | 1704 | if (b.verbose) log.info("truncate {s}", .{dest_path}); |
| 1705 | 1705 | const cwd = Io.Dir.cwd(); |
lib/std/Build/Cache/Path.zig+2-2| ... | ... | @@ -118,14 +118,14 @@ pub fn atomicFile( |
| 118 | 118 | return p.root_dir.handle.atomicFile(joined_path, options); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | pub fn access(p: Path, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void { | |
| 121 | pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void { | |
| 122 | 122 | var buf: [fs.max_path_bytes]u8 = undefined; |
| 123 | 123 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 124 | 124 | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 125 | 125 | p.sub_path, sub_path, |
| 126 | 126 | }) catch return error.NameTooLong; |
| 127 | 127 | }; |
| 128 | return p.root_dir.handle.access(joined_path, flags); | |
| 128 | return p.root_dir.handle.access(io, joined_path, flags); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | pub 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 |
| 519 | 519 | /// Wrapper around `Io.Dir.makePathStatus` that handles verbose and error output. |
| 520 | 520 | pub fn installDir(s: *Step, dest_path: []const u8) !Io.Dir.MakePathStatus { |
| 521 | 521 | const b = s.owner; |
| 522 | const io = b.graph.io; | |
| 522 | 523 | 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| | |
| 524 | 525 | return s.fail("unable to create dir '{s}': {t}", .{ dest_path, err }); |
| 525 | 526 | } |
| 526 | 527 | |
| 527 | 528 | fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool, web_server: ?*Build.WebServer, gpa: Allocator) !?Path { |
| 528 | 529 | const b = s.owner; |
| 529 | 530 | const arena = b.allocator; |
| 531 | const io = b.graph.io; | |
| 530 | 532 | |
| 531 | 533 | var timer = try std.time.Timer.start(); |
| 532 | 534 | |
| 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); | |
| 535 | 537 | |
| 536 | 538 | var result: ?Path = null; |
| 537 | 539 | |
| ... | ... | @@ -668,12 +670,12 @@ fn clearZigProcess(s: *Step, gpa: Allocator) void { |
| 668 | 670 | } |
| 669 | 671 | } |
| 670 | 672 | |
| 671 | fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void { | |
| 673 | fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void { | |
| 672 | 674 | const header: std.zig.Client.Message.Header = .{ |
| 673 | 675 | .tag = tag, |
| 674 | 676 | .bytes_len = 0, |
| 675 | 677 | }; |
| 676 | var w = file.writer(&.{}); | |
| 678 | var w = file.writer(io, &.{}); | |
| 677 | 679 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 678 | 680 | error.WriteFailed => return w.err.?, |
| 679 | 681 | }; |
lib/std/Build/Step/InstallDir.zig+1-1| ... | ... | @@ -71,7 +71,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 71 | 71 | defer src_dir.close(io); |
| 72 | 72 | var it = try src_dir.walk(arena); |
| 73 | 73 | var all_cached = true; |
| 74 | next_entry: while (try it.next()) |entry| { | |
| 74 | next_entry: while (try it.next(io)) |entry| { | |
| 75 | 75 | for (install_dir.options.exclude_extensions) |ext| { |
| 76 | 76 | if (mem.endsWith(u8, entry.path, ext)) continue :next_entry; |
| 77 | 77 | } |
lib/std/Build/Step/Run.zig+25-22| ... | ... | @@ -1310,7 +1310,7 @@ fn runCommand( |
| 1310 | 1310 | const need_cross_libc = exe.is_linking_libc and |
| 1311 | 1311 | (root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic)); |
| 1312 | 1312 | 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, .{ | |
| 1314 | 1314 | .qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null, |
| 1315 | 1315 | .link_libc = exe.is_linking_libc, |
| 1316 | 1316 | })) { |
| ... | ... | @@ -1702,7 +1702,7 @@ fn evalZigTest( |
| 1702 | 1702 | }); |
| 1703 | 1703 | var child_killed = false; |
| 1704 | 1704 | defer if (!child_killed) { |
| 1705 | _ = child.kill() catch {}; | |
| 1705 | _ = child.kill(io) catch {}; | |
| 1706 | 1706 | poller.deinit(); |
| 1707 | 1707 | run.step.result_peak_rss = @max( |
| 1708 | 1708 | run.step.result_peak_rss, |
| ... | ... | @@ -1732,7 +1732,7 @@ fn evalZigTest( |
| 1732 | 1732 | child.stdin = null; |
| 1733 | 1733 | poller.deinit(); |
| 1734 | 1734 | child_killed = true; |
| 1735 | const term = try child.wait(); | |
| 1735 | const term = try child.wait(io); | |
| 1736 | 1736 | run.step.result_peak_rss = @max( |
| 1737 | 1737 | run.step.result_peak_rss, |
| 1738 | 1738 | child.resource_usage_statistics.getMaxRss() orelse 0, |
| ... | ... | @@ -1752,7 +1752,7 @@ fn evalZigTest( |
| 1752 | 1752 | child.stdin = null; |
| 1753 | 1753 | poller.deinit(); |
| 1754 | 1754 | child_killed = true; |
| 1755 | const term = try child.wait(); | |
| 1755 | const term = try child.wait(io); | |
| 1756 | 1756 | run.step.result_peak_rss = @max( |
| 1757 | 1757 | run.step.result_peak_rss, |
| 1758 | 1758 | child.resource_usage_statistics.getMaxRss() orelse 0, |
| ... | ... | @@ -1840,6 +1840,7 @@ fn pollZigTest( |
| 1840 | 1840 | switch (ctx.fuzz.mode) { |
| 1841 | 1841 | .forever => { |
| 1842 | 1842 | sendRunFuzzTestMessage( |
| 1843 | io, | |
| 1843 | 1844 | child.stdin.?, |
| 1844 | 1845 | ctx.unit_test_index, |
| 1845 | 1846 | .forever, |
| ... | ... | @@ -1848,6 +1849,7 @@ fn pollZigTest( |
| 1848 | 1849 | }, |
| 1849 | 1850 | .limit => |limit| { |
| 1850 | 1851 | sendRunFuzzTestMessage( |
| 1852 | io, | |
| 1851 | 1853 | child.stdin.?, |
| 1852 | 1854 | ctx.unit_test_index, |
| 1853 | 1855 | .iterations, |
| ... | ... | @@ -1857,11 +1859,11 @@ fn pollZigTest( |
| 1857 | 1859 | } |
| 1858 | 1860 | } else if (opt_metadata.*) |*md| { |
| 1859 | 1861 | // 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 }; | |
| 1861 | 1863 | } else { |
| 1862 | 1864 | // Running unit tests normally |
| 1863 | 1865 | 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 }; | |
| 1865 | 1867 | } |
| 1866 | 1868 | |
| 1867 | 1869 | var active_test_index: ?u32 = null; |
| ... | ... | @@ -1977,7 +1979,7 @@ fn pollZigTest( |
| 1977 | 1979 | active_test_index = null; |
| 1978 | 1980 | if (timer) |*t| t.reset(); |
| 1979 | 1981 | |
| 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 }; | |
| 1981 | 1983 | }, |
| 1982 | 1984 | .test_started => { |
| 1983 | 1985 | active_test_index = opt_metadata.*.?.next_index - 1; |
| ... | ... | @@ -2026,7 +2028,7 @@ fn pollZigTest( |
| 2026 | 2028 | active_test_index = null; |
| 2027 | 2029 | if (timer) |*t| md.ns_per_test[tr_hdr.index] = t.lap(); |
| 2028 | 2030 | |
| 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 }; | |
| 2030 | 2032 | }, |
| 2031 | 2033 | .coverage_id => { |
| 2032 | 2034 | coverage_id = body_r.takeInt(u64, .little) catch unreachable; |
| ... | ... | @@ -2097,7 +2099,7 @@ pub const CachedTestMetadata = struct { |
| 2097 | 2099 | } |
| 2098 | 2100 | }; |
| 2099 | 2101 | |
| 2100 | fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void { | |
| 2102 | fn requestNextTest(io: Io, in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void { | |
| 2101 | 2103 | while (metadata.next_index < metadata.names.len) { |
| 2102 | 2104 | const i = metadata.next_index; |
| 2103 | 2105 | metadata.next_index += 1; |
| ... | ... | @@ -2108,31 +2110,31 @@ fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Pr |
| 2108 | 2110 | if (sub_prog_node.*) |n| n.end(); |
| 2109 | 2111 | sub_prog_node.* = metadata.prog_node.start(name, 0); |
| 2110 | 2112 | |
| 2111 | try sendRunTestMessage(in, .run_test, i); | |
| 2113 | try sendRunTestMessage(io, in, .run_test, i); | |
| 2112 | 2114 | return; |
| 2113 | 2115 | } else { |
| 2114 | 2116 | metadata.next_index = std.math.maxInt(u32); // indicate that all tests are done |
| 2115 | try sendMessage(in, .exit); | |
| 2117 | try sendMessage(io, in, .exit); | |
| 2116 | 2118 | } |
| 2117 | 2119 | } |
| 2118 | 2120 | |
| 2119 | fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void { | |
| 2121 | fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void { | |
| 2120 | 2122 | const header: std.zig.Client.Message.Header = .{ |
| 2121 | 2123 | .tag = tag, |
| 2122 | 2124 | .bytes_len = 0, |
| 2123 | 2125 | }; |
| 2124 | var w = file.writer(&.{}); | |
| 2126 | var w = file.writer(io, &.{}); | |
| 2125 | 2127 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 2126 | 2128 | error.WriteFailed => return w.err.?, |
| 2127 | 2129 | }; |
| 2128 | 2130 | } |
| 2129 | 2131 | |
| 2130 | fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void { | |
| 2132 | fn sendRunTestMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void { | |
| 2131 | 2133 | const header: std.zig.Client.Message.Header = .{ |
| 2132 | 2134 | .tag = tag, |
| 2133 | 2135 | .bytes_len = 4, |
| 2134 | 2136 | }; |
| 2135 | var w = file.writer(&.{}); | |
| 2137 | var w = file.writer(io, &.{}); | |
| 2136 | 2138 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 2137 | 2139 | error.WriteFailed => return w.err.?, |
| 2138 | 2140 | }; |
| ... | ... | @@ -2142,6 +2144,7 @@ fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32 |
| 2142 | 2144 | } |
| 2143 | 2145 | |
| 2144 | 2146 | fn sendRunFuzzTestMessage( |
| 2147 | io: Io, | |
| 2145 | 2148 | file: Io.File, |
| 2146 | 2149 | index: u32, |
| 2147 | 2150 | kind: std.Build.abi.fuzz.LimitKind, |
| ... | ... | @@ -2151,7 +2154,7 @@ fn sendRunFuzzTestMessage( |
| 2151 | 2154 | .tag = .start_fuzzing, |
| 2152 | 2155 | .bytes_len = 4 + 1 + 8, |
| 2153 | 2156 | }; |
| 2154 | var w = file.writer(&.{}); | |
| 2157 | var w = file.writer(io, &.{}); | |
| 2155 | 2158 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 2156 | 2159 | error.WriteFailed => return w.err.?, |
| 2157 | 2160 | }; |
| ... | ... | @@ -2172,14 +2175,14 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { |
| 2172 | 2175 | const arena = b.allocator; |
| 2173 | 2176 | |
| 2174 | 2177 | try child.spawn(); |
| 2175 | errdefer _ = child.kill() catch {}; | |
| 2178 | errdefer _ = child.kill(io) catch {}; | |
| 2176 | 2179 | |
| 2177 | 2180 | try child.waitForSpawn(); |
| 2178 | 2181 | |
| 2179 | 2182 | switch (run.stdin) { |
| 2180 | 2183 | .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}); | |
| 2183 | 2186 | }; |
| 2184 | 2187 | child.stdin.?.close(io); |
| 2185 | 2188 | child.stdin = null; |
| ... | ... | @@ -2187,14 +2190,14 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { |
| 2187 | 2190 | .lazy_path => |lazy_path| { |
| 2188 | 2191 | const path = lazy_path.getPath3(b, &run.step); |
| 2189 | 2192 | 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}); | |
| 2191 | 2194 | }; |
| 2192 | 2195 | defer file.close(io); |
| 2193 | 2196 | // TODO https://github.com/ziglang/zig/issues/23955 |
| 2194 | 2197 | var read_buffer: [1024]u8 = undefined; |
| 2195 | 2198 | var file_reader = file.reader(io, &read_buffer); |
| 2196 | 2199 | 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); | |
| 2198 | 2201 | _ = stdin_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) { |
| 2199 | 2202 | error.ReadFailed => return run.step.fail("failed to read from {f}: {t}", .{ |
| 2200 | 2203 | path, file_reader.err.?, |
| ... | ... | @@ -2267,7 +2270,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { |
| 2267 | 2270 | run.step.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0; |
| 2268 | 2271 | |
| 2269 | 2272 | return .{ |
| 2270 | .term = try child.wait(), | |
| 2273 | .term = try child.wait(io), | |
| 2271 | 2274 | .stdout = stdout_bytes, |
| 2272 | 2275 | .stderr = stderr_bytes, |
| 2273 | 2276 | }; |
lib/std/Build/Step/WriteFile.zig+3-6| ... | ... | @@ -228,7 +228,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 228 | 228 | |
| 229 | 229 | var it = try src_dir.walk(gpa); |
| 230 | 230 | defer it.deinit(); |
| 231 | while (try it.next()) |entry| { | |
| 231 | while (try it.next(io)) |entry| { | |
| 232 | 232 | if (!dir.options.pathIncluded(entry.path)) continue; |
| 233 | 233 | |
| 234 | 234 | switch (entry.kind) { |
| ... | ... | @@ -259,11 +259,8 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 259 | 259 | |
| 260 | 260 | write_file.generated_directory.path = try b.cache_root.join(arena, &.{ "o", &digest }); |
| 261 | 261 | |
| 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 }); | |
| 267 | 264 | defer cache_dir.close(io); |
| 268 | 265 | |
| 269 | 266 | for (write_file.files.items) |file| { |
lib/std/Io.zig+2-2| ... | ... | @@ -664,13 +664,13 @@ pub const VTable = struct { |
| 664 | 664 | |
| 665 | 665 | dirMake: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions) Dir.MakeError!void, |
| 666 | 666 | 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, | |
| 668 | 669 | dirStat: *const fn (?*anyopaque, Dir) Dir.StatError!Dir.Stat, |
| 669 | 670 | dirStatPath: *const fn (?*anyopaque, Dir, []const u8, Dir.StatPathOptions) Dir.StatPathError!File.Stat, |
| 670 | 671 | dirAccess: *const fn (?*anyopaque, Dir, []const u8, Dir.AccessOptions) Dir.AccessError!void, |
| 671 | 672 | dirCreateFile: *const fn (?*anyopaque, Dir, []const u8, File.CreateFlags) File.OpenError!File, |
| 672 | 673 | 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, | |
| 674 | 674 | dirClose: *const fn (?*anyopaque, []const Dir) void, |
| 675 | 675 | dirRead: *const fn (?*anyopaque, *Dir.Reader, []Dir.Entry) Dir.Reader.Error!usize, |
| 676 | 676 | 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 { |
| 191 | 191 | while (self.stack.items.len > 0) { |
| 192 | 192 | const top = &self.stack.items[self.stack.items.len - 1]; |
| 193 | 193 | var dirname_len = top.dirname_len; |
| 194 | if (top.iter.next() catch |err| { | |
| 194 | if (top.iter.next(io) catch |err| { | |
| 195 | 195 | // If we get an error, then we want the user to be able to continue |
| 196 | 196 | // walking if they want, which means that we need to pop the directory |
| 197 | 197 | // that errored from the stack. Otherwise, all future `next` calls would |
| ... | ... | @@ -302,7 +302,7 @@ pub const Walker = struct { |
| 302 | 302 | dir: Dir, |
| 303 | 303 | basename: [:0]const u8, |
| 304 | 304 | path: [:0]const u8, |
| 305 | kind: Dir.Entry.Kind, | |
| 305 | kind: File.Kind, | |
| 306 | 306 | |
| 307 | 307 | /// Returns the depth of the entry relative to the initial directory. |
| 308 | 308 | /// Returns 1 for a direct child of the initial directory, 2 for an entry |
| ... | ... | @@ -320,10 +320,10 @@ pub const Walker = struct { |
| 320 | 320 | /// After each call to this function, and on deinit(), the memory returned |
| 321 | 321 | /// from this function becomes invalid. A copy must be made in order to keep |
| 322 | 322 | /// 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); | |
| 325 | 325 | if (entry != null and entry.?.kind == .directory) { |
| 326 | try self.inner.enter(entry.?); | |
| 326 | try self.inner.enter(io, entry.?); | |
| 327 | 327 | } |
| 328 | 328 | return entry; |
| 329 | 329 | } |
| ... | ... | @@ -495,7 +495,7 @@ pub const WriteFileOptions = struct { |
| 495 | 495 | flags: File.CreateFlags = .{}, |
| 496 | 496 | }; |
| 497 | 497 | |
| 498 | pub const WriteFileError = File.WriteError || File.OpenError; | |
| 498 | pub const WriteFileError = File.Writer.Error || File.OpenError; | |
| 499 | 499 | |
| 500 | 500 | /// Writes content to the file system, using the file creation flags provided. |
| 501 | 501 | pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void { |
| ... | ... | @@ -556,11 +556,11 @@ pub fn updateFile( |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | if (path.dirname(dest_path)) |dirname| { |
| 559 | try dest_dir.makePath(io, dirname, .default_dir); | |
| 559 | try dest_dir.makePath(io, dirname); | |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | 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, .{ | |
| 564 | 564 | .permissions = actual_permissions, |
| 565 | 565 | .write_buffer = &buffer, |
| 566 | 566 | }); |
lib/std/Io/Threaded.zig+9-4| ... | ... | @@ -12,7 +12,7 @@ const std = @import("../std.zig"); |
| 12 | 12 | const Io = std.Io; |
| 13 | 13 | const net = std.Io.net; |
| 14 | 14 | const File = std.Io.File; |
| 15 | const Dir = std.Dir; | |
| 15 | const Dir = std.Io.Dir; | |
| 16 | 16 | const HostName = std.Io.net.HostName; |
| 17 | 17 | const IpAddress = std.Io.net.IpAddress; |
| 18 | 18 | const Allocator = std.mem.Allocator; |
| ... | ... | @@ -1614,13 +1614,14 @@ fn dirMakeOpenPathPosix( |
| 1614 | 1614 | userdata: ?*anyopaque, |
| 1615 | 1615 | dir: Dir, |
| 1616 | 1616 | sub_path: []const u8, |
| 1617 | permissions: Dir.Permissions, | |
| 1617 | 1618 | options: Dir.OpenOptions, |
| 1618 | 1619 | ) Dir.MakeOpenPathError!Dir { |
| 1619 | 1620 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 1620 | 1621 | 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) { | |
| 1622 | 1623 | error.FileNotFound => { |
| 1623 | try dir.makePath(t_io, sub_path); | |
| 1624 | _ = try dir.makePathStatus(t_io, sub_path, permissions); | |
| 1624 | 1625 | return dirOpenDirPosix(t, dir, sub_path, options); |
| 1625 | 1626 | }, |
| 1626 | 1627 | else => |e| return e, |
| ... | ... | @@ -1631,12 +1632,15 @@ fn dirMakeOpenPathWindows( |
| 1631 | 1632 | userdata: ?*anyopaque, |
| 1632 | 1633 | dir: Dir, |
| 1633 | 1634 | sub_path: []const u8, |
| 1635 | permissions: Dir.Permissions, | |
| 1634 | 1636 | options: Dir.OpenOptions, |
| 1635 | 1637 | ) Dir.MakeOpenPathError!Dir { |
| 1636 | 1638 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 1637 | 1639 | const current_thread = Thread.getCurrent(t); |
| 1638 | 1640 | const w = windows; |
| 1639 | 1641 | |
| 1642 | _ = permissions; // TODO apply these permissions | |
| 1643 | ||
| 1640 | 1644 | var it = std.fs.path.componentIterator(sub_path); |
| 1641 | 1645 | // If there are no components in the path, then create a dummy component with the full path. |
| 1642 | 1646 | var component: std.fs.path.NativeComponentIterator.Component = it.last() orelse .{ |
| ... | ... | @@ -1746,13 +1750,14 @@ fn dirMakeOpenPathWasi( |
| 1746 | 1750 | userdata: ?*anyopaque, |
| 1747 | 1751 | dir: Dir, |
| 1748 | 1752 | sub_path: []const u8, |
| 1753 | permissions: Dir.Permissions, | |
| 1749 | 1754 | options: Dir.OpenOptions, |
| 1750 | 1755 | ) Dir.MakeOpenPathError!Dir { |
| 1751 | 1756 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 1752 | 1757 | const t_io = ioBasic(t); |
| 1753 | 1758 | return dirOpenDirWasi(t, dir, sub_path, options) catch |err| switch (err) { |
| 1754 | 1759 | error.FileNotFound => { |
| 1755 | try dir.makePath(t_io, sub_path); | |
| 1760 | _ = try dir.makePathStatus(t_io, sub_path, permissions); | |
| 1756 | 1761 | return dirOpenDirWasi(t, dir, sub_path, options); |
| 1757 | 1762 | }, |
| 1758 | 1763 | else => |e| return e, |
lib/std/Io/test.zig+1-1| ... | ... | @@ -30,7 +30,7 @@ test "write a file, read it, then delete it" { |
| 30 | 30 | var file = try tmp.dir.createFile(io, tmp_file_name, .{}); |
| 31 | 31 | defer file.close(io); |
| 32 | 32 | |
| 33 | var file_writer = file.writer(&.{}); | |
| 33 | var file_writer = file.writer(io, &.{}); | |
| 34 | 34 | const st = &file_writer.interface; |
| 35 | 35 | try st.print("begin", .{}); |
| 36 | 36 | try st.writeAll(&data); |
lib/std/debug.zig+4-4| ... | ... | @@ -1279,7 +1279,7 @@ test printLineFromFile { |
| 1279 | 1279 | |
| 1280 | 1280 | const overlap = 10; |
| 1281 | 1281 | var buf: [16]u8 = undefined; |
| 1282 | var file_writer = file.writer(&buf); | |
| 1282 | var file_writer = file.writer(io, &buf); | |
| 1283 | 1283 | const writer = &file_writer.interface; |
| 1284 | 1284 | try writer.splatByteAll('a', std.heap.page_size_min - overlap); |
| 1285 | 1285 | try writer.writeByte('\n'); |
| ... | ... | @@ -1296,7 +1296,7 @@ test printLineFromFile { |
| 1296 | 1296 | const path = try fs.path.join(gpa, &.{ test_dir_path, "file_ends_on_page_boundary.zig" }); |
| 1297 | 1297 | defer gpa.free(path); |
| 1298 | 1298 | |
| 1299 | var file_writer = file.writer(&.{}); | |
| 1299 | var file_writer = file.writer(io, &.{}); | |
| 1300 | 1300 | const writer = &file_writer.interface; |
| 1301 | 1301 | try writer.splatByteAll('a', std.heap.page_size_max); |
| 1302 | 1302 | |
| ... | ... | @@ -1310,7 +1310,7 @@ test printLineFromFile { |
| 1310 | 1310 | const path = try fs.path.join(gpa, &.{ test_dir_path, "very_long_first_line_spanning_multiple_pages.zig" }); |
| 1311 | 1311 | defer gpa.free(path); |
| 1312 | 1312 | |
| 1313 | var file_writer = file.writer(&.{}); | |
| 1313 | var file_writer = file.writer(io, &.{}); | |
| 1314 | 1314 | const writer = &file_writer.interface; |
| 1315 | 1315 | try writer.splatByteAll('a', 3 * std.heap.page_size_max); |
| 1316 | 1316 | |
| ... | ... | @@ -1336,7 +1336,7 @@ test printLineFromFile { |
| 1336 | 1336 | const path = try fs.path.join(gpa, &.{ test_dir_path, "file_of_newlines.zig" }); |
| 1337 | 1337 | defer gpa.free(path); |
| 1338 | 1338 | |
| 1339 | var file_writer = file.writer(&.{}); | |
| 1339 | var file_writer = file.writer(io, &.{}); | |
| 1340 | 1340 | const writer = &file_writer.interface; |
| 1341 | 1341 | const real_file_start = 3 * std.heap.page_size_min; |
| 1342 | 1342 | try writer.splatByteAll('\n', real_file_start); |
lib/std/fs/test.zig+12-12| ... | ... | @@ -1206,8 +1206,8 @@ test "deleteTree does not follow symlinks" { |
| 1206 | 1206 | |
| 1207 | 1207 | try tmp.dir.deleteTree("a"); |
| 1208 | 1208 | |
| 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", .{}); | |
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | test "deleteTree on a symlink" { |
| ... | ... | @@ -1221,16 +1221,16 @@ test "deleteTree on a symlink" { |
| 1221 | 1221 | try setupSymlink(tmp.dir, "file", "filelink", .{}); |
| 1222 | 1222 | |
| 1223 | 1223 | 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", .{}); | |
| 1226 | 1226 | |
| 1227 | 1227 | // Symlink to a directory |
| 1228 | 1228 | try tmp.dir.makePath(io, "dir"); |
| 1229 | 1229 | try setupSymlink(tmp.dir, "dir", "dirlink", .{ .is_directory = true }); |
| 1230 | 1230 | |
| 1231 | 1231 | 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", .{}); | |
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | test "makePath, put some files in it, deleteTree" { |
| ... | ... | @@ -1358,8 +1358,8 @@ test "makepath relative walks" { |
| 1358 | 1358 | // On Windows, .. is resolved before passing the path to NtCreateFile, |
| 1359 | 1359 | // meaning everything except `first/C` drops out. |
| 1360 | 1360 | 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", .{})); | |
| 1363 | 1363 | }, |
| 1364 | 1364 | else => { |
| 1365 | 1365 | try expectDir(io, tmp.dir, "first" ++ fs.path.sep_str ++ "A"); |
| ... | ... | @@ -1561,10 +1561,10 @@ test "access file" { |
| 1561 | 1561 | const file_path = try ctx.transformPath("os_test_tmp" ++ fs.path.sep_str ++ "file.txt"); |
| 1562 | 1562 | |
| 1563 | 1563 | 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, .{})); | |
| 1565 | 1565 | |
| 1566 | 1566 | try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "" }); |
| 1567 | try ctx.dir.access(file_path, .{}); | |
| 1567 | try ctx.dir.access(io, file_path, .{}); | |
| 1568 | 1568 | try ctx.dir.deleteTree(dir_path); |
| 1569 | 1569 | } |
| 1570 | 1570 | }.impl); |
| ... | ... | @@ -2036,13 +2036,13 @@ test "'.' and '..' in Io.Dir functions" { |
| 2036 | 2036 | const update_path = try ctx.transformPath("./subdir/../update"); |
| 2037 | 2037 | |
| 2038 | 2038 | try ctx.dir.makeDir(subdir_path); |
| 2039 | try ctx.dir.access(subdir_path, .{}); | |
| 2039 | try ctx.dir.access(io, subdir_path, .{}); | |
| 2040 | 2040 | var created_subdir = try ctx.dir.openDir(io, subdir_path, .{}); |
| 2041 | 2041 | created_subdir.close(io); |
| 2042 | 2042 | |
| 2043 | 2043 | const created_file = try ctx.dir.createFile(io, file_path, .{}); |
| 2044 | 2044 | created_file.close(io); |
| 2045 | try ctx.dir.access(file_path, .{}); | |
| 2045 | try ctx.dir.access(io, file_path, .{}); | |
| 2046 | 2046 | |
| 2047 | 2047 | try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{}); |
| 2048 | 2048 | 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 { |
| 2842 | 2842 | } |
| 2843 | 2843 | } |
| 2844 | 2844 | |
| 2845 | pub 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. | |
| 2870 | pub 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. | |
| 2881 | pub 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 | ||
| 2906 | 2845 | pub const PipeError = error{ |
| 2907 | 2846 | SystemFdQuotaExceeded, |
| 2908 | 2847 | ProcessFdQuotaExceeded, |
lib/std/posix/test.zig+7-5| ... | ... | @@ -376,7 +376,7 @@ test "mmap" { |
| 376 | 376 | const file = try tmp.dir.createFile(io, test_out_file, .{}); |
| 377 | 377 | defer file.close(io); |
| 378 | 378 | |
| 379 | var stream = file.writer(&.{}); | |
| 379 | var stream = file.writer(io, &.{}); | |
| 380 | 380 | |
| 381 | 381 | var i: usize = 0; |
| 382 | 382 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { |
| ... | ... | @@ -741,6 +741,8 @@ test "access smoke test" { |
| 741 | 741 | if (native_os == .windows) return error.SkipZigTest; |
| 742 | 742 | if (native_os == .openbsd) return error.SkipZigTest; |
| 743 | 743 | |
| 744 | const io = testing.io; | |
| 745 | ||
| 744 | 746 | var tmp = tmpDir(.{}); |
| 745 | 747 | defer tmp.cleanup(); |
| 746 | 748 | |
| ... | ... | @@ -761,9 +763,9 @@ test "access smoke test" { |
| 761 | 763 | const file_path = try fs.path.join(a, &.{ base_path, "some_file" }); |
| 762 | 764 | defer a.free(file_path); |
| 763 | 765 | if (native_os == .windows) { |
| 764 | try posix.access(file_path, posix.F_OK); | |
| 766 | try posix.access(io, file_path, posix.F_OK); | |
| 765 | 767 | } 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); | |
| 767 | 769 | } |
| 768 | 770 | } |
| 769 | 771 | |
| ... | ... | @@ -771,7 +773,7 @@ test "access smoke test" { |
| 771 | 773 | // Try to access() a non-existent file - should fail with error.FileNotFound |
| 772 | 774 | const file_path = try fs.path.join(a, &.{ base_path, "some_other_file" }); |
| 773 | 775 | 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)); | |
| 775 | 777 | } |
| 776 | 778 | |
| 777 | 779 | { |
| ... | ... | @@ -786,7 +788,7 @@ test "access smoke test" { |
| 786 | 788 | const file_path = try fs.path.join(a, &.{ base_path, "some_dir" }); |
| 787 | 789 | defer a.free(file_path); |
| 788 | 790 | |
| 789 | try posix.access(file_path, posix.F_OK); | |
| 791 | try posix.access(io, file_path, posix.F_OK); | |
| 790 | 792 | } |
| 791 | 793 | } |
| 792 | 794 |
lib/std/zig/LibCInstallation.zig+5-5| ... | ... | @@ -357,7 +357,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | 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, .{})) |_| { | |
| 361 | 361 | self.sys_include_dir = try allocator.dupeZ(u8, search_path); |
| 362 | 362 | } else |err| switch (err) { |
| 363 | 363 | error.FileNotFound => {}, |
| ... | ... | @@ -402,7 +402,7 @@ fn findNativeIncludeDirWindows( |
| 402 | 402 | }; |
| 403 | 403 | defer dir.close(io); |
| 404 | 404 | |
| 405 | dir.access("stdlib.h", .{}) catch |err| switch (err) { | |
| 405 | dir.access(io, "stdlib.h", .{}) catch |err| switch (err) { | |
| 406 | 406 | error.FileNotFound => continue, |
| 407 | 407 | else => return error.FileSystem, |
| 408 | 408 | }; |
| ... | ... | @@ -450,7 +450,7 @@ fn findNativeCrtDirWindows( |
| 450 | 450 | }; |
| 451 | 451 | defer dir.close(io); |
| 452 | 452 | |
| 453 | dir.access("ucrt.lib", .{}) catch |err| switch (err) { | |
| 453 | dir.access(io, "ucrt.lib", .{}) catch |err| switch (err) { | |
| 454 | 454 | error.FileNotFound => continue, |
| 455 | 455 | else => return error.FileSystem, |
| 456 | 456 | }; |
| ... | ... | @@ -518,7 +518,7 @@ fn findNativeKernel32LibDir( |
| 518 | 518 | }; |
| 519 | 519 | defer dir.close(io); |
| 520 | 520 | |
| 521 | dir.access("kernel32.lib", .{}) catch |err| switch (err) { | |
| 521 | dir.access(io, "kernel32.lib", .{}) catch |err| switch (err) { | |
| 522 | 522 | error.FileNotFound => continue, |
| 523 | 523 | else => return error.FileSystem, |
| 524 | 524 | }; |
| ... | ... | @@ -554,7 +554,7 @@ fn findNativeMsvcIncludeDir( |
| 554 | 554 | }; |
| 555 | 555 | defer dir.close(io); |
| 556 | 556 | |
| 557 | dir.access("vcruntime.h", .{}) catch |err| switch (err) { | |
| 557 | dir.access(io, "vcruntime.h", .{}) catch |err| switch (err) { | |
| 558 | 558 | error.FileNotFound => return error.LibCStdLibHeaderNotFound, |
| 559 | 559 | else => return error.FileSystem, |
| 560 | 560 | }; |
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 |
| 9589 | 9589 | try b.printToFile(io, file, &buffer); |
| 9590 | 9590 | } |
| 9591 | 9591 | |
| 9592 | pub fn printToFile(b: *Builder, file: Io.File, buffer: []u8) !void { | |
| 9593 | var fw = file.writer(buffer); | |
| 9592 | pub fn printToFile(b: *Builder, io: Io, file: Io.File, buffer: []u8) !void { | |
| 9593 | var fw = file.writer(io, buffer); | |
| 9594 | 9594 | try print(b, &fw.interface); |
| 9595 | 9595 | try fw.interface.flush(); |
| 9596 | 9596 | } |
lib/std/zig/system.zig+2-1| ... | ... | @@ -40,6 +40,7 @@ pub const GetExternalExecutorOptions = struct { |
| 40 | 40 | /// Return whether or not the given host is capable of running executables of |
| 41 | 41 | /// the other target. |
| 42 | 42 | pub fn getExternalExecutor( |
| 43 | io: Io, | |
| 43 | 44 | host: *const std.Target, |
| 44 | 45 | candidate: *const std.Target, |
| 45 | 46 | options: GetExternalExecutorOptions, |
| ... | ... | @@ -70,7 +71,7 @@ pub fn getExternalExecutor( |
| 70 | 71 | if (os_match and cpu_ok) native: { |
| 71 | 72 | if (options.link_libc) { |
| 72 | 73 | if (candidate.dynamic_linker.get()) |candidate_dl| { |
| 73 | Io.Dir.cwd().access(candidate_dl, .{}) catch { | |
| 74 | Io.Dir.cwd().access(io, candidate_dl, .{}) catch { | |
| 74 | 75 | bad_result = .{ .bad_dl = candidate_dl }; |
| 75 | 76 | break :native; |
| 76 | 77 | }; |
src/Compilation.zig+1-1| ... | ... | @@ -788,7 +788,7 @@ pub const Directories = struct { |
| 788 | 788 | const local_cache: Cache.Directory = switch (local_cache_strat) { |
| 789 | 789 | .override => |path| openUnresolved(arena, io, cwd, path, .@"local cache"), |
| 790 | 790 | .search => d: { |
| 791 | const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, cwd) catch |err| { | |
| 791 | const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, io, cwd) catch |err| { | |
| 792 | 792 | fatal("unable to resolve zig cache directory: {s}", .{@errorName(err)}); |
| 793 | 793 | }; |
| 794 | 794 | 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 { |
| 418 | 418 | const prefixed_pkg_sub_path = prefixed_pkg_sub_path_buffer[0 .. 2 + hash_slice.len]; |
| 419 | 419 | const prefix_len: usize = if (f.job_queue.read_only) "p/".len else 0; |
| 420 | 420 | 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, .{})) |_| { | |
| 422 | 422 | assert(f.lazy_status != .unavailable); |
| 423 | 423 | f.package_root = .{ |
| 424 | 424 | .root_dir = cache_root, |
| ... | ... | @@ -637,8 +637,9 @@ pub fn computedPackageHash(f: *const Fetch) Package.Hash { |
| 637 | 637 | /// `computeHash` gets a free check for the existence of `build.zig`, but when |
| 638 | 638 | /// not computing a hash, we need to do a syscall to check for it. |
| 639 | 639 | fn checkBuildFileExistence(f: *Fetch) RunError!void { |
| 640 | const io = f.job_queue.io; | |
| 640 | 641 | 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, .{})) |_| { | |
| 642 | 643 | f.has_build_zig = true; |
| 643 | 644 | } else |err| switch (err) { |
| 644 | 645 | error.FileNotFound => {}, |
src/introspect.zig+2-2| ... | ... | @@ -202,11 +202,11 @@ pub const default_local_zig_cache_basename = ".zig-cache"; |
| 202 | 202 | /// Searches upwards from `cwd` for a directory containing a `build.zig` file. |
| 203 | 203 | /// If such a directory is found, returns the path to it joined to the `.zig_cache` name. |
| 204 | 204 | /// Otherwise, returns `null`, indicating no suitable local cache location. |
| 205 | pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator.Error!?[]u8 { | |
| 205 | pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 { | |
| 206 | 206 | var cur_dir = cwd; |
| 207 | 207 | while (true) { |
| 208 | 208 | 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, .{})) |_| { | |
| 210 | 210 | return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename }); |
| 211 | 211 | } else |err| switch (err) { |
| 212 | 212 | error.FileNotFound => { |
src/libs/mingw.zig+7-5| ... | ... | @@ -242,7 +242,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 242 | 242 | defer arena_allocator.deinit(); |
| 243 | 243 | const arena = arena_allocator.allocator(); |
| 244 | 244 | |
| 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) { | |
| 246 | 246 | error.FileNotFound => { |
| 247 | 247 | log.debug("no {s}.def file available to make a DLL import {s}.lib", .{ lib_name, lib_name }); |
| 248 | 248 | // 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 { |
| 402 | 402 | |
| 403 | 403 | pub fn libExists( |
| 404 | 404 | allocator: Allocator, |
| 405 | io: Io, | |
| 405 | 406 | target: *const std.Target, |
| 406 | 407 | zig_lib_directory: Cache.Directory, |
| 407 | 408 | lib_name: []const u8, |
| 408 | 409 | ) !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) { | |
| 410 | 411 | error.FileNotFound => return false, |
| 411 | 412 | else => |e| return e, |
| 412 | 413 | }; |
| ... | ... | @@ -418,6 +419,7 @@ pub fn libExists( |
| 418 | 419 | /// see if a .def file exists. |
| 419 | 420 | fn findDef( |
| 420 | 421 | allocator: Allocator, |
| 422 | io: Io, | |
| 421 | 423 | target: *const std.Target, |
| 422 | 424 | zig_lib_directory: Cache.Directory, |
| 423 | 425 | lib_name: []const u8, |
| ... | ... | @@ -443,7 +445,7 @@ fn findDef( |
| 443 | 445 | } else { |
| 444 | 446 | try override_path.print(fmt_path, .{ lib_path, lib_name }); |
| 445 | 447 | } |
| 446 | if (Io.Dir.cwd().access(override_path.items, .{})) |_| { | |
| 448 | if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| { | |
| 447 | 449 | return override_path.toOwnedSlice(); |
| 448 | 450 | } else |err| switch (err) { |
| 449 | 451 | error.FileNotFound => {}, |
| ... | ... | @@ -460,7 +462,7 @@ fn findDef( |
| 460 | 462 | } else { |
| 461 | 463 | try override_path.print(fmt_path, .{lib_name}); |
| 462 | 464 | } |
| 463 | if (Io.Dir.cwd().access(override_path.items, .{})) |_| { | |
| 465 | if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| { | |
| 464 | 466 | return override_path.toOwnedSlice(); |
| 465 | 467 | } else |err| switch (err) { |
| 466 | 468 | error.FileNotFound => {}, |
| ... | ... | @@ -477,7 +479,7 @@ fn findDef( |
| 477 | 479 | } else { |
| 478 | 480 | try override_path.print(fmt_path, .{lib_name}); |
| 479 | 481 | } |
| 480 | if (Io.Dir.cwd().access(override_path.items, .{})) |_| { | |
| 482 | if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| { | |
| 481 | 483 | return override_path.toOwnedSlice(); |
| 482 | 484 | } else |err| switch (err) { |
| 483 | 485 | 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 |
| 371 | 371 | const comp = self.base.comp; |
| 372 | 372 | const diags = &comp.link_diags; |
| 373 | 373 | const gpa = comp.gpa; |
| 374 | const io = comp.io; | |
| 374 | 375 | const zcu = self.base.comp.zcu.?; |
| 375 | 376 | const ip = &zcu.intern_pool; |
| 376 | 377 | 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 |
| 509 | 510 | |
| 510 | 511 | const file = self.base.file.?; |
| 511 | 512 | 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, &.{}); | |
| 513 | 514 | var w = &fw.interface; |
| 514 | 515 | w.writeVecAll(f.all_buffers.items) catch |err| switch (err) { |
| 515 | 516 | 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 { |
| 359 | 359 | fn coffLink(lld: *Lld, arena: Allocator) !void { |
| 360 | 360 | const comp = lld.base.comp; |
| 361 | 361 | const gpa = comp.gpa; |
| 362 | const io = comp.io; | |
| 362 | 363 | const base = &lld.base; |
| 363 | 364 | const coff = &lld.ofmt.coff; |
| 364 | 365 | |
| ... | ... | @@ -718,13 +719,13 @@ fn coffLink(lld: *Lld, arena: Allocator) !void { |
| 718 | 719 | argv.appendAssumeCapacity(try crt_file.full_object_path.toString(arena)); |
| 719 | 720 | continue; |
| 720 | 721 | } |
| 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| { | |
| 722 | 723 | argv.appendAssumeCapacity(full_path); |
| 723 | 724 | continue; |
| 724 | 725 | } |
| 725 | 726 | if (target.abi.isGnu()) { |
| 726 | 727 | 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| { | |
| 728 | 729 | argv.appendAssumeCapacity(full_path); |
| 729 | 730 | continue; |
| 730 | 731 | } |
| ... | ... | @@ -741,9 +742,9 @@ fn coffLink(lld: *Lld, arena: Allocator) !void { |
| 741 | 742 | try spawnLld(comp, arena, argv.items); |
| 742 | 743 | } |
| 743 | 744 | } |
| 744 | fn findLib(arena: Allocator, name: []const u8, lib_directories: []const Cache.Directory) !?[]const u8 { | |
| 745 | fn findLib(arena: Allocator, io: Io, name: []const u8, lib_directories: []const Cache.Directory) !?[]const u8 { | |
| 745 | 746 | 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) { | |
| 747 | 748 | error.FileNotFound => continue, |
| 748 | 749 | else => |e| return e, |
| 749 | 750 | }; |
src/link/MachO.zig+12-9| ... | ... | @@ -829,7 +829,8 @@ pub fn resolveLibSystem( |
| 829 | 829 | comp: *Compilation, |
| 830 | 830 | out_libs: anytype, |
| 831 | 831 | ) !void { |
| 832 | const diags = &self.base.comp.link_diags; | |
| 832 | const io = comp.io; | |
| 833 | const diags = &comp.link_diags; | |
| 833 | 834 | |
| 834 | 835 | var test_path = std.array_list.Managed(u8).init(arena); |
| 835 | 836 | var checked_paths = std.array_list.Managed([]const u8).init(arena); |
| ... | ... | @@ -838,16 +839,16 @@ pub fn resolveLibSystem( |
| 838 | 839 | if (self.sdk_layout) |sdk_layout| switch (sdk_layout) { |
| 839 | 840 | .sdk => { |
| 840 | 841 | 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; | |
| 842 | 843 | }, |
| 843 | 844 | .vendored => { |
| 844 | 845 | 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; | |
| 846 | 847 | }, |
| 847 | 848 | }; |
| 848 | 849 | |
| 849 | 850 | 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; | |
| 851 | 852 | } |
| 852 | 853 | |
| 853 | 854 | diags.addMissingLibraryError(checked_paths.items, "unable to find libSystem system library", .{}); |
| ... | ... | @@ -1074,6 +1075,7 @@ fn isHoisted(self: *MachO, install_name: []const u8) bool { |
| 1074 | 1075 | /// TODO delete this, libraries must be instead resolved when instantiating the compilation pipeline |
| 1075 | 1076 | fn accessLibPath( |
| 1076 | 1077 | arena: Allocator, |
| 1078 | io: Io, | |
| 1077 | 1079 | test_path: *std.array_list.Managed(u8), |
| 1078 | 1080 | checked_paths: *std.array_list.Managed([]const u8), |
| 1079 | 1081 | search_dir: []const u8, |
| ... | ... | @@ -1085,7 +1087,7 @@ fn accessLibPath( |
| 1085 | 1087 | test_path.clearRetainingCapacity(); |
| 1086 | 1088 | try test_path.print("{s}" ++ sep ++ "lib{s}{s}", .{ search_dir, name, ext }); |
| 1087 | 1089 | 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) { | |
| 1089 | 1091 | error.FileNotFound => continue, |
| 1090 | 1092 | else => |e| return e, |
| 1091 | 1093 | }; |
| ... | ... | @@ -1097,6 +1099,7 @@ fn accessLibPath( |
| 1097 | 1099 | |
| 1098 | 1100 | fn accessFrameworkPath( |
| 1099 | 1101 | arena: Allocator, |
| 1102 | io: Io, | |
| 1100 | 1103 | test_path: *std.array_list.Managed(u8), |
| 1101 | 1104 | checked_paths: *std.array_list.Managed([]const u8), |
| 1102 | 1105 | search_dir: []const u8, |
| ... | ... | @@ -1113,7 +1116,7 @@ fn accessFrameworkPath( |
| 1113 | 1116 | ext, |
| 1114 | 1117 | }); |
| 1115 | 1118 | 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) { | |
| 1117 | 1120 | error.FileNotFound => continue, |
| 1118 | 1121 | else => |e| return e, |
| 1119 | 1122 | }; |
| ... | ... | @@ -1172,14 +1175,14 @@ fn parseDependentDylibs(self: *MachO) !void { |
| 1172 | 1175 | // Framework |
| 1173 | 1176 | for (framework_dirs) |dir| { |
| 1174 | 1177 | 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; | |
| 1176 | 1179 | } |
| 1177 | 1180 | |
| 1178 | 1181 | // Library |
| 1179 | 1182 | const lib_name = eatPrefix(stem, "lib") orelse stem; |
| 1180 | 1183 | for (lib_directories) |lib_directory| { |
| 1181 | 1184 | 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; | |
| 1183 | 1186 | } |
| 1184 | 1187 | } |
| 1185 | 1188 | |
| ... | ... | @@ -1194,7 +1197,7 @@ fn parseDependentDylibs(self: *MachO) !void { |
| 1194 | 1197 | try test_path.print("{s}{s}", .{ path, ext }); |
| 1195 | 1198 | } |
| 1196 | 1199 | 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) { | |
| 1198 | 1201 | error.FileNotFound => continue, |
| 1199 | 1202 | else => |e| return e, |
| 1200 | 1203 | }; |
src/main.zig+5-3| ... | ... | @@ -3208,6 +3208,7 @@ fn buildOutputType( |
| 3208 | 3208 | |
| 3209 | 3209 | for (create_module.framework_dirs.items) |framework_dir_path| { |
| 3210 | 3210 | if (try accessFrameworkPath( |
| 3211 | io, | |
| 3211 | 3212 | &test_path, |
| 3212 | 3213 | &checked_paths, |
| 3213 | 3214 | framework_dir_path, |
| ... | ... | @@ -6626,7 +6627,7 @@ fn warnAboutForeignBinaries( |
| 6626 | 6627 | const host_query: std.Target.Query = .{}; |
| 6627 | 6628 | const host_target = std.zig.resolveTargetQueryOrFatal(io, host_query); |
| 6628 | 6629 | |
| 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 })) { | |
| 6630 | 6631 | .native => return, |
| 6631 | 6632 | .rosetta => { |
| 6632 | 6633 | const host_name = try host_target.zigTriple(arena); |
| ... | ... | @@ -6832,6 +6833,7 @@ const ClangSearchSanitizer = struct { |
| 6832 | 6833 | }; |
| 6833 | 6834 | |
| 6834 | 6835 | fn accessFrameworkPath( |
| 6836 | io: Io, | |
| 6835 | 6837 | test_path: *std.array_list.Managed(u8), |
| 6836 | 6838 | checked_paths: *std.array_list.Managed(u8), |
| 6837 | 6839 | framework_dir_path: []const u8, |
| ... | ... | @@ -6845,7 +6847,7 @@ fn accessFrameworkPath( |
| 6845 | 6847 | framework_dir_path, framework_name, framework_name, ext, |
| 6846 | 6848 | }); |
| 6847 | 6849 | 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) { | |
| 6849 | 6851 | error.FileNotFound => continue, |
| 6850 | 6852 | else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{ |
| 6851 | 6853 | ext, test_path.items, @errorName(e), |
| ... | ... | @@ -7280,7 +7282,7 @@ fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) !Build |
| 7280 | 7282 | var dirname: []const u8 = cwd_path; |
| 7281 | 7283 | while (true) { |
| 7282 | 7284 | 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, .{})) |_| { | |
| 7284 | 7286 | const dir = Io.Dir.cwd().openDir(io, dirname, .{}) catch |err| { |
| 7285 | 7287 | fatal("unable to open directory while searching for build.zig file, '{s}': {s}", .{ dirname, @errorName(err) }); |
| 7286 | 7288 | }; |