authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-11 23:18:42-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
log16f8af1b9a7a287ac6fdefec5949725c55cbe179
tree2a1a3e3fb9f7ad20da5480e1dc21a337b02830c4
parente1cf753db72425fd944f6fe9f2a991fb1de3f942

compiler: update various code to new fs API


32 files changed, 228 insertions(+), 219 deletions(-)

lib/compiler/aro/main.zig+1-1
......@@ -43,7 +43,7 @@ pub fn main() u8 {
4343 return 1;
4444 };
4545
46 const aro_name = std.fs.selfExePathAlloc(gpa) catch {
46 const aro_name = process.executablePathAlloc(io, gpa) catch {
4747 std.debug.print("unable to find Aro executable path\n", .{});
4848 if (fast_exit) process.exit(1);
4949 return 1;
lib/std/Build/Cache.zig+4-4
......@@ -1330,7 +1330,7 @@ test "cache file and then recall it" {
13301330 var cache: Cache = .{
13311331 .io = io,
13321332 .gpa = testing.allocator,
1333 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
1333 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
13341334 };
13351335 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
13361336 defer cache.manifest_dir.close(io);
......@@ -1396,7 +1396,7 @@ test "check that changing a file makes cache fail" {
13961396 var cache: Cache = .{
13971397 .io = io,
13981398 .gpa = testing.allocator,
1399 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
1399 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
14001400 };
14011401 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
14021402 defer cache.manifest_dir.close(io);
......@@ -1456,7 +1456,7 @@ test "no file inputs" {
14561456 var cache: Cache = .{
14571457 .io = io,
14581458 .gpa = testing.allocator,
1459 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
1459 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
14601460 };
14611461 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
14621462 defer cache.manifest_dir.close(io);
......@@ -1515,7 +1515,7 @@ test "Manifest with files added after initial hash work" {
15151515 var cache: Cache = .{
15161516 .io = io,
15171517 .gpa = testing.allocator,
1518 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),
1518 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
15191519 };
15201520 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
15211521 defer cache.manifest_dir.close(io);
lib/std/Build/Cache/Path.zig+2-2
......@@ -84,14 +84,14 @@ pub fn openDir(
8484 return p.root_dir.handle.openDir(io, joined_path, args);
8585}
8686
87pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir {
87pub fn makeOpenPath(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir {
8888 var buf: [fs.max_path_bytes]u8 = undefined;
8989 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
9090 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
9191 p.sub_path, sub_path,
9292 }) catch return error.NameTooLong;
9393 };
94 return p.root_dir.handle.makeOpenPath(joined_path, opts);
94 return p.root_dir.handle.makeOpenPath(io, joined_path, opts);
9595}
9696
9797pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {
lib/std/Io/Dir.zig+1-1
......@@ -1588,7 +1588,7 @@ pub const CopyFileOptions = struct {
15881588
15891589pub const CopyFileError = File.OpenError || File.StatError ||
15901590 File.Atomic.InitError || File.Atomic.FinishError ||
1591 File.Reader.Error || File.WriteError || error{InvalidFileName};
1591 File.Reader.Error || File.Writer.Error || error{InvalidFileName};
15921592
15931593/// Atomically creates a new file at `dest_path` within `dest_dir` with the
15941594/// same contents as `source_path` within `source_dir`, overwriting any already
lib/std/crypto/Certificate/Bundle.zig+1-2
......@@ -242,8 +242,7 @@ pub fn addCertsFromFilePath(
242242}
243243
244244pub const AddCertsFromFileError = Allocator.Error ||
245 Io.File.GetSeekPosError ||
246 Io.File.ReadError ||
245 Io.File.Reader.Error ||
247246 ParseCertError ||
248247 std.base64.Error ||
249248 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };
lib/std/crypto/Certificate/Bundle/macos.zig+1-1
......@@ -6,7 +6,7 @@ const mem = std.mem;
66const Allocator = std.mem.Allocator;
77const Bundle = @import("../Bundle.zig");
88
9pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.ReadError || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream};
9pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.Reader.Error || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream};
1010
1111pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {
1212 cb.bytes.clearRetainingCapacity();
lib/std/fs/test.zig+7-7
......@@ -213,7 +213,7 @@ test "Dir.readLink" {
213213 // test 3: relative path symlink
214214 const parent_file = ".." ++ fs.path.sep_str ++ "target.txt";
215215 const canonical_parent_file = try ctx.toCanonicalPathSep(parent_file);
216 var subdir = try ctx.dir.makeOpenPath("subdir", .{});
216 var subdir = try ctx.dir.makeOpenPath(io, "subdir", .{});
217217 defer subdir.close(io);
218218 try setupSymlink(io, subdir, canonical_parent_file, "relative-link.txt", .{});
219219 try testReadLink(io, subdir, canonical_parent_file, "relative-link.txt");
......@@ -411,7 +411,7 @@ test "openDir non-cwd parent '..'" {
411411 var tmp = tmpDir(.{});
412412 defer tmp.cleanup();
413413
414 var subdir = try tmp.dir.makeOpenPath("subdir", .{});
414 var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{});
415415 defer subdir.close(io);
416416
417417 var dir = try subdir.openDir(io, "..", .{});
......@@ -613,7 +613,7 @@ test "Dir.Iterator but dir is deleted during iteration" {
613613 defer tmp.cleanup();
614614
615615 // Create directory and setup an iterator for it
616 var subdir = try tmp.dir.makeOpenPath("subdir", .{ .iterate = true });
616 var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{ .iterate = true });
617617 defer subdir.close(io);
618618
619619 var iterator = subdir.iterate();
......@@ -862,7 +862,7 @@ test "makeOpenPath parent dirs do not exist" {
862862 var tmp_dir = tmpDir(.{});
863863 defer tmp_dir.cleanup();
864864
865 var dir = try tmp_dir.dir.makeOpenPath("root_dir/parent_dir/some_dir", .{});
865 var dir = try tmp_dir.dir.makeOpenPath(io, "root_dir/parent_dir/some_dir", .{});
866866 dir.close(io);
867867
868868 // double check that the full directory structure was created
......@@ -1010,7 +1010,7 @@ test "Dir.rename directory onto non-empty dir" {
10101010
10111011 try ctx.dir.makeDir(io, test_dir_path, .default_dir);
10121012
1013 var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{});
1013 var target_dir = try ctx.dir.makeOpenPath(io, target_dir_path, .{});
10141014 var file = try target_dir.createFile(io, "test_file", .{ .read = true });
10151015 file.close(io);
10161016 target_dir.close(io);
......@@ -1147,7 +1147,7 @@ test "deleteTree does not follow symlinks" {
11471147
11481148 try tmp.dir.makePath(io, "b");
11491149 {
1150 var a = try tmp.dir.makeOpenPath("a", .{});
1150 var a = try tmp.dir.makeOpenPath(io, "a", .{});
11511151 defer a.close(io);
11521152
11531153 try setupSymlink(io, a, "../b", "b", .{ .is_directory = true });
......@@ -1346,7 +1346,7 @@ test "makepath ignores '.'" {
13461346fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void {
13471347 // setup, create a dir and a nested file both with maxed filenames, and walk the dir
13481348 {
1349 var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
1349 var maxed_dir = try iterable_dir.makeOpenPath(io, maxed_filename, .{});
13501350 defer maxed_dir.close(io);
13511351
13521352 try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
lib/std/posix/test.zig+1-1
......@@ -142,7 +142,7 @@ test "linkat with different directories" {
142142 const target_name = "link-target";
143143 const link_name = "newlink";
144144
145 const subdir = try tmp.dir.makeOpenPath("subdir", .{});
145 const subdir = try tmp.dir.makeOpenPath(io, "subdir", .{});
146146
147147 defer tmp.dir.deleteFile(io, target_name) catch {};
148148 try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });
lib/std/zip.zig+2-2
......@@ -117,7 +117,7 @@ pub const EndRecord = extern struct {
117117 return record;
118118 }
119119
120 pub const FindFileError = File.Reader.SizeError || File.SeekError || File.ReadError || error{
120 pub const FindFileError = File.Reader.SizeError || File.SeekError || File.Reader.Error || error{
121121 ZipNoEndRecord,
122122 EndOfStream,
123123 ReadFailed,
......@@ -560,7 +560,7 @@ pub const Iterator = struct {
560560
561561 const out_file = blk: {
562562 if (std.fs.path.dirname(filename)) |dirname| {
563 var parent_dir = try dest.makeOpenPath(dirname, .{});
563 var parent_dir = try dest.makeOpenPath(io, dirname, .{});
564564 defer parent_dir.close(io);
565565
566566 const basename = std.fs.path.basename(filename);
src/Compilation.zig+15-15
......@@ -832,7 +832,7 @@ pub const Directories = struct {
832832 const nonempty_path = if (path.len == 0) "." else path;
833833 const handle_or_err = switch (thing) {
834834 .@"zig lib" => Io.Dir.cwd().openDir(io, nonempty_path, .{}),
835 .@"global cache", .@"local cache" => Io.Dir.cwd().makeOpenPath(nonempty_path, .{}),
835 .@"global cache", .@"local cache" => Io.Dir.cwd().makeOpenPath(io, nonempty_path, .{}),
836836 };
837837 return .{
838838 .path = if (path.len == 0) null else path,
......@@ -2111,7 +2111,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21112111 cache.* = .{
21122112 .gpa = gpa,
21132113 .io = io,
2114 .manifest_dir = options.dirs.local_cache.handle.makeOpenPath("h", .{}) catch |err| {
2114 .manifest_dir = options.dirs.local_cache.handle.makeOpenPath(io, "h", .{}) catch |err| {
21152115 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } });
21162116 },
21172117 };
......@@ -2161,7 +2161,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21612161 // to redundantly happen for each AstGen operation.
21622162 const zir_sub_dir = "z";
21632163
2164 var local_zir_dir = options.dirs.local_cache.handle.makeOpenPath(zir_sub_dir, .{}) catch |err| {
2164 var local_zir_dir = options.dirs.local_cache.handle.makeOpenPath(io, zir_sub_dir, .{}) catch |err| {
21652165 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = zir_sub_dir, .err = err } });
21662166 };
21672167 errdefer local_zir_dir.close(io);
......@@ -2169,7 +2169,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21692169 .handle = local_zir_dir,
21702170 .path = try options.dirs.local_cache.join(arena, &.{zir_sub_dir}),
21712171 };
2172 var global_zir_dir = options.dirs.global_cache.handle.makeOpenPath(zir_sub_dir, .{}) catch |err| {
2172 var global_zir_dir = options.dirs.global_cache.handle.makeOpenPath(io, zir_sub_dir, .{}) catch |err| {
21732173 return diag.fail(.{ .create_cache_path = .{ .which = .global, .sub = zir_sub_dir, .err = err } });
21742174 };
21752175 errdefer global_zir_dir.close(io);
......@@ -2440,7 +2440,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
24402440 const digest = hash.final();
24412441
24422442 const artifact_sub_dir = "o" ++ fs.path.sep_str ++ digest;
2443 var artifact_dir = options.dirs.local_cache.handle.makeOpenPath(artifact_sub_dir, .{}) catch |err| {
2443 var artifact_dir = options.dirs.local_cache.handle.makeOpenPath(io, artifact_sub_dir, .{}) catch |err| {
24442444 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = artifact_sub_dir, .err = err } });
24452445 };
24462446 errdefer artifact_dir.close(io);
......@@ -2895,7 +2895,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
28952895 tmp_dir_rand_int = std.crypto.random.int(u64);
28962896 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
28972897 const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path});
2898 const handle = comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}) catch |err| {
2898 const handle = comp.dirs.local_cache.handle.makeOpenPath(io, tmp_dir_sub_path, .{}) catch |err| {
28992899 return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });
29002900 };
29012901 break :d .{ .path = path, .handle = handle };
......@@ -2976,7 +2976,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
29762976 tmp_dir_rand_int = std.crypto.random.int(u64);
29772977 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
29782978 const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path});
2979 const handle = comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}) catch |err| {
2979 const handle = comp.dirs.local_cache.handle.makeOpenPath(io, tmp_dir_sub_path, .{}) catch |err| {
29802980 return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });
29812981 };
29822982 break :d .{ .path = path, .handle = handle };
......@@ -5267,7 +5267,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
52675267 const io = comp.io;
52685268
52695269 const docs_path = comp.resolveEmitPath(comp.emit_docs.?);
5270 var out_dir = docs_path.root_dir.handle.makeOpenPath(docs_path.sub_path, .{}) catch |err| {
5270 var out_dir = docs_path.root_dir.handle.makeOpenPath(io, docs_path.sub_path, .{}) catch |err| {
52715271 return comp.lockAndSetMiscFailure(
52725272 .docs_copy,
52735273 "unable to create output directory '{f}': {s}",
......@@ -5509,7 +5509,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
55095509 assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory
55105510
55115511 const docs_path = comp.resolveEmitPath(comp.emit_docs.?);
5512 var out_dir = docs_path.root_dir.handle.makeOpenPath(docs_path.sub_path, .{}) catch |err| {
5512 var out_dir = docs_path.root_dir.handle.makeOpenPath(io, docs_path.sub_path, .{}) catch |err| {
55135513 comp.lockAndSetMiscFailure(
55145514 .docs_copy,
55155515 "unable to create output directory '{f}': {t}",
......@@ -5699,7 +5699,7 @@ pub fn translateC(
56995699 const tmp_basename = std.fmt.hex(std.crypto.random.int(u64));
57005700 const tmp_sub_path = "tmp" ++ fs.path.sep_str ++ tmp_basename;
57015701 const cache_dir = comp.dirs.local_cache.handle;
5702 var cache_tmp_dir = try cache_dir.makeOpenPath(tmp_sub_path, .{});
5702 var cache_tmp_dir = try cache_dir.makeOpenPath(io, tmp_sub_path, .{});
57035703 defer cache_tmp_dir.close(io);
57045704
57055705 const translated_path = try comp.dirs.local_cache.join(arena, &.{ tmp_sub_path, translated_basename });
......@@ -6274,7 +6274,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
62746274 // We can't know the digest until we do the C compiler invocation,
62756275 // so we need a temporary filename.
62766276 const out_obj_path = try comp.tmpFilePath(arena, o_basename);
6277 var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath("tmp", .{});
6277 var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, "tmp", .{});
62786278 defer zig_cache_tmp_dir.close(io);
62796279
62806280 const out_diag_path = if (comp.clang_passthrough_mode or !ext.clangSupportsDiagnostics())
......@@ -6439,7 +6439,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
64396439 // Rename into place.
64406440 const digest = man.final();
64416441 const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });
6442 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
6442 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, o_sub_path, .{});
64436443 defer o_dir.close(io);
64446444 const tmp_basename = fs.path.basename(out_obj_path);
64456445 try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename, io);
......@@ -6528,7 +6528,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
65286528 const digest = man.final();
65296529
65306530 const o_sub_path = try fs.path.join(arena, &.{ "o", &digest });
6531 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
6531 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, o_sub_path, .{});
65326532 defer o_dir.close(io);
65336533
65346534 const in_rc_path = try comp.dirs.local_cache.join(comp.gpa, &.{
......@@ -6616,7 +6616,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
66166616 const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len];
66176617
66186618 const digest = if (try man.hit()) man.final() else blk: {
6619 var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath("tmp", .{});
6619 var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, "tmp", .{});
66206620 defer zig_cache_tmp_dir.close(io);
66216621
66226622 const res_filename = try std.fmt.allocPrint(arena, "{s}.res", .{rc_basename_noext});
......@@ -6687,7 +6687,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
66876687 // Rename into place.
66886688 const digest = man.final();
66896689 const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });
6690 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(o_sub_path, .{});
6690 var o_dir = try comp.dirs.local_cache.handle.makeOpenPath(io, o_sub_path, .{});
66916691 defer o_dir.close(io);
66926692 const tmp_basename = fs.path.basename(out_res_path);
66936693 try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, res_filename, io);
src/Package/Fetch.zig+7-7
......@@ -500,12 +500,12 @@ fn runResource(
500500 var tmp_directory: Cache.Directory = .{
501501 .path = tmp_directory_path,
502502 .handle = handle: {
503 const dir = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
503 const dir = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
504504 .iterate = true,
505505 }) catch |err| {
506506 try eb.addRootErrorMessage(.{
507 .msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{
508 tmp_directory_path, @errorName(err),
507 .msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{
508 tmp_directory_path, err,
509509 }),
510510 });
511511 return error.FetchFailed;
......@@ -524,7 +524,7 @@ fn runResource(
524524 if (native_os == .linux and f.job_queue.work_around_btrfs_bug) {
525525 // https://github.com/ziglang/zig/issues/17095
526526 pkg_path.root_dir.handle.close(io);
527 pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(tmp_dir_sub_path, .{
527 pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
528528 .iterate = true,
529529 }) catch @panic("btrfs workaround failed");
530530 }
......@@ -1366,7 +1366,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
13661366 // we do not attempt to replicate the exact structure of a real .git
13671367 // directory, since that isn't relevant for fetching a package.
13681368 {
1369 var pack_dir = try out_dir.makeOpenPath(".git", .{});
1369 var pack_dir = try out_dir.makeOpenPath(io, ".git", .{});
13701370 defer pack_dir.close(io);
13711371 var pack_file = try pack_dir.createFile(io, "pkg.pack", .{ .read = true });
13721372 defer pack_file.close(io);
......@@ -1743,7 +1743,7 @@ const HashedFile = struct {
17431743
17441744 const Error =
17451745 Io.File.OpenError ||
1746 Io.File.ReadError ||
1746 Io.File.Reader.Error ||
17471747 Io.File.StatError ||
17481748 Io.File.ChmodError ||
17491749 Io.Dir.ReadLinkError;
......@@ -2258,7 +2258,7 @@ const TestFetchBuilder = struct {
22582258 cache_parent_dir: std.Io.Dir,
22592259 path_or_url: []const u8,
22602260 ) !*Fetch {
2261 const cache_dir = try cache_parent_dir.makeOpenPath("zig-global-cache", .{});
2261 const cache_dir = try cache_parent_dir.makeOpenPath(io, "zig-global-cache", .{});
22622262
22632263 self.http_client = .{ .allocator = allocator, .io = io };
22642264 self.global_cache_directory = .{ .handle = cache_dir, .path = null };
src/Package/Fetch/git.zig+2-2
......@@ -1720,10 +1720,10 @@ pub fn main() !void {
17201720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
17211721
17221722 const commit = try Oid.parse(format, args[3]);
1723 var worktree = try Io.Dir.cwd().makeOpenPath(args[4], .{});
1723 var worktree = try Io.Dir.cwd().makeOpenPath(io, args[4], .{});
17241724 defer worktree.close(io);
17251725
1726 var git_dir = try worktree.makeOpenPath(".git", .{});
1726 var git_dir = try worktree.makeOpenPath(io, ".git", .{});
17271727 defer git_dir.close(io);
17281728
17291729 std.debug.print("Starting index...\n", .{});
src/Zcu.zig+1-1
......@@ -1200,7 +1200,7 @@ pub const EmbedFile = struct {
12001200 /// `.none` means the file was not loaded, so `stat` is undefined.
12011201 val: InternPool.Index,
12021202 /// If this is `null` and `val` is `.none`, the file has never been loaded.
1203 err: ?(Io.File.OpenError || Io.File.StatError || Io.File.ReadError || error{UnexpectedEof}),
1203 err: ?(Io.File.OpenError || Io.File.StatError || Io.File.Reader.Error || error{UnexpectedEof}),
12041204 stat: Cache.File.Stat,
12051205
12061206 pub const Index = enum(u32) {
src/crash_report.zig+5-5
......@@ -95,19 +95,19 @@ fn dumpCrashContext() Io.Writer.Error!void {
9595
9696 // TODO: this does mean that a different thread could grab the stderr mutex between the context
9797 // and the actual panic printing, which would be quite confusing.
98 const stderr, _ = std.debug.lockStderrWriter(&.{});
98 const stderr = std.debug.lockStderrWriter(&.{});
9999 defer std.debug.unlockStderrWriter();
100100
101 try stderr.writeAll("Compiler crash context:\n");
101 try stderr.interface.writeAll("Compiler crash context:\n");
102102
103103 if (CodegenFunc.current) |*cg| {
104104 const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav;
105105 const func_fqn = cg.zcu.intern_pool.getNav(func_nav).fqn;
106 try stderr.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)});
106 try stderr.interface.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)});
107107 } else if (AnalyzeBody.current) |anal| {
108 try dumpCrashContextSema(anal, stderr, &S.crash_heap);
108 try dumpCrashContextSema(anal, &stderr.interface, &S.crash_heap);
109109 } else {
110 try stderr.writeAll("(no context)\n\n");
110 try stderr.interface.writeAll("(no context)\n\n");
111111 }
112112}
113113fn dumpCrashContextSema(anal: *AnalyzeBody, stderr: *Io.Writer, crash_heap: []u8) Io.Writer.Error!void {
src/fmt.zig+6-6
......@@ -59,7 +59,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
5959 const arg = args[i];
6060 if (mem.startsWith(u8, arg, "-")) {
6161 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
62 try Io.File.stdout().writeAll(usage_fmt);
62 try Io.File.stdout().writeStreamingAll(io, usage_fmt);
6363 return process.cleanExit();
6464 } else if (mem.eql(u8, arg, "--color")) {
6565 if (i + 1 >= args.len) {
......@@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
154154 process.exit(code);
155155 }
156156
157 return Io.File.stdout().writeAll(formatted);
157 return Io.File.stdout().writeStreamingAll(io, formatted);
158158 }
159159
160160 if (input_files.items.len == 0) {
......@@ -162,7 +162,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
162162 }
163163
164164 var stdout_buffer: [4096]u8 = undefined;
165 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
165 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
166166
167167 var fmt: Fmt = .{
168168 .gpa = gpa,
......@@ -231,7 +231,7 @@ fn fmtPathDir(
231231 if (try fmt.seen.fetchPut(stat.inode, {})) |_| return;
232232
233233 var dir_it = dir.iterate();
234 while (try dir_it.next()) |entry| {
234 while (try dir_it.next(io)) |entry| {
235235 const is_dir = entry.kind == .directory;
236236
237237 if (mem.startsWith(u8, entry.name, ".")) continue;
......@@ -244,7 +244,7 @@ fn fmtPathDir(
244244 try fmtPathDir(fmt, full_path, check_mode, dir, entry.name);
245245 } else {
246246 fmtPathFile(fmt, full_path, check_mode, dir, entry.name) catch |err| {
247 std.log.err("unable to format '{s}': {s}", .{ full_path, @errorName(err) });
247 std.log.err("unable to format '{s}': {t}", .{ full_path, err });
248248 fmt.any_error = true;
249249 return;
250250 };
......@@ -355,7 +355,7 @@ fn fmtPathFile(
355355 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});
356356 fmt.any_error = true;
357357 } else {
358 var af = try dir.atomicFile(sub_path, .{ .mode = stat.mode, .write_buffer = &.{} });
358 var af = try dir.atomicFile(io, sub_path, .{ .permissions = stat.permissions, .write_buffer = &.{} });
359359 defer af.deinit();
360360
361361 try af.file_writer.interface.writeAll(fmt.out_buffer.written());
src/introspect.zig+26-28
......@@ -3,10 +3,9 @@ const build_options = @import("build_options");
33
44const std = @import("std");
55const Io = std.Io;
6const Dir = std.Io.Dir;
67const mem = std.mem;
78const Allocator = std.mem.Allocator;
8const os = std.os;
9const fs = std.fs;
109const Cache = std.Build.Cache;
1110
1211const Compilation = @import("Compilation.zig");
......@@ -16,11 +15,11 @@ const Package = @import("Package.zig");
1615/// The path of the returned Directory is relative to `base`.
1716/// The handle of the returned Directory is open.
1817fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
19 const test_index_file = "std" ++ fs.path.sep_str ++ "std.zig";
18 const test_index_file = "std" ++ Dir.path.sep_str ++ "std.zig";
2019
2120 zig_dir: {
2221 // Try lib/zig/std/std.zig
23 const lib_zig = "lib" ++ fs.path.sep_str ++ "zig";
22 const lib_zig = "lib" ++ Dir.path.sep_str ++ "zig";
2423 var test_zig_dir = base_dir.openDir(io, lib_zig, .{}) catch break :zig_dir;
2524 const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
2625 test_zig_dir.close(io);
......@@ -44,13 +43,13 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
4443pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory {
4544 const cwd_path = try getResolvedCwd(gpa);
4645 defer gpa.free(cwd_path);
47 const self_exe_path = try fs.selfExePathAlloc(gpa);
46 const self_exe_path = try std.process.executablePathAlloc(io, gpa);
4847 defer gpa.free(self_exe_path);
4948
5049 return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path);
5150}
5251
53/// Like `std.process.getCwdAlloc`, but also resolves the path with `std.fs.path.resolve`. This
52/// Like `std.process.getCwdAlloc`, but also resolves the path with `Dir.path.resolve`. This
5453/// means the path has no repeated separators, no "." or ".." components, and no trailing separator.
5554/// On WASI, "" is returned instead of ".".
5655pub fn getResolvedCwd(gpa: Allocator) error{
......@@ -68,8 +67,8 @@ pub fn getResolvedCwd(gpa: Allocator) error{
6867 }
6968 const cwd = try std.process.getCwdAlloc(gpa);
7069 defer gpa.free(cwd);
71 const resolved = try fs.path.resolve(gpa, &.{cwd});
72 std.debug.assert(fs.path.isAbsolute(resolved));
70 const resolved = try Dir.path.resolve(gpa, &.{cwd});
71 std.debug.assert(Dir.path.isAbsolute(resolved));
7372 return resolved;
7473}
7574
......@@ -84,12 +83,12 @@ pub fn findZigLibDirFromSelfExe(
8483) error{ OutOfMemory, FileNotFound }!Cache.Directory {
8584 const cwd = Io.Dir.cwd();
8685 var cur_path: []const u8 = self_exe_path;
87 while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
86 while (Dir.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
8887 var base_dir = cwd.openDir(io, dirname, .{}) catch continue;
8988 defer base_dir.close(io);
9089
9190 const sub_directory = testZigInstallPrefix(io, base_dir) orelse continue;
92 const p = try fs.path.join(allocator, &.{ dirname, sub_directory.path.? });
91 const p = try Dir.path.join(allocator, &.{ dirname, sub_directory.path.? });
9392 defer allocator.free(p);
9493
9594 const resolved = try resolvePath(allocator, cwd_path, &.{p});
......@@ -113,18 +112,18 @@ pub fn resolveGlobalCacheDir(allocator: Allocator) ![]u8 {
113112 if (builtin.os.tag != .windows) {
114113 if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| {
115114 if (cache_root.len > 0) {
116 return fs.path.join(allocator, &.{ cache_root, appname });
115 return Dir.path.join(allocator, &.{ cache_root, appname });
117116 }
118117 }
119118 if (std.zig.EnvVar.HOME.getPosix()) |home| {
120 return fs.path.join(allocator, &.{ home, ".cache", appname });
119 return Dir.path.join(allocator, &.{ home, ".cache", appname });
121120 }
122121 }
123122
124 return fs.getAppDataDir(allocator, appname);
123 return std.fs.getAppDataDir(allocator, appname);
125124}
126125
127/// Similar to `fs.path.resolve`, but converts to a cwd-relative path, or, if that would
126/// Similar to `Dir.path.resolve`, but converts to a cwd-relative path, or, if that would
128127/// start with a relative up-dir (".."), an absolute path based on the cwd. Also, the cwd
129128/// returns the empty string ("") instead of ".".
130129pub fn resolvePath(
......@@ -136,7 +135,7 @@ pub fn resolvePath(
136135) Allocator.Error![]u8 {
137136 if (builtin.target.os.tag == .wasi) {
138137 std.debug.assert(mem.eql(u8, cwd_resolved, ""));
139 const res = try fs.path.resolve(gpa, paths);
138 const res = try Dir.path.resolve(gpa, paths);
140139 if (mem.eql(u8, res, ".")) {
141140 gpa.free(res);
142141 return "";
......@@ -146,16 +145,16 @@ pub fn resolvePath(
146145
147146 // Heuristic for a fast path: if no component is absolute and ".." never appears, we just need to resolve `paths`.
148147 for (paths) |p| {
149 if (fs.path.isAbsolute(p)) break; // absolute path
148 if (Dir.path.isAbsolute(p)) break; // absolute path
150149 if (mem.indexOf(u8, p, "..") != null) break; // may contain up-dir
151150 } else {
152151 // no absolute path, no "..".
153 const res = try fs.path.resolve(gpa, paths);
152 const res = try Dir.path.resolve(gpa, paths);
154153 if (mem.eql(u8, res, ".")) {
155154 gpa.free(res);
156155 return "";
157156 }
158 std.debug.assert(!fs.path.isAbsolute(res));
157 std.debug.assert(!Dir.path.isAbsolute(res));
159158 std.debug.assert(!isUpDir(res));
160159 return res;
161160 }
......@@ -164,19 +163,19 @@ pub fn resolvePath(
164163 // Optimization: `paths` often has just one element.
165164 const path_resolved = switch (paths.len) {
166165 0 => unreachable,
167 1 => try fs.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),
166 1 => try Dir.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),
168167 else => r: {
169168 const all_paths = try gpa.alloc([]const u8, paths.len + 1);
170169 defer gpa.free(all_paths);
171170 all_paths[0] = cwd_resolved;
172171 @memcpy(all_paths[1..], paths);
173 break :r try fs.path.resolve(gpa, all_paths);
172 break :r try Dir.path.resolve(gpa, all_paths);
174173 },
175174 };
176175 errdefer gpa.free(path_resolved);
177176
178 std.debug.assert(fs.path.isAbsolute(path_resolved));
179 std.debug.assert(fs.path.isAbsolute(cwd_resolved));
177 std.debug.assert(Dir.path.isAbsolute(path_resolved));
178 std.debug.assert(Dir.path.isAbsolute(cwd_resolved));
180179
181180 if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
182181 if (path_resolved.len == cwd_resolved.len) {
......@@ -184,7 +183,7 @@ pub fn resolvePath(
184183 gpa.free(path_resolved);
185184 return "";
186185 }
187 if (path_resolved[cwd_resolved.len] != std.fs.path.sep) return path_resolved; // not in cwd (last component differs)
186 if (path_resolved[cwd_resolved.len] != Dir.path.sep) return path_resolved; // not in cwd (last component differs)
188187
189188 // in cwd; extract sub path
190189 const sub_path = try gpa.dupe(u8, path_resolved[cwd_resolved.len + 1 ..]);
......@@ -192,9 +191,8 @@ pub fn resolvePath(
192191 return sub_path;
193192}
194193
195/// TODO move this to std.fs.path
196194pub fn isUpDir(p: []const u8) bool {
197 return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == fs.path.sep);
195 return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == Dir.path.sep);
198196}
199197
200198pub const default_local_zig_cache_basename = ".zig-cache";
......@@ -205,12 +203,12 @@ pub const default_local_zig_cache_basename = ".zig-cache";
205203pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 {
206204 var cur_dir = cwd;
207205 while (true) {
208 const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
206 const joined = try Dir.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
209207 if (Io.Dir.cwd().access(io, joined, .{})) |_| {
210 return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
208 return try Dir.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
211209 } else |err| switch (err) {
212210 error.FileNotFound => {
213 cur_dir = fs.path.dirname(cur_dir) orelse return null;
211 cur_dir = Dir.path.dirname(cur_dir) orelse return null;
214212 continue;
215213 },
216214 else => return null,
src/libs/freebsd.zig+2-2
......@@ -444,7 +444,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
444444 var cache: Cache = .{
445445 .gpa = gpa,
446446 .io = io,
447 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
447 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
448448 };
449449 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
450450 cache.addPrefix(comp.dirs.zig_lib);
......@@ -477,7 +477,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
477477 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
478478
479479 var o_directory: Cache.Directory = .{
480 .handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
480 .handle = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{}),
481481 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
482482 };
483483 defer o_directory.handle.close(io);
src/libs/glibc.zig+2-2
......@@ -679,7 +679,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
679679 var cache: Cache = .{
680680 .gpa = gpa,
681681 .io = io,
682 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
682 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
683683 };
684684 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
685685 cache.addPrefix(comp.dirs.zig_lib);
......@@ -712,7 +712,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
712712 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
713713
714714 var o_directory: Cache.Directory = .{
715 .handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
715 .handle = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{}),
716716 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
717717 };
718718 defer o_directory.handle.close(io);
src/libs/mingw.zig+2-2
......@@ -258,7 +258,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
258258 var cache: Cache = .{
259259 .gpa = gpa,
260260 .io = io,
261 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
261 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
262262 };
263263 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
264264 cache.addPrefix(comp.dirs.zig_lib);
......@@ -297,7 +297,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
297297
298298 const digest = man.final();
299299 const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
300 var o_dir = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{});
300 var o_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{});
301301 defer o_dir.close(io);
302302
303303 const aro = @import("aro");
src/libs/netbsd.zig+2-2
......@@ -385,7 +385,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
385385 var cache: Cache = .{
386386 .gpa = gpa,
387387 .io = io,
388 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
388 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath(io, "h", .{}),
389389 };
390390 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
391391 cache.addPrefix(comp.dirs.zig_lib);
......@@ -418,7 +418,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
418418 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
419419
420420 var o_directory: Cache.Directory = .{
421 .handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
421 .handle = try comp.dirs.global_cache.handle.makeOpenPath(io, o_sub_path, .{}),
422422 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
423423 };
424424 defer o_directory.handle.close(io);
src/link.zig+7-8
......@@ -2170,28 +2170,27 @@ fn resolvePathInputLib(
21702170 }) {
21712171 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
21722172 error.FileNotFound => return .no_match,
2173 else => |e| fatal("unable to search for {s} library '{f}': {s}", .{
2174 @tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e),
2173 else => |e| fatal("unable to search for {t} library '{f}': {t}", .{
2174 link_mode, std.fmt.alt(test_path, .formatEscapeChar), e,
21752175 }),
21762176 };
21772177 errdefer file.close(io);
21782178 try ld_script_bytes.resize(gpa, @max(std.elf.MAGIC.len, std.elf.ARMAG.len));
2179 const n = file.preadAll(ld_script_bytes.items, 0) catch |err| fatal("failed to read '{f}': {s}", .{
2180 std.fmt.alt(test_path, .formatEscapeChar), @errorName(err),
2181 });
2179 const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err|
2180 fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err });
21822181 const buf = ld_script_bytes.items[0..n];
21832182 if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) {
21842183 // Appears to be an ELF or archive file.
21852184 return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);
21862185 }
21872186 const stat = file.stat(io) catch |err|
2188 fatal("failed to stat {f}: {s}", .{ test_path, @errorName(err) });
2187 fatal("failed to stat {f}: {t}", .{ test_path, err });
21892188 const size = std.math.cast(u32, stat.size) orelse
21902189 fatal("{f}: linker script too big", .{test_path});
21912190 try ld_script_bytes.resize(gpa, size);
21922191 const buf2 = ld_script_bytes.items[n..];
2193 const n2 = file.preadAll(buf2, n) catch |err|
2194 fatal("failed to read {f}: {s}", .{ test_path, @errorName(err) });
2192 const n2 = file.readPositionalAll(io, buf2, n) catch |err|
2193 fatal("failed to read {f}: {t}", .{ test_path, err });
21952194 if (n2 != buf2.len) fatal("failed to read {f}: unexpected end of file", .{test_path});
21962195
21972196 // This `Io` is only used for a mutex, and we know we aren't doing anything async/concurrent.
src/link/Coff.zig+2-2
......@@ -636,7 +636,7 @@ fn create(
636636 const coff = try arena.create(Coff);
637637 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
638638 .read = true,
639 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
639 .permissions = link.File.determinePermissions(comp.config.output_mode, comp.config.link_mode),
640640 });
641641 errdefer file.close(io);
642642 coff.* = .{
......@@ -653,7 +653,7 @@ fn create(
653653 .allow_shlib_undefined = false,
654654 .stack_size = 0,
655655 },
656 .mf = try .init(file, comp.gpa),
656 .mf = try .init(file, comp.gpa, io),
657657 .nodes = .empty,
658658 .import_table = .{
659659 .ni = .none,
src/link/Dwarf.zig-1
......@@ -52,7 +52,6 @@ pub const UpdateError = error{
5252 codegen.GenerateSymbolError ||
5353 Io.File.OpenError ||
5454 Io.File.LengthError ||
55 Io.File.CopyRangeError ||
5655 Io.File.ReadPositionalError ||
5756 Io.File.WritePositionalError;
5857
src/link/Elf.zig+1-1
......@@ -320,7 +320,7 @@ pub fn createEmpty(
320320 self.base.file = try emit.root_dir.handle.createFile(io, sub_path, .{
321321 .truncate = true,
322322 .read = true,
323 .mode = link.File.determineMode(output_mode, link_mode),
323 .permissions = link.File.determinePermissions(output_mode, link_mode),
324324 });
325325
326326 const gpa = comp.gpa;
src/link/Elf2.zig+2-2
......@@ -976,7 +976,7 @@ fn create(
976976 const elf = try arena.create(Elf);
977977 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
978978 .read = true,
979 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
979 .permissions = link.File.determinePermissions(comp.config.output_mode, comp.config.link_mode),
980980 });
981981 errdefer file.close(io);
982982 elf.* = .{
......@@ -994,7 +994,7 @@ fn create(
994994 .stack_size = 0,
995995 },
996996 .options = options,
997 .mf = try .init(file, comp.gpa),
997 .mf = try .init(file, comp.gpa, io),
998998 .ni = .{
999999 .tls = .none,
10001000 },
src/link/MachO.zig+25-10
......@@ -224,7 +224,7 @@ pub fn createEmpty(
224224 self.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
225225 .truncate = true,
226226 .read = true,
227 .mode = link.File.determineMode(output_mode, link_mode),
227 .permissions = link.File.determinePermissions(output_mode, link_mode),
228228 });
229229
230230 // Append null file
......@@ -3157,7 +3157,9 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) !?u64 {
31573157 }
31583158 }
31593159
3160 if (at_end) try self.base.file.?.setEndPos(end);
3160 const comp = self.base.comp;
3161 const io = comp.io;
3162 if (at_end) try self.base.file.?.setLength(io, end);
31613163 return null;
31623164}
31633165
......@@ -3292,7 +3294,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {
32923294 );
32933295 defer gpa.free(d_sym_path);
32943296
3295 var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(d_sym_path, .{});
3297 var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(io, d_sym_path, .{});
32963298 defer d_sym_bundle.close(io);
32973299
32983300 self.d_sym.?.file = try d_sym_bundle.createFile(io, fs.path.basename(self.base.emit.sub_path), .{
......@@ -3303,6 +3305,10 @@ pub fn reopenDebugInfo(self: *MachO) !void {
33033305
33043306// TODO: move to ZigObject
33053307fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
3308 const comp = self.base.comp;
3309 const gpa = comp.gpa;
3310 const io = comp.io;
3311
33063312 if (!self.base.isRelocatable()) {
33073313 const base_vmaddr = blk: {
33083314 const pagezero_size = self.pagezero_size orelse default_pagezero_size;
......@@ -3357,7 +3363,11 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
33573363 if (options.zo.dwarf) |*dwarf| {
33583364 // Create dSYM bundle.
33593365 log.debug("creating {s}.dSYM bundle", .{options.emit.sub_path});
3360 self.d_sym = .{ .allocator = self.base.comp.gpa, .file = null };
3366 self.d_sym = .{
3367 .io = io,
3368 .allocator = gpa,
3369 .file = null,
3370 };
33613371 try self.reopenDebugInfo();
33623372 try self.d_sym.?.initMetadata(self);
33633373 try dwarf.initMetadata();
......@@ -3477,6 +3487,9 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
34773487 const seg_id = self.sections.items(.segment_id)[sect_index];
34783488 const seg = &self.segments.items[seg_id];
34793489
3490 const comp = self.base.comp;
3491 const io = comp.io;
3492
34803493 if (!sect.isZerofill()) {
34813494 const allocated_size = self.allocatedSize(sect.offset);
34823495 if (needed_size > allocated_size) {
......@@ -3498,7 +3511,7 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
34983511
34993512 sect.offset = @intCast(new_offset);
35003513 } else if (sect.offset + allocated_size == std.math.maxInt(u64)) {
3501 try self.base.file.?.setEndPos(sect.offset + needed_size);
3514 try self.base.file.?.setLength(io, sect.offset + needed_size);
35023515 }
35033516 seg.filesize = needed_size;
35043517 }
......@@ -3520,6 +3533,8 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
35203533}
35213534
35223535fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void {
3536 const comp = self.base.comp;
3537 const io = comp.io;
35233538 const sect = &self.sections.items(.header)[sect_index];
35243539
35253540 if (!sect.isZerofill()) {
......@@ -3547,7 +3562,7 @@ fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void
35473562 sect.offset = @intCast(new_offset);
35483563 sect.addr = new_addr;
35493564 } else if (sect.offset + allocated_size == std.math.maxInt(u64)) {
3550 try self.base.file.?.setEndPos(sect.offset + needed_size);
3565 try self.base.file.?.setLength(io, sect.offset + needed_size);
35513566 }
35523567 }
35533568 sect.size = needed_size;
......@@ -5346,12 +5361,12 @@ pub fn pwriteAll(macho_file: *MachO, bytes: []const u8, offset: u64) error{LinkF
53465361 };
53475362}
53485363
5349pub fn setEndPos(macho_file: *MachO, length: u64) error{LinkFailure}!void {
5364pub fn setLength(macho_file: *MachO, length: u64) error{LinkFailure}!void {
53505365 const comp = macho_file.base.comp;
5366 const io = comp.io;
53515367 const diags = &comp.link_diags;
5352 macho_file.base.file.?.setEndPos(length) catch |err| {
5353 return diags.fail("failed to set file end pos: {s}", .{@errorName(err)});
5354 };
5368 macho_file.base.file.?.setLength(io, length) catch |err|
5369 return diags.fail("failed to set file end pos: {t}", .{err});
53555370}
53565371
53575372pub fn cast(macho_file: *MachO, comptime T: type, x: anytype) error{LinkFailure}!T {
src/link/MappedFile.zig+5-2
......@@ -10,6 +10,7 @@ const assert = std.debug.assert;
1010const linux = std.os.linux;
1111const windows = std.os.windows;
1212
13io: Io,
1314file: std.Io.File,
1415flags: packed struct {
1516 block_size: std.mem.Alignment,
......@@ -36,8 +37,9 @@ pub const Error = std.posix.MMapError || std.posix.MRemapError || Io.File.Length
3637 NoSpaceLeft,
3738};
3839
39pub fn init(file: std.Io.File, gpa: std.mem.Allocator) !MappedFile {
40pub fn init(file: std.Io.File, gpa: std.mem.Allocator, io: Io) !MappedFile {
4041 var mf: MappedFile = .{
42 .io = io,
4143 .file = file,
4244 .flags = undefined,
4345 .section = if (is_windows) windows.INVALID_HANDLE_VALUE else {},
......@@ -624,13 +626,14 @@ pub fn addNodeAfter(
624626}
625627
626628fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested_size: u64) !void {
629 const io = mf.io;
627630 const node = ni.get(mf);
628631 const old_offset, const old_size = node.location().resolve(mf);
629632 const new_size = node.flags.alignment.forward(@intCast(requested_size));
630633 // Resize the entire file
631634 if (ni == Node.Index.root) {
632635 try mf.ensureCapacityForSetLocation(gpa);
633 try mf.file.setEndPos(new_size);
636 try mf.file.setLength(io, new_size);
634637 try mf.ensureTotalCapacity(@intCast(new_size));
635638 ni.setLocationAssumeCapacity(mf, old_offset, new_size);
636639 return;
src/link/Wasm.zig+3-3
......@@ -3002,11 +3002,11 @@ pub fn createEmpty(
30023002 wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
30033003 .truncate = true,
30043004 .read = true,
3005 .mode = if (Io.File.Permissions.has_executable_bit)
3005 .permissions = if (Io.File.Permissions.has_executable_bit)
30063006 if (target.os.tag == .wasi and output_mode == .Exe)
3007 Io.File.default_mode | 0b001_000_000
3007 .executable_file
30083008 else
3009 Io.File.default_mode
3009 .default_file
30103010 else
30113011 0,
30123012 });
src/main.zig+73-82
......@@ -335,19 +335,20 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
335335 } else if (mem.eql(u8, cmd, "targets")) {
336336 dev.check(.targets_command);
337337 const host = std.zig.resolveTargetQueryOrFatal(io, .{});
338 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
338 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
339339 try @import("print_targets.zig").cmdTargets(arena, io, cmd_args, &stdout_writer.interface, &host);
340340 return stdout_writer.interface.flush();
341341 } else if (mem.eql(u8, cmd, "version")) {
342342 dev.check(.version_command);
343 try Io.File.stdout().writeAll(build_options.version ++ "\n");
343 try Io.File.stdout().writeStreamingAll(io, build_options.version ++ "\n");
344344 return;
345345 } else if (mem.eql(u8, cmd, "env")) {
346346 dev.check(.env_command);
347347 const host = std.zig.resolveTargetQueryOrFatal(io, .{});
348 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
348 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
349349 try @import("print_env.zig").cmdEnv(
350350 arena,
351 io,
351352 &stdout_writer.interface,
352353 args,
353354 if (native_os == .wasi) wasi_preopens,
......@@ -361,10 +362,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
361362 });
362363 } else if (mem.eql(u8, cmd, "zen")) {
363364 dev.check(.zen_command);
364 return Io.File.stdout().writeAll(info_zen);
365 return Io.File.stdout().writeStreamingAll(io, info_zen);
365366 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
366367 dev.check(.help_command);
367 return Io.File.stdout().writeAll(usage);
368 return Io.File.stdout().writeStreamingAll(io, usage);
368369 } else if (mem.eql(u8, cmd, "ast-check")) {
369370 return cmdAstCheck(arena, io, cmd_args);
370371 } else if (mem.eql(u8, cmd, "detect-cpu")) {
......@@ -374,7 +375,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
374375 } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) {
375376 return cmdDumpZir(arena, io, cmd_args);
376377 } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "llvm-ints")) {
377 return cmdDumpLlvmInts(gpa, arena, cmd_args);
378 return cmdDumpLlvmInts(gpa, arena, io, cmd_args);
378379 } else {
379380 std.log.info("{s}", .{usage});
380381 fatal("unknown command: {s}", .{args[1]});
......@@ -701,7 +702,7 @@ const Emit = union(enum) {
701702 yes: []const u8,
702703
703704 const OutputToCacheReason = enum { listen, @"zig run", @"zig test" };
704 fn resolve(io: Io, emit: Emit, default_basename: []const u8, output_to_cache: ?OutputToCacheReason) Compilation.CreateOptions.Emit {
705 fn resolve(emit: Emit, io: Io, default_basename: []const u8, output_to_cache: ?OutputToCacheReason) Compilation.CreateOptions.Emit {
705706 return switch (emit) {
706707 .no => .no,
707708 .yes_default_path => if (output_to_cache != null) .yes_cache else .{ .yes_path = default_basename },
......@@ -1036,7 +1037,7 @@ fn buildOutputType(
10361037 fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err });
10371038 } else if (mem.startsWith(u8, arg, "-")) {
10381039 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
1039 try Io.File.stdout().writeAll(usage_build_generic);
1040 try Io.File.stdout().writeStreamingAll(io, usage_build_generic);
10401041 return cleanExit();
10411042 } else if (mem.eql(u8, arg, "--")) {
10421043 if (arg_mode == .run) {
......@@ -1858,9 +1859,7 @@ fn buildOutputType(
18581859 var must_link = false;
18591860 var file_ext: ?Compilation.FileExt = null;
18601861 while (it.has_next) {
1861 it.next() catch |err| {
1862 fatal("unable to parse command line parameters: {s}", .{@errorName(err)});
1863 };
1862 it.next(io) catch |err| fatal("unable to parse command line parameters: {t}", .{err});
18641863 switch (it.zig_equivalent) {
18651864 .target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown
18661865 .o => {
......@@ -2836,9 +2835,9 @@ fn buildOutputType(
28362835 } else if (mem.eql(u8, arg, "-V")) {
28372836 warn("ignoring request for supported emulations: unimplemented", .{});
28382837 } else if (mem.eql(u8, arg, "-v")) {
2839 try Io.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
2838 try Io.File.stdout().writeStreamingAll(io, "zig ld " ++ build_options.version ++ "\n");
28402839 } else if (mem.eql(u8, arg, "--version")) {
2841 try Io.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
2840 try Io.File.stdout().writeStreamingAll(io, "zig ld " ++ build_options.version ++ "\n");
28422841 process.exit(0);
28432842 } else {
28442843 fatal("unsupported linker arg: {s}", .{arg});
......@@ -3077,14 +3076,13 @@ fn buildOutputType(
30773076
30783077 const self_exe_path = switch (native_os) {
30793078 .wasi => {},
3080 else => fs.selfExePathAlloc(arena) catch |err| {
3081 fatal("unable to find zig self exe path: {s}", .{@errorName(err)});
3082 },
3079 else => process.executablePathAlloc(io, arena) catch |err| fatal("unable to find zig self exe path: {t}", .{err}),
30833080 };
30843081
30853082 // This `init` calls `fatal` on error.
30863083 var dirs: Compilation.Directories = .init(
30873084 arena,
3085 io,
30883086 override_lib_dir,
30893087 override_global_cache_dir,
30903088 s: {
......@@ -3097,11 +3095,9 @@ fn buildOutputType(
30973095 if (native_os == .wasi) wasi_preopens,
30983096 self_exe_path,
30993097 );
3100 defer dirs.deinit();
3098 defer dirs.deinit(io);
31013099
3102 if (linker_optimization) |o| {
3103 warn("ignoring deprecated linker optimization setting '{s}'", .{o});
3104 }
3100 if (linker_optimization) |o| warn("ignoring deprecated linker optimization setting '{s}'", .{o});
31053101
31063102 create_module.dirs = dirs;
31073103 create_module.opts.emit_llvm_ir = emit_llvm_ir != .no;
......@@ -3324,18 +3320,18 @@ fn buildOutputType(
33243320 };
33253321
33263322 const default_h_basename = try std.fmt.allocPrint(arena, "{s}.h", .{root_name});
3327 const emit_h_resolved = emit_h.resolve(default_h_basename, output_to_cache);
3323 const emit_h_resolved = emit_h.resolve(io, default_h_basename, output_to_cache);
33283324
33293325 const default_asm_basename = try std.fmt.allocPrint(arena, "{s}.s", .{root_name});
3330 const emit_asm_resolved = emit_asm.resolve(default_asm_basename, output_to_cache);
3326 const emit_asm_resolved = emit_asm.resolve(io, default_asm_basename, output_to_cache);
33313327
33323328 const default_llvm_ir_basename = try std.fmt.allocPrint(arena, "{s}.ll", .{root_name});
3333 const emit_llvm_ir_resolved = emit_llvm_ir.resolve(default_llvm_ir_basename, output_to_cache);
3329 const emit_llvm_ir_resolved = emit_llvm_ir.resolve(io, default_llvm_ir_basename, output_to_cache);
33343330
33353331 const default_llvm_bc_basename = try std.fmt.allocPrint(arena, "{s}.bc", .{root_name});
3336 const emit_llvm_bc_resolved = emit_llvm_bc.resolve(default_llvm_bc_basename, output_to_cache);
3332 const emit_llvm_bc_resolved = emit_llvm_bc.resolve(io, default_llvm_bc_basename, output_to_cache);
33373333
3338 const emit_docs_resolved = emit_docs.resolve("docs", output_to_cache);
3334 const emit_docs_resolved = emit_docs.resolve(io, "docs", output_to_cache);
33393335
33403336 const is_exe_or_dyn_lib = switch (create_module.resolved_options.output_mode) {
33413337 .Obj => false,
......@@ -3356,7 +3352,7 @@ fn buildOutputType(
33563352 const default_implib_basename = try std.fmt.allocPrint(arena, "{s}.lib", .{root_name});
33573353 const emit_implib_resolved: Compilation.CreateOptions.Emit = switch (emit_implib) {
33583354 .no => .no,
3359 .yes => emit_implib.resolve(default_implib_basename, output_to_cache),
3355 .yes => emit_implib.resolve(io, default_implib_basename, output_to_cache),
33603356 .yes_default_path => emit: {
33613357 if (output_to_cache != null) break :emit .yes_cache;
33623358 const p = try fs.path.join(arena, &.{
......@@ -3399,7 +3395,7 @@ fn buildOutputType(
33993395 // for the hashing algorithm here and in the cache are the same.
34003396 // We are providing our own cache key, because this file has nothing
34013397 // to do with the cache manifest.
3402 var file_writer = f.writer(&.{});
3398 var file_writer = f.writer(io, &.{});
34033399 var buffer: [1000]u8 = undefined;
34043400 var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);
34053401 var stdin_reader = Io.File.stdin().readerStreaming(io, &.{});
......@@ -3633,13 +3629,13 @@ fn buildOutputType(
36333629 if (show_builtin) {
36343630 const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config);
36353631 const source = try builtin_opts.generate(arena);
3636 return Io.File.stdout().writeAll(source);
3632 return Io.File.stdout().writeStreamingAll(io, source);
36373633 }
36383634 switch (listen) {
36393635 .none => {},
36403636 .stdio => {
36413637 var stdin_reader = Io.File.stdin().reader(io, &stdin_buffer);
3642 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
3638 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
36433639 try serve(
36443640 comp,
36453641 &stdin_reader.interface,
......@@ -3930,11 +3926,8 @@ fn createModule(
39303926 }
39313927
39323928 if (target.isMinGW()) {
3933 const exists = mingw.libExists(arena, target, create_module.dirs.zig_lib, lib_name) catch |err| {
3934 fatal("failed to check zig installation for DLL import libs: {s}", .{
3935 @errorName(err),
3936 });
3937 };
3929 const exists = mingw.libExists(arena, io, target, create_module.dirs.zig_lib, lib_name) catch |err|
3930 fatal("failed to check zig installation for DLL import libs: {t}", .{err});
39383931 if (exists) {
39393932 try create_module.windows_libs.put(arena, lib_name, {});
39403933 continue;
......@@ -4009,11 +4002,8 @@ fn createModule(
40094002 }
40104003
40114004 if (create_module.libc_paths_file) |paths_file| {
4012 create_module.libc_installation = LibCInstallation.parse(arena, paths_file, target) catch |err| {
4013 fatal("unable to parse libc paths file at path {s}: {s}", .{
4014 paths_file, @errorName(err),
4015 });
4016 };
4005 create_module.libc_installation = LibCInstallation.parse(arena, io, paths_file, target) catch |err|
4006 fatal("unable to parse libc paths file at path {s}: {t}", .{ paths_file, err });
40174007 }
40184008
40194009 if (target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and
......@@ -4024,7 +4014,7 @@ fn createModule(
40244014 .verbose = true,
40254015 .target = target,
40264016 }) catch |err| {
4027 fatal("unable to find native libc installation: {s}", .{@errorName(err)});
4017 fatal("unable to find native libc installation: {t}", .{err});
40284018 };
40294019 }
40304020 try create_module.lib_directories.ensureUnusedCapacity(arena, 2);
......@@ -4163,7 +4153,7 @@ fn serve(
41634153
41644154 var child_pid: ?std.process.Child.Id = null;
41654155
4166 const main_progress_node = std.Progress.start(.{});
4156 const main_progress_node = std.Progress.start(io, .{});
41674157 const file_system_inputs = comp.file_system_inputs.?;
41684158
41694159 const IncrementalDebugServer = if (build_options.enable_debug_extensions and !builtin.single_threaded)
......@@ -4694,7 +4684,7 @@ fn cmdTranslateC(
46944684 });
46954685 };
46964686 defer zig_file.close(io);
4697 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
4687 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
46984688 var file_reader = zig_file.reader(io, &.{});
46994689 _ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited);
47004690 try stdout_writer.interface.flush();
......@@ -4744,7 +4734,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
47444734 if (mem.eql(u8, arg, "-m") or mem.eql(u8, arg, "--minimal")) {
47454735 template = .minimal;
47464736 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
4747 try Io.File.stdout().writeAll(usage_init);
4737 try Io.File.stdout().writeStreamingAll(io, usage_init);
47484738 return cleanExit();
47494739 } else {
47504740 fatal("unrecognized parameter: '{s}'", .{arg});
......@@ -4764,7 +4754,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
47644754 switch (template) {
47654755 .example => {
47664756 var templates = findTemplates(gpa, arena, io);
4767 defer templates.deinit();
4757 defer templates.deinit(io);
47684758
47694759 const s = fs.path.sep_str;
47704760 const template_paths = [_][]const u8{
......@@ -4898,7 +4888,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
48984888 const argv_index_exe = child_argv.items.len;
48994889 _ = try child_argv.addOne();
49004890
4901 const self_exe_path = try fs.selfExePathAlloc(arena);
4891 const self_exe_path = try process.executablePathAlloc(io, arena);
49024892 try child_argv.append(self_exe_path);
49034893
49044894 const argv_index_zig_lib_dir = child_argv.items.len;
......@@ -5079,7 +5069,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
50795069
50805070 const work_around_btrfs_bug = native_os == .linux and
50815071 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
5082 const root_prog_node = std.Progress.start(.{
5072 const root_prog_node = std.Progress.start(io, .{
50835073 .disable_printing = (color == .off),
50845074 .root_name = "Compile Build Script",
50855075 });
......@@ -5114,7 +5104,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
51145104 const paths_file = debug_libc_paths_file orelse break :lci null;
51155105 if (!build_options.enable_debug_extensions) unreachable;
51165106 const lci = try arena.create(LibCInstallation);
5117 lci.* = try .parse(arena, paths_file, &resolved_target.result);
5107 lci.* = try .parse(arena, io, paths_file, &resolved_target.result);
51185108 break :lci lci;
51195109 };
51205110
......@@ -5129,6 +5119,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
51295119 // This `init` calls `fatal` on error.
51305120 var dirs: Compilation.Directories = .init(
51315121 arena,
5122 io,
51325123 override_lib_dir,
51335124 override_global_cache_dir,
51345125 .{ .override = path: {
......@@ -5138,7 +5129,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
51385129 {},
51395130 self_exe_path,
51405131 );
5141 defer dirs.deinit();
5132 defer dirs.deinit(io);
51425133
51435134 child_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
51445135 child_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;
......@@ -5421,11 +5412,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
54215412 child.stderr_behavior = .Inherit;
54225413
54235414 const term = t: {
5424 std.debug.lockStdErr();
5425 defer std.debug.unlockStdErr();
5426 break :t child.spawnAndWait(io) catch |err| {
5415 _ = std.debug.lockStderrWriter(&.{});
5416 defer std.debug.unlockStderrWriter();
5417 break :t child.spawnAndWait(io) catch |err|
54275418 fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err });
5428 };
54295419 };
54305420
54315421 switch (term) {
......@@ -5517,7 +5507,7 @@ fn jitCmd(
55175507 dev.check(.jit_command);
55185508
55195509 const color: Color = .auto;
5520 const root_prog_node = if (options.progress_node) |node| node else std.Progress.start(.{
5510 const root_prog_node = if (options.progress_node) |node| node else std.Progress.start(io, .{
55215511 .disable_printing = (color == .off),
55225512 });
55235513
......@@ -5529,9 +5519,8 @@ fn jitCmd(
55295519 .is_explicit_dynamic_linker = false,
55305520 };
55315521
5532 const self_exe_path = fs.selfExePathAlloc(arena) catch |err| {
5533 fatal("unable to find self exe path: {s}", .{@errorName(err)});
5534 };
5522 const self_exe_path = process.executablePathAlloc(io, arena) catch |err|
5523 fatal("unable to find self exe path: {t}", .{err});
55355524
55365525 const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet())
55375526 .Debug
......@@ -5544,13 +5533,14 @@ fn jitCmd(
55445533 // This `init` calls `fatal` on error.
55455534 var dirs: Compilation.Directories = .init(
55465535 arena,
5536 io,
55475537 override_lib_dir,
55485538 override_global_cache_dir,
55495539 .global,
55505540 if (native_os == .wasi) wasi_preopens,
55515541 self_exe_path,
55525542 );
5553 defer dirs.deinit();
5543 defer dirs.deinit(io);
55545544
55555545 const thread_limit = @min(
55565546 @max(std.Thread.getCpuCount() catch 1, 1),
......@@ -5629,7 +5619,7 @@ fn jitCmd(
56295619 defer comp.destroy();
56305620
56315621 if (options.server) {
5632 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
5622 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
56335623 var server: std.zig.Server = .{
56345624 .out = &stdout_writer.interface,
56355625 .in = undefined, // won't be receiving messages
......@@ -5696,7 +5686,7 @@ fn jitCmd(
56965686 ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
56975687 }
56985688
5699 const term = try child.wait();
5689 const term = try child.wait(io);
57005690 switch (term) {
57015691 .Exited => |code| {
57025692 if (code == 0) {
......@@ -6160,7 +6150,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
61606150 const arg = args[i];
61616151 if (mem.startsWith(u8, arg, "-")) {
61626152 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6163 try Io.File.stdout().writeAll(usage_ast_check);
6153 try Io.File.stdout().writeStreamingAll(io, usage_ast_check);
61646154 return cleanExit();
61656155 } else if (mem.eql(u8, arg, "-t")) {
61666156 want_output_text = true;
......@@ -6211,7 +6201,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62116201
62126202 const tree = try Ast.parse(arena, source, mode);
62136203
6214 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
6204 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
62156205 const stdout_bw = &stdout_writer.interface;
62166206 switch (mode) {
62176207 .zig => {
......@@ -6334,7 +6324,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
63346324 const arg = args[i];
63356325 if (mem.startsWith(u8, arg, "-")) {
63366326 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6337 try Io.File.stdout().writeAll(detect_cpu_usage);
6327 try Io.File.stdout().writeStreamingAll(io, detect_cpu_usage);
63386328 return cleanExit();
63396329 } else if (mem.eql(u8, arg, "--llvm")) {
63406330 use_llvm = true;
......@@ -6355,10 +6345,10 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
63556345 const name = llvm.GetHostCPUName() orelse fatal("LLVM could not figure out the host cpu name", .{});
63566346 const features = llvm.GetHostCPUFeatures() orelse fatal("LLVM could not figure out the host cpu feature set", .{});
63576347 const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features);
6358 try printCpu(cpu);
6348 try printCpu(io, cpu);
63596349 } else {
63606350 const host_target = std.zig.resolveTargetQueryOrFatal(io, .{});
6361 try printCpu(host_target.cpu);
6351 try printCpu(io, host_target.cpu);
63626352 }
63636353}
63646354
......@@ -6425,8 +6415,8 @@ fn detectNativeCpuWithLLVM(
64256415 return result;
64266416}
64276417
6428fn printCpu(cpu: std.Target.Cpu) !void {
6429 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
6418fn printCpu(io: Io, cpu: std.Target.Cpu) !void {
6419 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
64306420 const stdout_bw = &stdout_writer.interface;
64316421
64326422 if (cpu.model.llvm_name) |llvm_name| {
......@@ -6448,6 +6438,7 @@ fn printCpu(cpu: std.Target.Cpu) !void {
64486438fn cmdDumpLlvmInts(
64496439 gpa: Allocator,
64506440 arena: Allocator,
6441 io: Io,
64516442 args: []const []const u8,
64526443) !void {
64536444 dev.check(.llvm_ints_command);
......@@ -6475,7 +6466,7 @@ fn cmdDumpLlvmInts(
64756466 const dl = tm.createTargetDataLayout();
64766467 const context = llvm.Context.create();
64776468
6478 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
6469 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
64796470 const stdout_bw = &stdout_writer.interface;
64806471 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
64816472 const int_type = context.intType(bits);
......@@ -6501,7 +6492,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {
65016492 defer f.close(io);
65026493
65036494 const zir = try Zcu.loadZirCache(arena, io, f);
6504 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
6495 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
65056496 const stdout_bw = &stdout_writer.interface;
65066497 {
65076498 const instruction_bytes = zir.instructions.len *
......@@ -6585,7 +6576,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65856576 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
65866577 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
65876578
6588 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
6579 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
65896580 const stdout_bw = &stdout_writer.interface;
65906581 {
65916582 try stdout_bw.print("Instruction mappings:\n", .{});
......@@ -6917,7 +6908,7 @@ fn cmdFetch(
69176908 const arg = args[i];
69186909 if (mem.startsWith(u8, arg, "-")) {
69196910 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6920 try Io.File.stdout().writeAll(usage_fetch);
6911 try Io.File.stdout().writeStreamingAll(io, usage_fetch);
69216912 return cleanExit();
69226913 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
69236914 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
......@@ -6951,7 +6942,7 @@ fn cmdFetch(
69516942
69526943 try http_client.initDefaultProxies(arena);
69536944
6954 var root_prog_node = std.Progress.start(.{
6945 var root_prog_node = std.Progress.start(io, .{
69556946 .root_name = "Fetch",
69566947 });
69576948 defer root_prog_node.end();
......@@ -6959,7 +6950,7 @@ fn cmdFetch(
69596950 var global_cache_directory: Directory = l: {
69606951 const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);
69616952 break :l .{
6962 .handle = try Io.Dir.cwd().makeOpenPath(p, .{}),
6953 .handle = try Io.Dir.cwd().makeOpenPath(io, p, .{}),
69636954 .path = p,
69646955 };
69656956 };
......@@ -7026,7 +7017,7 @@ fn cmdFetch(
70267017
70277018 const name = switch (save) {
70287019 .no => {
7029 var stdout = Io.File.stdout().writerStreaming(&stdout_buffer);
7020 var stdout = Io.File.stdout().writerStreaming(io, &stdout_buffer);
70307021 try stdout.interface.print("{s}\n", .{package_hash_slice});
70317022 try stdout.interface.flush();
70327023 return cleanExit();
......@@ -7044,7 +7035,7 @@ fn cmdFetch(
70447035 var build_root = try findBuildRoot(arena, io, .{
70457036 .cwd_path = cwd_path,
70467037 });
7047 defer build_root.deinit();
7038 defer build_root.deinit(io);
70487039
70497040 // The name to use in case the manifest file needs to be created now.
70507041 const init_root_name = fs.path.basename(build_root.directory.path orelse cwd_path);
......@@ -7205,7 +7196,7 @@ fn createDependenciesModule(
72057196 const rand_int = std.crypto.random.int(u64);
72067197 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(rand_int);
72077198 {
7208 var tmp_dir = try dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{});
7199 var tmp_dir = try dirs.local_cache.handle.makeOpenPath(io, tmp_dir_sub_path, .{});
72097200 defer tmp_dir.close(io);
72107201 try tmp_dir.writeFile(io, .{ .sub_path = basename, .data = source });
72117202 }
......@@ -7446,28 +7437,28 @@ fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const
74467437 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
74477438 defer f.close(io);
74487439 var buf: [4096]u8 = undefined;
7449 var fw = f.writer(&buf);
7440 var fw = f.writer(io, &buf);
74507441 try fw.interface.print(fmt, args);
74517442 try fw.interface.flush();
74527443}
74537444
74547445fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates {
74557446 const cwd_path = introspect.getResolvedCwd(arena) catch |err| {
7456 fatal("unable to get cwd: {s}", .{@errorName(err)});
7447 fatal("unable to get cwd: {t}", .{err});
74577448 };
7458 const self_exe_path = fs.selfExePathAlloc(arena) catch |err| {
7459 fatal("unable to find self exe path: {s}", .{@errorName(err)});
7449 const self_exe_path = process.executablePathAlloc(io, arena) catch |err| {
7450 fatal("unable to find self exe path: {t}", .{err});
74607451 };
74617452 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, io, cwd_path, self_exe_path) catch |err| {
7462 fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });
7453 fatal("unable to find zig installation directory '{s}': {t}", .{ self_exe_path, err });
74637454 };
74647455
74657456 const s = fs.path.sep_str;
74667457 const template_sub_path = "init";
74677458 const template_dir = zig_lib_directory.handle.openDir(io, template_sub_path, .{}) catch |err| {
74687459 const path = zig_lib_directory.path orelse ".";
7469 fatal("unable to open zig project template directory '{s}{s}{s}': {s}", .{
7470 path, s, template_sub_path, @errorName(err),
7460 fatal("unable to open zig project template directory '{s}{s}{s}': {t}", .{
7461 path, s, template_sub_path, err,
74717462 });
74727463 };
74737464
src/print_env.zig+11-6
......@@ -1,13 +1,17 @@
1const std = @import("std");
21const builtin = @import("builtin");
3const build_options = @import("build_options");
4const Compilation = @import("Compilation.zig");
2
3const std = @import("std");
4const Io = std.Io;
55const Allocator = std.mem.Allocator;
66const EnvVar = std.zig.EnvVar;
77const fatal = std.process.fatal;
88
9const build_options = @import("build_options");
10const Compilation = @import("Compilation.zig");
11
912pub fn cmdEnv(
1013 arena: Allocator,
14 io: Io,
1115 out: *std.Io.Writer,
1216 args: []const []const u8,
1317 wasi_preopens: switch (builtin.target.os.tag) {
......@@ -21,20 +25,21 @@ pub fn cmdEnv(
2125
2226 const self_exe_path = switch (builtin.target.os.tag) {
2327 .wasi => args[0],
24 else => std.fs.selfExePathAlloc(arena) catch |err| {
25 fatal("unable to find zig self exe path: {s}", .{@errorName(err)});
28 else => std.process.executablePathAlloc(io, arena) catch |err| {
29 fatal("unable to find zig self exe path: {t}", .{err});
2630 },
2731 };
2832
2933 var dirs: Compilation.Directories = .init(
3034 arena,
35 io,
3136 override_lib_dir,
3237 override_global_cache_dir,
3338 .global,
3439 if (builtin.target.os.tag == .wasi) wasi_preopens,
3540 if (builtin.target.os.tag != .wasi) self_exe_path,
3641 );
37 defer dirs.deinit();
42 defer dirs.deinit(io);
3843
3944 const zig_lib_dir = dirs.zig_lib.path orelse "";
4045 const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"});
src/print_targets.zig+8-8
......@@ -1,14 +1,16 @@
11const std = @import("std");
2const Io = std.Io;
23const fs = std.fs;
34const mem = std.mem;
45const meta = std.meta;
56const fatal = std.process.fatal;
67const Allocator = std.mem.Allocator;
78const Target = std.Target;
8const target = @import("target.zig");
99const assert = std.debug.assert;
10
1011const glibc = @import("libs/glibc.zig");
1112const introspect = @import("introspect.zig");
13const target = @import("target.zig");
1214
1315pub fn cmdTargets(
1416 allocator: Allocator,
......@@ -18,19 +20,19 @@ pub fn cmdTargets(
1820 native_target: *const Target,
1921) !void {
2022 _ = args;
21 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
22 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
23 };
23 var zig_lib_directory = introspect.findZigLibDir(allocator, io) catch |err|
24 fatal("unable to find zig installation directory: {t}", .{err});
2425 defer zig_lib_directory.handle.close(io);
2526 defer allocator.free(zig_lib_directory.path.?);
2627
2728 const abilists_contents = zig_lib_directory.handle.readFileAlloc(
29 io,
2830 glibc.abilists_path,
2931 allocator,
3032 .limited(glibc.abilists_max_size),
3133 ) catch |err| switch (err) {
3234 error.OutOfMemory => return error.OutOfMemory,
33 else => fatal("unable to read " ++ glibc.abilists_path ++ ": {s}", .{@errorName(err)}),
35 else => fatal("unable to read " ++ glibc.abilists_path ++ ": {t}", .{err}),
3436 };
3537 defer allocator.free(abilists_contents);
3638
......@@ -49,9 +51,7 @@ pub fn cmdTargets(
4951 {
5052 var libc_obj = try root_obj.beginTupleField("libc", .{});
5153 for (std.zig.target.available_libcs) |libc| {
52 const tmp = try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{
53 @tagName(libc.arch), @tagName(libc.os), @tagName(libc.abi),
54 });
54 const tmp = try std.fmt.allocPrint(allocator, "{t}-{t}-{t}", .{ libc.arch, libc.os, libc.abi });
5555 defer allocator.free(tmp);
5656 try libc_obj.field(tmp, .{});
5757 }
test/standalone/self_exe_symlink/main.zig+1-1
......@@ -9,7 +9,7 @@ pub fn main() !void {
99 defer threaded.deinit();
1010 const io = threaded.io();
1111
12 const self_path = try std.fs.selfExePathAlloc(gpa);
12 const self_path = try std.process.executablePathAlloc(io, gpa);
1313 defer gpa.free(self_path);
1414
1515 var self_exe = try std.fs.openSelfExe(.{});