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 {...@@ -43,7 +43,7 @@ pub fn main() u8 {
43 return 1;43 return 1;
44 };44 };
4545
46 const aro_name = std.fs.selfExePathAlloc(gpa) catch {46 const aro_name = process.executablePathAlloc(io, gpa) catch {
47 std.debug.print("unable to find Aro executable path\n", .{});47 std.debug.print("unable to find Aro executable path\n", .{});
48 if (fast_exit) process.exit(1);48 if (fast_exit) process.exit(1);
49 return 1;49 return 1;
lib/std/Build/Cache.zig+4-4
...@@ -1330,7 +1330,7 @@ test "cache file and then recall it" {...@@ -1330,7 +1330,7 @@ test "cache file and then recall it" {
1330 var cache: Cache = .{1330 var cache: Cache = .{
1331 .io = io,1331 .io = io,
1332 .gpa = testing.allocator,1332 .gpa = testing.allocator,
1333 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),1333 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
1334 };1334 };
1335 cache.addPrefix(.{ .path = null, .handle = tmp.dir });1335 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
1336 defer cache.manifest_dir.close(io);1336 defer cache.manifest_dir.close(io);
...@@ -1396,7 +1396,7 @@ test "check that changing a file makes cache fail" {...@@ -1396,7 +1396,7 @@ test "check that changing a file makes cache fail" {
1396 var cache: Cache = .{1396 var cache: Cache = .{
1397 .io = io,1397 .io = io,
1398 .gpa = testing.allocator,1398 .gpa = testing.allocator,
1399 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),1399 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
1400 };1400 };
1401 cache.addPrefix(.{ .path = null, .handle = tmp.dir });1401 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
1402 defer cache.manifest_dir.close(io);1402 defer cache.manifest_dir.close(io);
...@@ -1456,7 +1456,7 @@ test "no file inputs" {...@@ -1456,7 +1456,7 @@ test "no file inputs" {
1456 var cache: Cache = .{1456 var cache: Cache = .{
1457 .io = io,1457 .io = io,
1458 .gpa = testing.allocator,1458 .gpa = testing.allocator,
1459 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),1459 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
1460 };1460 };
1461 cache.addPrefix(.{ .path = null, .handle = tmp.dir });1461 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
1462 defer cache.manifest_dir.close(io);1462 defer cache.manifest_dir.close(io);
...@@ -1515,7 +1515,7 @@ test "Manifest with files added after initial hash work" {...@@ -1515,7 +1515,7 @@ test "Manifest with files added after initial hash work" {
1515 var cache: Cache = .{1515 var cache: Cache = .{
1516 .io = io,1516 .io = io,
1517 .gpa = testing.allocator,1517 .gpa = testing.allocator,
1518 .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}),1518 .manifest_dir = try tmp.dir.makeOpenPath(io, temp_manifest_dir, .{}),
1519 };1519 };
1520 cache.addPrefix(.{ .path = null, .handle = tmp.dir });1520 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
1521 defer cache.manifest_dir.close(io);1521 defer cache.manifest_dir.close(io);
lib/std/Build/Cache/Path.zig+2-2
...@@ -84,14 +84,14 @@ pub fn openDir(...@@ -84,14 +84,14 @@ pub fn openDir(
84 return p.root_dir.handle.openDir(io, joined_path, args);84 return p.root_dir.handle.openDir(io, joined_path, args);
85}85}
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 {
88 var buf: [fs.max_path_bytes]u8 = undefined;88 var buf: [fs.max_path_bytes]u8 = undefined;
89 const joined_path = if (p.sub_path.len == 0) sub_path else p: {89 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
90 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{90 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
91 p.sub_path, sub_path,91 p.sub_path, sub_path,
92 }) catch return error.NameTooLong;92 }) catch return error.NameTooLong;
93 };93 };
94 return p.root_dir.handle.makeOpenPath(joined_path, opts);94 return p.root_dir.handle.makeOpenPath(io, joined_path, opts);
95}95}
9696
97pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {97pub 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 {...@@ -1588,7 +1588,7 @@ pub const CopyFileOptions = struct {
15881588
1589pub const CopyFileError = File.OpenError || File.StatError ||1589pub const CopyFileError = File.OpenError || File.StatError ||
1590 File.Atomic.InitError || File.Atomic.FinishError ||1590 File.Atomic.InitError || File.Atomic.FinishError ||
1591 File.Reader.Error || File.WriteError || error{InvalidFileName};1591 File.Reader.Error || File.Writer.Error || error{InvalidFileName};
15921592
1593/// Atomically creates a new file at `dest_path` within `dest_dir` with the1593/// Atomically creates a new file at `dest_path` within `dest_dir` with the
1594/// same contents as `source_path` within `source_dir`, overwriting any already1594/// 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(...@@ -242,8 +242,7 @@ pub fn addCertsFromFilePath(
242}242}
243243
244pub const AddCertsFromFileError = Allocator.Error ||244pub const AddCertsFromFileError = Allocator.Error ||
245 Io.File.GetSeekPosError ||245 Io.File.Reader.Error ||
246 Io.File.ReadError ||
247 ParseCertError ||246 ParseCertError ||
248 std.base64.Error ||247 std.base64.Error ||
249 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };248 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };
lib/std/crypto/Certificate/Bundle/macos.zig+1-1
...@@ -6,7 +6,7 @@ const mem = std.mem;...@@ -6,7 +6,7 @@ const mem = std.mem;
6const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
7const Bundle = @import("../Bundle.zig");7const 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
11pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {11pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {
12 cb.bytes.clearRetainingCapacity();12 cb.bytes.clearRetainingCapacity();
lib/std/fs/test.zig+7-7
...@@ -213,7 +213,7 @@ test "Dir.readLink" {...@@ -213,7 +213,7 @@ test "Dir.readLink" {
213 // test 3: relative path symlink213 // test 3: relative path symlink
214 const parent_file = ".." ++ fs.path.sep_str ++ "target.txt";214 const parent_file = ".." ++ fs.path.sep_str ++ "target.txt";
215 const canonical_parent_file = try ctx.toCanonicalPathSep(parent_file);215 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", .{});
217 defer subdir.close(io);217 defer subdir.close(io);
218 try setupSymlink(io, subdir, canonical_parent_file, "relative-link.txt", .{});218 try setupSymlink(io, subdir, canonical_parent_file, "relative-link.txt", .{});
219 try testReadLink(io, subdir, canonical_parent_file, "relative-link.txt");219 try testReadLink(io, subdir, canonical_parent_file, "relative-link.txt");
...@@ -411,7 +411,7 @@ test "openDir non-cwd parent '..'" {...@@ -411,7 +411,7 @@ test "openDir non-cwd parent '..'" {
411 var tmp = tmpDir(.{});411 var tmp = tmpDir(.{});
412 defer tmp.cleanup();412 defer tmp.cleanup();
413413
414 var subdir = try tmp.dir.makeOpenPath("subdir", .{});414 var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{});
415 defer subdir.close(io);415 defer subdir.close(io);
416416
417 var dir = try subdir.openDir(io, "..", .{});417 var dir = try subdir.openDir(io, "..", .{});
...@@ -613,7 +613,7 @@ test "Dir.Iterator but dir is deleted during iteration" {...@@ -613,7 +613,7 @@ test "Dir.Iterator but dir is deleted during iteration" {
613 defer tmp.cleanup();613 defer tmp.cleanup();
614614
615 // Create directory and setup an iterator for it615 // 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 });
617 defer subdir.close(io);617 defer subdir.close(io);
618618
619 var iterator = subdir.iterate();619 var iterator = subdir.iterate();
...@@ -862,7 +862,7 @@ test "makeOpenPath parent dirs do not exist" {...@@ -862,7 +862,7 @@ test "makeOpenPath parent dirs do not exist" {
862 var tmp_dir = tmpDir(.{});862 var tmp_dir = tmpDir(.{});
863 defer tmp_dir.cleanup();863 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", .{});
866 dir.close(io);866 dir.close(io);
867867
868 // double check that the full directory structure was created868 // double check that the full directory structure was created
...@@ -1010,7 +1010,7 @@ test "Dir.rename directory onto non-empty dir" {...@@ -1010,7 +1010,7 @@ test "Dir.rename directory onto non-empty dir" {
10101010
1011 try ctx.dir.makeDir(io, test_dir_path, .default_dir);1011 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, .{});
1014 var file = try target_dir.createFile(io, "test_file", .{ .read = true });1014 var file = try target_dir.createFile(io, "test_file", .{ .read = true });
1015 file.close(io);1015 file.close(io);
1016 target_dir.close(io);1016 target_dir.close(io);
...@@ -1147,7 +1147,7 @@ test "deleteTree does not follow symlinks" {...@@ -1147,7 +1147,7 @@ test "deleteTree does not follow symlinks" {
11471147
1148 try tmp.dir.makePath(io, "b");1148 try tmp.dir.makePath(io, "b");
1149 {1149 {
1150 var a = try tmp.dir.makeOpenPath("a", .{});1150 var a = try tmp.dir.makeOpenPath(io, "a", .{});
1151 defer a.close(io);1151 defer a.close(io);
11521152
1153 try setupSymlink(io, a, "../b", "b", .{ .is_directory = true });1153 try setupSymlink(io, a, "../b", "b", .{ .is_directory = true });
...@@ -1346,7 +1346,7 @@ test "makepath ignores '.'" {...@@ -1346,7 +1346,7 @@ test "makepath ignores '.'" {
1346fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void {1346fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void {
1347 // setup, create a dir and a nested file both with maxed filenames, and walk the dir1347 // setup, create a dir and a nested file both with maxed filenames, and walk the dir
1348 {1348 {
1349 var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});1349 var maxed_dir = try iterable_dir.makeOpenPath(io, maxed_filename, .{});
1350 defer maxed_dir.close(io);1350 defer maxed_dir.close(io);
13511351
1352 try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });1352 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" {...@@ -142,7 +142,7 @@ test "linkat with different directories" {
142 const target_name = "link-target";142 const target_name = "link-target";
143 const link_name = "newlink";143 const link_name = "newlink";
144144
145 const subdir = try tmp.dir.makeOpenPath("subdir", .{});145 const subdir = try tmp.dir.makeOpenPath(io, "subdir", .{});
146146
147 defer tmp.dir.deleteFile(io, target_name) catch {};147 defer tmp.dir.deleteFile(io, target_name) catch {};
148 try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });148 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 {...@@ -117,7 +117,7 @@ pub const EndRecord = extern struct {
117 return record;117 return record;
118 }118 }
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{
121 ZipNoEndRecord,121 ZipNoEndRecord,
122 EndOfStream,122 EndOfStream,
123 ReadFailed,123 ReadFailed,
...@@ -560,7 +560,7 @@ pub const Iterator = struct {...@@ -560,7 +560,7 @@ pub const Iterator = struct {
560560
561 const out_file = blk: {561 const out_file = blk: {
562 if (std.fs.path.dirname(filename)) |dirname| {562 if (std.fs.path.dirname(filename)) |dirname| {
563 var parent_dir = try dest.makeOpenPath(dirname, .{});563 var parent_dir = try dest.makeOpenPath(io, dirname, .{});
564 defer parent_dir.close(io);564 defer parent_dir.close(io);
565565
566 const basename = std.fs.path.basename(filename);566 const basename = std.fs.path.basename(filename);
src/Compilation.zig+15-15
...@@ -832,7 +832,7 @@ pub const Directories = struct {...@@ -832,7 +832,7 @@ pub const Directories = struct {
832 const nonempty_path = if (path.len == 0) "." else path;832 const nonempty_path = if (path.len == 0) "." else path;
833 const handle_or_err = switch (thing) {833 const handle_or_err = switch (thing) {
834 .@"zig lib" => Io.Dir.cwd().openDir(io, nonempty_path, .{}),834 .@"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, .{}),
836 };836 };
837 return .{837 return .{
838 .path = if (path.len == 0) null else path,838 .path = if (path.len == 0) null else path,
...@@ -2111,7 +2111,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2111,7 +2111,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2111 cache.* = .{2111 cache.* = .{
2112 .gpa = gpa,2112 .gpa = gpa,
2113 .io = io,2113 .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| {
2115 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } });2115 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } });
2116 },2116 },
2117 };2117 };
...@@ -2161,7 +2161,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2161,7 +2161,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2161 // to redundantly happen for each AstGen operation.2161 // to redundantly happen for each AstGen operation.
2162 const zir_sub_dir = "z";2162 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| {
2165 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = zir_sub_dir, .err = err } });2165 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = zir_sub_dir, .err = err } });
2166 };2166 };
2167 errdefer local_zir_dir.close(io);2167 errdefer local_zir_dir.close(io);
...@@ -2169,7 +2169,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2169,7 +2169,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2169 .handle = local_zir_dir,2169 .handle = local_zir_dir,
2170 .path = try options.dirs.local_cache.join(arena, &.{zir_sub_dir}),2170 .path = try options.dirs.local_cache.join(arena, &.{zir_sub_dir}),
2171 };2171 };
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| {
2173 return diag.fail(.{ .create_cache_path = .{ .which = .global, .sub = zir_sub_dir, .err = err } });2173 return diag.fail(.{ .create_cache_path = .{ .which = .global, .sub = zir_sub_dir, .err = err } });
2174 };2174 };
2175 errdefer global_zir_dir.close(io);2175 errdefer global_zir_dir.close(io);
...@@ -2440,7 +2440,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2440,7 +2440,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2440 const digest = hash.final();2440 const digest = hash.final();
24412441
2442 const artifact_sub_dir = "o" ++ fs.path.sep_str ++ digest;2442 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| {
2444 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = artifact_sub_dir, .err = err } });2444 return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = artifact_sub_dir, .err = err } });
2445 };2445 };
2446 errdefer artifact_dir.close(io);2446 errdefer artifact_dir.close(io);
...@@ -2895,7 +2895,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2895,7 +2895,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2895 tmp_dir_rand_int = std.crypto.random.int(u64);2895 tmp_dir_rand_int = std.crypto.random.int(u64);
2896 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);2896 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
2897 const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path});2897 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| {
2899 return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });2899 return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });
2900 };2900 };
2901 break :d .{ .path = path, .handle = handle };2901 break :d .{ .path = path, .handle = handle };
...@@ -2976,7 +2976,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2976,7 +2976,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2976 tmp_dir_rand_int = std.crypto.random.int(u64);2976 tmp_dir_rand_int = std.crypto.random.int(u64);
2977 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);2977 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int);
2978 const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path});2978 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| {
2980 return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });2980 return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err });
2981 };2981 };
2982 break :d .{ .path = path, .handle = handle };2982 break :d .{ .path = path, .handle = handle };
...@@ -5267,7 +5267,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {...@@ -5267,7 +5267,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
5267 const io = comp.io;5267 const io = comp.io;
52685268
5269 const docs_path = comp.resolveEmitPath(comp.emit_docs.?);5269 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| {
5271 return comp.lockAndSetMiscFailure(5271 return comp.lockAndSetMiscFailure(
5272 .docs_copy,5272 .docs_copy,
5273 "unable to create output directory '{f}': {s}",5273 "unable to create output directory '{f}': {s}",
...@@ -5509,7 +5509,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU...@@ -5509,7 +5509,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
5509 assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory5509 assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory
55105510
5511 const docs_path = comp.resolveEmitPath(comp.emit_docs.?);5511 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| {
5513 comp.lockAndSetMiscFailure(5513 comp.lockAndSetMiscFailure(
5514 .docs_copy,5514 .docs_copy,
5515 "unable to create output directory '{f}': {t}",5515 "unable to create output directory '{f}': {t}",
...@@ -5699,7 +5699,7 @@ pub fn translateC(...@@ -5699,7 +5699,7 @@ pub fn translateC(
5699 const tmp_basename = std.fmt.hex(std.crypto.random.int(u64));5699 const tmp_basename = std.fmt.hex(std.crypto.random.int(u64));
5700 const tmp_sub_path = "tmp" ++ fs.path.sep_str ++ tmp_basename;5700 const tmp_sub_path = "tmp" ++ fs.path.sep_str ++ tmp_basename;
5701 const cache_dir = comp.dirs.local_cache.handle;5701 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, .{});
5703 defer cache_tmp_dir.close(io);5703 defer cache_tmp_dir.close(io);
57045704
5705 const translated_path = try comp.dirs.local_cache.join(arena, &.{ tmp_sub_path, translated_basename });5705 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...@@ -6274,7 +6274,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
6274 // We can't know the digest until we do the C compiler invocation,6274 // We can't know the digest until we do the C compiler invocation,
6275 // so we need a temporary filename.6275 // so we need a temporary filename.
6276 const out_obj_path = try comp.tmpFilePath(arena, o_basename);6276 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", .{});
6278 defer zig_cache_tmp_dir.close(io);6278 defer zig_cache_tmp_dir.close(io);
62796279
6280 const out_diag_path = if (comp.clang_passthrough_mode or !ext.clangSupportsDiagnostics())6280 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...@@ -6439,7 +6439,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
6439 // Rename into place.6439 // Rename into place.
6440 const digest = man.final();6440 const digest = man.final();
6441 const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });6441 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, .{});
6443 defer o_dir.close(io);6443 defer o_dir.close(io);
6444 const tmp_basename = fs.path.basename(out_obj_path);6444 const tmp_basename = fs.path.basename(out_obj_path);
6445 try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename, io);6445 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...@@ -6528,7 +6528,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6528 const digest = man.final();6528 const digest = man.final();
65296529
6530 const o_sub_path = try fs.path.join(arena, &.{ "o", &digest });6530 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, .{});
6532 defer o_dir.close(io);6532 defer o_dir.close(io);
65336533
6534 const in_rc_path = try comp.dirs.local_cache.join(comp.gpa, &.{6534 const in_rc_path = try comp.dirs.local_cache.join(comp.gpa, &.{
...@@ -6616,7 +6616,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -6616,7 +6616,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6616 const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len];6616 const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len];
66176617
6618 const digest = if (try man.hit()) man.final() else blk: {6618 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", .{});
6620 defer zig_cache_tmp_dir.close(io);6620 defer zig_cache_tmp_dir.close(io);
66216621
6622 const res_filename = try std.fmt.allocPrint(arena, "{s}.res", .{rc_basename_noext});6622 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...@@ -6687,7 +6687,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6687 // Rename into place.6687 // Rename into place.
6688 const digest = man.final();6688 const digest = man.final();
6689 const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });6689 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, .{});
6691 defer o_dir.close(io);6691 defer o_dir.close(io);
6692 const tmp_basename = fs.path.basename(out_res_path);6692 const tmp_basename = fs.path.basename(out_res_path);
6693 try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, res_filename, io);6693 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(...@@ -500,12 +500,12 @@ fn runResource(
500 var tmp_directory: Cache.Directory = .{500 var tmp_directory: Cache.Directory = .{
501 .path = tmp_directory_path,501 .path = tmp_directory_path,
502 .handle = handle: {502 .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, .{
504 .iterate = true,504 .iterate = true,
505 }) catch |err| {505 }) catch |err| {
506 try eb.addRootErrorMessage(.{506 try eb.addRootErrorMessage(.{
507 .msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{507 .msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{
508 tmp_directory_path, @errorName(err),508 tmp_directory_path, err,
509 }),509 }),
510 });510 });
511 return error.FetchFailed;511 return error.FetchFailed;
...@@ -524,7 +524,7 @@ fn runResource(...@@ -524,7 +524,7 @@ fn runResource(
524 if (native_os == .linux and f.job_queue.work_around_btrfs_bug) {524 if (native_os == .linux and f.job_queue.work_around_btrfs_bug) {
525 // https://github.com/ziglang/zig/issues/17095525 // https://github.com/ziglang/zig/issues/17095
526 pkg_path.root_dir.handle.close(io);526 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, .{
528 .iterate = true,528 .iterate = true,
529 }) catch @panic("btrfs workaround failed");529 }) catch @panic("btrfs workaround failed");
530 }530 }
...@@ -1366,7 +1366,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U...@@ -1366,7 +1366,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
1366 // we do not attempt to replicate the exact structure of a real .git1366 // we do not attempt to replicate the exact structure of a real .git
1367 // directory, since that isn't relevant for fetching a package.1367 // directory, since that isn't relevant for fetching a package.
1368 {1368 {
1369 var pack_dir = try out_dir.makeOpenPath(".git", .{});1369 var pack_dir = try out_dir.makeOpenPath(io, ".git", .{});
1370 defer pack_dir.close(io);1370 defer pack_dir.close(io);
1371 var pack_file = try pack_dir.createFile(io, "pkg.pack", .{ .read = true });1371 var pack_file = try pack_dir.createFile(io, "pkg.pack", .{ .read = true });
1372 defer pack_file.close(io);1372 defer pack_file.close(io);
...@@ -1743,7 +1743,7 @@ const HashedFile = struct {...@@ -1743,7 +1743,7 @@ const HashedFile = struct {
17431743
1744 const Error =1744 const Error =
1745 Io.File.OpenError ||1745 Io.File.OpenError ||
1746 Io.File.ReadError ||1746 Io.File.Reader.Error ||
1747 Io.File.StatError ||1747 Io.File.StatError ||
1748 Io.File.ChmodError ||1748 Io.File.ChmodError ||
1749 Io.Dir.ReadLinkError;1749 Io.Dir.ReadLinkError;
...@@ -2258,7 +2258,7 @@ const TestFetchBuilder = struct {...@@ -2258,7 +2258,7 @@ const TestFetchBuilder = struct {
2258 cache_parent_dir: std.Io.Dir,2258 cache_parent_dir: std.Io.Dir,
2259 path_or_url: []const u8,2259 path_or_url: []const u8,
2260 ) !*Fetch {2260 ) !*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
2263 self.http_client = .{ .allocator = allocator, .io = io };2263 self.http_client = .{ .allocator = allocator, .io = io };
2264 self.global_cache_directory = .{ .handle = cache_dir, .path = null };2264 self.global_cache_directory = .{ .handle = cache_dir, .path = null };
src/Package/Fetch/git.zig+2-2
...@@ -1720,10 +1720,10 @@ pub fn main() !void {...@@ -1720,10 +1720,10 @@ pub fn main() !void {
1720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);1720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
17211721
1722 const commit = try Oid.parse(format, args[3]);1722 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], .{});
1724 defer worktree.close(io);1724 defer worktree.close(io);
17251725
1726 var git_dir = try worktree.makeOpenPath(".git", .{});1726 var git_dir = try worktree.makeOpenPath(io, ".git", .{});
1727 defer git_dir.close(io);1727 defer git_dir.close(io);
17281728
1729 std.debug.print("Starting index...\n", .{});1729 std.debug.print("Starting index...\n", .{});
src/Zcu.zig+1-1
...@@ -1200,7 +1200,7 @@ pub const EmbedFile = struct {...@@ -1200,7 +1200,7 @@ pub const EmbedFile = struct {
1200 /// `.none` means the file was not loaded, so `stat` is undefined.1200 /// `.none` means the file was not loaded, so `stat` is undefined.
1201 val: InternPool.Index,1201 val: InternPool.Index,
1202 /// If this is `null` and `val` is `.none`, the file has never been loaded.1202 /// 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}),
1204 stat: Cache.File.Stat,1204 stat: Cache.File.Stat,
12051205
1206 pub const Index = enum(u32) {1206 pub const Index = enum(u32) {
src/crash_report.zig+5-5
...@@ -95,19 +95,19 @@ fn dumpCrashContext() Io.Writer.Error!void {...@@ -95,19 +95,19 @@ fn dumpCrashContext() Io.Writer.Error!void {
9595
96 // TODO: this does mean that a different thread could grab the stderr mutex between the context96 // TODO: this does mean that a different thread could grab the stderr mutex between the context
97 // and the actual panic printing, which would be quite confusing.97 // and the actual panic printing, which would be quite confusing.
98 const stderr, _ = std.debug.lockStderrWriter(&.{});98 const stderr = std.debug.lockStderrWriter(&.{});
99 defer std.debug.unlockStderrWriter();99 defer std.debug.unlockStderrWriter();
100100
101 try stderr.writeAll("Compiler crash context:\n");101 try stderr.interface.writeAll("Compiler crash context:\n");
102102
103 if (CodegenFunc.current) |*cg| {103 if (CodegenFunc.current) |*cg| {
104 const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav;104 const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav;
105 const func_fqn = cg.zcu.intern_pool.getNav(func_nav).fqn;105 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)});
107 } else if (AnalyzeBody.current) |anal| {107 } else if (AnalyzeBody.current) |anal| {
108 try dumpCrashContextSema(anal, stderr, &S.crash_heap);108 try dumpCrashContextSema(anal, &stderr.interface, &S.crash_heap);
109 } else {109 } else {
110 try stderr.writeAll("(no context)\n\n");110 try stderr.interface.writeAll("(no context)\n\n");
111 }111 }
112}112}
113fn dumpCrashContextSema(anal: *AnalyzeBody, stderr: *Io.Writer, crash_heap: []u8) Io.Writer.Error!void {113fn 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) !...@@ -59,7 +59,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
59 const arg = args[i];59 const arg = args[i];
60 if (mem.startsWith(u8, arg, "-")) {60 if (mem.startsWith(u8, arg, "-")) {
61 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {61 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);
63 return process.cleanExit();63 return process.cleanExit();
64 } else if (mem.eql(u8, arg, "--color")) {64 } else if (mem.eql(u8, arg, "--color")) {
65 if (i + 1 >= args.len) {65 if (i + 1 >= args.len) {
...@@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
154 process.exit(code);154 process.exit(code);
155 }155 }
156156
157 return Io.File.stdout().writeAll(formatted);157 return Io.File.stdout().writeStreamingAll(io, formatted);
158 }158 }
159159
160 if (input_files.items.len == 0) {160 if (input_files.items.len == 0) {
...@@ -162,7 +162,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -162,7 +162,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
162 }162 }
163163
164 var stdout_buffer: [4096]u8 = undefined;164 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
167 var fmt: Fmt = .{167 var fmt: Fmt = .{
168 .gpa = gpa,168 .gpa = gpa,
...@@ -231,7 +231,7 @@ fn fmtPathDir(...@@ -231,7 +231,7 @@ fn fmtPathDir(
231 if (try fmt.seen.fetchPut(stat.inode, {})) |_| return;231 if (try fmt.seen.fetchPut(stat.inode, {})) |_| return;
232232
233 var dir_it = dir.iterate();233 var dir_it = dir.iterate();
234 while (try dir_it.next()) |entry| {234 while (try dir_it.next(io)) |entry| {
235 const is_dir = entry.kind == .directory;235 const is_dir = entry.kind == .directory;
236236
237 if (mem.startsWith(u8, entry.name, ".")) continue;237 if (mem.startsWith(u8, entry.name, ".")) continue;
...@@ -244,7 +244,7 @@ fn fmtPathDir(...@@ -244,7 +244,7 @@ fn fmtPathDir(
244 try fmtPathDir(fmt, full_path, check_mode, dir, entry.name);244 try fmtPathDir(fmt, full_path, check_mode, dir, entry.name);
245 } else {245 } else {
246 fmtPathFile(fmt, full_path, check_mode, dir, entry.name) catch |err| {246 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 });
248 fmt.any_error = true;248 fmt.any_error = true;
249 return;249 return;
250 };250 };
...@@ -355,7 +355,7 @@ fn fmtPathFile(...@@ -355,7 +355,7 @@ fn fmtPathFile(
355 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});355 try fmt.stdout_writer.interface.print("{s}\n", .{file_path});
356 fmt.any_error = true;356 fmt.any_error = true;
357 } else {357 } 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 = &.{} });
359 defer af.deinit();359 defer af.deinit();
360360
361 try af.file_writer.interface.writeAll(fmt.out_buffer.written());361 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");...@@ -3,10 +3,9 @@ const build_options = @import("build_options");
33
4const std = @import("std");4const std = @import("std");
5const Io = std.Io;5const Io = std.Io;
6const Dir = std.Io.Dir;
6const mem = std.mem;7const mem = std.mem;
7const Allocator = std.mem.Allocator;8const Allocator = std.mem.Allocator;
8const os = std.os;
9const fs = std.fs;
10const Cache = std.Build.Cache;9const Cache = std.Build.Cache;
1110
12const Compilation = @import("Compilation.zig");11const Compilation = @import("Compilation.zig");
...@@ -16,11 +15,11 @@ const Package = @import("Package.zig");...@@ -16,11 +15,11 @@ const Package = @import("Package.zig");
16/// The path of the returned Directory is relative to `base`.15/// The path of the returned Directory is relative to `base`.
17/// The handle of the returned Directory is open.16/// The handle of the returned Directory is open.
18fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {17fn 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
21 zig_dir: {20 zig_dir: {
22 // Try lib/zig/std/std.zig21 // 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";
24 var test_zig_dir = base_dir.openDir(io, lib_zig, .{}) catch break :zig_dir;23 var test_zig_dir = base_dir.openDir(io, lib_zig, .{}) catch break :zig_dir;
25 const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {24 const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
26 test_zig_dir.close(io);25 test_zig_dir.close(io);
...@@ -44,13 +43,13 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {...@@ -44,13 +43,13 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory {
44pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory {43pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory {
45 const cwd_path = try getResolvedCwd(gpa);44 const cwd_path = try getResolvedCwd(gpa);
46 defer gpa.free(cwd_path);45 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);
48 defer gpa.free(self_exe_path);47 defer gpa.free(self_exe_path);
4948
50 return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path);49 return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path);
51}50}
5251
53/// Like `std.process.getCwdAlloc`, but also resolves the path with `std.fs.path.resolve`. This52/// Like `std.process.getCwdAlloc`, but also resolves the path with `Dir.path.resolve`. This
54/// means the path has no repeated separators, no "." or ".." components, and no trailing separator.53/// means the path has no repeated separators, no "." or ".." components, and no trailing separator.
55/// On WASI, "" is returned instead of ".".54/// On WASI, "" is returned instead of ".".
56pub fn getResolvedCwd(gpa: Allocator) error{55pub fn getResolvedCwd(gpa: Allocator) error{
...@@ -68,8 +67,8 @@ pub fn getResolvedCwd(gpa: Allocator) error{...@@ -68,8 +67,8 @@ pub fn getResolvedCwd(gpa: Allocator) error{
68 }67 }
69 const cwd = try std.process.getCwdAlloc(gpa);68 const cwd = try std.process.getCwdAlloc(gpa);
70 defer gpa.free(cwd);69 defer gpa.free(cwd);
71 const resolved = try fs.path.resolve(gpa, &.{cwd});70 const resolved = try Dir.path.resolve(gpa, &.{cwd});
72 std.debug.assert(fs.path.isAbsolute(resolved));71 std.debug.assert(Dir.path.isAbsolute(resolved));
73 return resolved;72 return resolved;
74}73}
7574
...@@ -84,12 +83,12 @@ pub fn findZigLibDirFromSelfExe(...@@ -84,12 +83,12 @@ pub fn findZigLibDirFromSelfExe(
84) error{ OutOfMemory, FileNotFound }!Cache.Directory {83) error{ OutOfMemory, FileNotFound }!Cache.Directory {
85 const cwd = Io.Dir.cwd();84 const cwd = Io.Dir.cwd();
86 var cur_path: []const u8 = self_exe_path;85 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) {
88 var base_dir = cwd.openDir(io, dirname, .{}) catch continue;87 var base_dir = cwd.openDir(io, dirname, .{}) catch continue;
89 defer base_dir.close(io);88 defer base_dir.close(io);
9089
91 const sub_directory = testZigInstallPrefix(io, base_dir) orelse continue;90 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.? });
93 defer allocator.free(p);92 defer allocator.free(p);
9493
95 const resolved = try resolvePath(allocator, cwd_path, &.{p});94 const resolved = try resolvePath(allocator, cwd_path, &.{p});
...@@ -113,18 +112,18 @@ pub fn resolveGlobalCacheDir(allocator: Allocator) ![]u8 {...@@ -113,18 +112,18 @@ pub fn resolveGlobalCacheDir(allocator: Allocator) ![]u8 {
113 if (builtin.os.tag != .windows) {112 if (builtin.os.tag != .windows) {
114 if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| {113 if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| {
115 if (cache_root.len > 0) {114 if (cache_root.len > 0) {
116 return fs.path.join(allocator, &.{ cache_root, appname });115 return Dir.path.join(allocator, &.{ cache_root, appname });
117 }116 }
118 }117 }
119 if (std.zig.EnvVar.HOME.getPosix()) |home| {118 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 });
121 }120 }
122 }121 }
123122
124 return fs.getAppDataDir(allocator, appname);123 return std.fs.getAppDataDir(allocator, appname);
125}124}
126125
127/// Similar to `fs.path.resolve`, but converts to a cwd-relative path, or, if that would126/// Similar to `Dir.path.resolve`, but converts to a cwd-relative path, or, if that would
128/// start with a relative up-dir (".."), an absolute path based on the cwd. Also, the cwd127/// start with a relative up-dir (".."), an absolute path based on the cwd. Also, the cwd
129/// returns the empty string ("") instead of ".".128/// returns the empty string ("") instead of ".".
130pub fn resolvePath(129pub fn resolvePath(
...@@ -136,7 +135,7 @@ pub fn resolvePath(...@@ -136,7 +135,7 @@ pub fn resolvePath(
136) Allocator.Error![]u8 {135) Allocator.Error![]u8 {
137 if (builtin.target.os.tag == .wasi) {136 if (builtin.target.os.tag == .wasi) {
138 std.debug.assert(mem.eql(u8, cwd_resolved, ""));137 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);
140 if (mem.eql(u8, res, ".")) {139 if (mem.eql(u8, res, ".")) {
141 gpa.free(res);140 gpa.free(res);
142 return "";141 return "";
...@@ -146,16 +145,16 @@ pub fn resolvePath(...@@ -146,16 +145,16 @@ pub fn resolvePath(
146145
147 // Heuristic for a fast path: if no component is absolute and ".." never appears, we just need to resolve `paths`.146 // Heuristic for a fast path: if no component is absolute and ".." never appears, we just need to resolve `paths`.
148 for (paths) |p| {147 for (paths) |p| {
149 if (fs.path.isAbsolute(p)) break; // absolute path148 if (Dir.path.isAbsolute(p)) break; // absolute path
150 if (mem.indexOf(u8, p, "..") != null) break; // may contain up-dir149 if (mem.indexOf(u8, p, "..") != null) break; // may contain up-dir
151 } else {150 } else {
152 // no absolute path, no "..".151 // no absolute path, no "..".
153 const res = try fs.path.resolve(gpa, paths);152 const res = try Dir.path.resolve(gpa, paths);
154 if (mem.eql(u8, res, ".")) {153 if (mem.eql(u8, res, ".")) {
155 gpa.free(res);154 gpa.free(res);
156 return "";155 return "";
157 }156 }
158 std.debug.assert(!fs.path.isAbsolute(res));157 std.debug.assert(!Dir.path.isAbsolute(res));
159 std.debug.assert(!isUpDir(res));158 std.debug.assert(!isUpDir(res));
160 return res;159 return res;
161 }160 }
...@@ -164,19 +163,19 @@ pub fn resolvePath(...@@ -164,19 +163,19 @@ pub fn resolvePath(
164 // Optimization: `paths` often has just one element.163 // Optimization: `paths` often has just one element.
165 const path_resolved = switch (paths.len) {164 const path_resolved = switch (paths.len) {
166 0 => unreachable,165 0 => unreachable,
167 1 => try fs.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),166 1 => try Dir.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),
168 else => r: {167 else => r: {
169 const all_paths = try gpa.alloc([]const u8, paths.len + 1);168 const all_paths = try gpa.alloc([]const u8, paths.len + 1);
170 defer gpa.free(all_paths);169 defer gpa.free(all_paths);
171 all_paths[0] = cwd_resolved;170 all_paths[0] = cwd_resolved;
172 @memcpy(all_paths[1..], paths);171 @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);
174 },173 },
175 };174 };
176 errdefer gpa.free(path_resolved);175 errdefer gpa.free(path_resolved);
177176
178 std.debug.assert(fs.path.isAbsolute(path_resolved));177 std.debug.assert(Dir.path.isAbsolute(path_resolved));
179 std.debug.assert(fs.path.isAbsolute(cwd_resolved));178 std.debug.assert(Dir.path.isAbsolute(cwd_resolved));
180179
181 if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd180 if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
182 if (path_resolved.len == cwd_resolved.len) {181 if (path_resolved.len == cwd_resolved.len) {
...@@ -184,7 +183,7 @@ pub fn resolvePath(...@@ -184,7 +183,7 @@ pub fn resolvePath(
184 gpa.free(path_resolved);183 gpa.free(path_resolved);
185 return "";184 return "";
186 }185 }
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
189 // in cwd; extract sub path188 // in cwd; extract sub path
190 const sub_path = try gpa.dupe(u8, path_resolved[cwd_resolved.len + 1 ..]);189 const sub_path = try gpa.dupe(u8, path_resolved[cwd_resolved.len + 1 ..]);
...@@ -192,9 +191,8 @@ pub fn resolvePath(...@@ -192,9 +191,8 @@ pub fn resolvePath(
192 return sub_path;191 return sub_path;
193}192}
194193
195/// TODO move this to std.fs.path
196pub fn isUpDir(p: []const u8) bool {194pub 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);
198}196}
199197
200pub const default_local_zig_cache_basename = ".zig-cache";198pub const default_local_zig_cache_basename = ".zig-cache";
...@@ -205,12 +203,12 @@ pub const default_local_zig_cache_basename = ".zig-cache";...@@ -205,12 +203,12 @@ pub const default_local_zig_cache_basename = ".zig-cache";
205pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 {203pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 {
206 var cur_dir = cwd;204 var cur_dir = cwd;
207 while (true) {205 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 });
209 if (Io.Dir.cwd().access(io, joined, .{})) |_| {207 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 });
211 } else |err| switch (err) {209 } else |err| switch (err) {
212 error.FileNotFound => {210 error.FileNotFound => {
213 cur_dir = fs.path.dirname(cur_dir) orelse return null;211 cur_dir = Dir.path.dirname(cur_dir) orelse return null;
214 continue;212 continue;
215 },213 },
216 else => return null,214 else => return null,
src/libs/freebsd.zig+2-2
...@@ -444,7 +444,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -444,7 +444,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
444 var cache: Cache = .{444 var cache: Cache = .{
445 .gpa = gpa,445 .gpa = gpa,
446 .io = io,446 .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", .{}),
448 };448 };
449 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });449 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
450 cache.addPrefix(comp.dirs.zig_lib);450 cache.addPrefix(comp.dirs.zig_lib);
...@@ -477,7 +477,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -477,7 +477,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
477 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });477 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
478478
479 var o_directory: Cache.Directory = .{479 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, .{}),
481 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),481 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
482 };482 };
483 defer o_directory.handle.close(io);483 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...@@ -679,7 +679,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
679 var cache: Cache = .{679 var cache: Cache = .{
680 .gpa = gpa,680 .gpa = gpa,
681 .io = io,681 .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", .{}),
683 };683 };
684 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });684 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
685 cache.addPrefix(comp.dirs.zig_lib);685 cache.addPrefix(comp.dirs.zig_lib);
...@@ -712,7 +712,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -712,7 +712,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
712 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });712 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
713713
714 var o_directory: Cache.Directory = .{714 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, .{}),
716 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),716 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
717 };717 };
718 defer o_directory.handle.close(io);718 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 {...@@ -258,7 +258,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
258 var cache: Cache = .{258 var cache: Cache = .{
259 .gpa = gpa,259 .gpa = gpa,
260 .io = io,260 .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", .{}),
262 };262 };
263 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });263 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
264 cache.addPrefix(comp.dirs.zig_lib);264 cache.addPrefix(comp.dirs.zig_lib);
...@@ -297,7 +297,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -297,7 +297,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
297297
298 const digest = man.final();298 const digest = man.final();
299 const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });299 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, .{});
301 defer o_dir.close(io);301 defer o_dir.close(io);
302302
303 const aro = @import("aro");303 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...@@ -385,7 +385,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
385 var cache: Cache = .{385 var cache: Cache = .{
386 .gpa = gpa,386 .gpa = gpa,
387 .io = io,387 .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", .{}),
389 };389 };
390 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });390 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
391 cache.addPrefix(comp.dirs.zig_lib);391 cache.addPrefix(comp.dirs.zig_lib);
...@@ -418,7 +418,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -418,7 +418,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
418 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });418 const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
419419
420 var o_directory: Cache.Directory = .{420 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, .{}),
422 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),422 .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
423 };423 };
424 defer o_directory.handle.close(io);424 defer o_directory.handle.close(io);
src/link.zig+7-8
...@@ -2170,28 +2170,27 @@ fn resolvePathInputLib(...@@ -2170,28 +2170,27 @@ fn resolvePathInputLib(
2170 }) {2170 }) {
2171 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {2171 var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) {
2172 error.FileNotFound => return .no_match,2172 error.FileNotFound => return .no_match,
2173 else => |e| fatal("unable to search for {s} library '{f}': {s}", .{2173 else => |e| fatal("unable to search for {t} library '{f}': {t}", .{
2174 @tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e),2174 link_mode, std.fmt.alt(test_path, .formatEscapeChar), e,
2175 }),2175 }),
2176 };2176 };
2177 errdefer file.close(io);2177 errdefer file.close(io);
2178 try ld_script_bytes.resize(gpa, @max(std.elf.MAGIC.len, std.elf.ARMAG.len));2178 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}", .{2179 const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err|
2180 std.fmt.alt(test_path, .formatEscapeChar), @errorName(err),2180 fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err });
2181 });
2182 const buf = ld_script_bytes.items[0..n];2181 const buf = ld_script_bytes.items[0..n];
2183 if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) {2182 if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) {
2184 // Appears to be an ELF or archive file.2183 // Appears to be an ELF or archive file.
2185 return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);2184 return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query);
2186 }2185 }
2187 const stat = file.stat(io) catch |err|2186 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 });
2189 const size = std.math.cast(u32, stat.size) orelse2188 const size = std.math.cast(u32, stat.size) orelse
2190 fatal("{f}: linker script too big", .{test_path});2189 fatal("{f}: linker script too big", .{test_path});
2191 try ld_script_bytes.resize(gpa, size);2190 try ld_script_bytes.resize(gpa, size);
2192 const buf2 = ld_script_bytes.items[n..];2191 const buf2 = ld_script_bytes.items[n..];
2193 const n2 = file.preadAll(buf2, n) catch |err|2192 const n2 = file.readPositionalAll(io, buf2, n) catch |err|
2194 fatal("failed to read {f}: {s}", .{ test_path, @errorName(err) });2193 fatal("failed to read {f}: {t}", .{ test_path, err });
2195 if (n2 != buf2.len) fatal("failed to read {f}: unexpected end of file", .{test_path});2194 if (n2 != buf2.len) fatal("failed to read {f}: unexpected end of file", .{test_path});
21962195
2197 // This `Io` is only used for a mutex, and we know we aren't doing anything async/concurrent.2196 // 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(...@@ -636,7 +636,7 @@ fn create(
636 const coff = try arena.create(Coff);636 const coff = try arena.create(Coff);
637 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{637 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
638 .read = true,638 .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),
640 });640 });
641 errdefer file.close(io);641 errdefer file.close(io);
642 coff.* = .{642 coff.* = .{
...@@ -653,7 +653,7 @@ fn create(...@@ -653,7 +653,7 @@ fn create(
653 .allow_shlib_undefined = false,653 .allow_shlib_undefined = false,
654 .stack_size = 0,654 .stack_size = 0,
655 },655 },
656 .mf = try .init(file, comp.gpa),656 .mf = try .init(file, comp.gpa, io),
657 .nodes = .empty,657 .nodes = .empty,
658 .import_table = .{658 .import_table = .{
659 .ni = .none,659 .ni = .none,
src/link/Dwarf.zig-1
...@@ -52,7 +52,6 @@ pub const UpdateError = error{...@@ -52,7 +52,6 @@ pub const UpdateError = error{
52 codegen.GenerateSymbolError ||52 codegen.GenerateSymbolError ||
53 Io.File.OpenError ||53 Io.File.OpenError ||
54 Io.File.LengthError ||54 Io.File.LengthError ||
55 Io.File.CopyRangeError ||
56 Io.File.ReadPositionalError ||55 Io.File.ReadPositionalError ||
57 Io.File.WritePositionalError;56 Io.File.WritePositionalError;
5857
src/link/Elf.zig+1-1
...@@ -320,7 +320,7 @@ pub fn createEmpty(...@@ -320,7 +320,7 @@ pub fn createEmpty(
320 self.base.file = try emit.root_dir.handle.createFile(io, sub_path, .{320 self.base.file = try emit.root_dir.handle.createFile(io, sub_path, .{
321 .truncate = true,321 .truncate = true,
322 .read = true,322 .read = true,
323 .mode = link.File.determineMode(output_mode, link_mode),323 .permissions = link.File.determinePermissions(output_mode, link_mode),
324 });324 });
325325
326 const gpa = comp.gpa;326 const gpa = comp.gpa;
src/link/Elf2.zig+2-2
...@@ -976,7 +976,7 @@ fn create(...@@ -976,7 +976,7 @@ fn create(
976 const elf = try arena.create(Elf);976 const elf = try arena.create(Elf);
977 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{977 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
978 .read = true,978 .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),
980 });980 });
981 errdefer file.close(io);981 errdefer file.close(io);
982 elf.* = .{982 elf.* = .{
...@@ -994,7 +994,7 @@ fn create(...@@ -994,7 +994,7 @@ fn create(
994 .stack_size = 0,994 .stack_size = 0,
995 },995 },
996 .options = options,996 .options = options,
997 .mf = try .init(file, comp.gpa),997 .mf = try .init(file, comp.gpa, io),
998 .ni = .{998 .ni = .{
999 .tls = .none,999 .tls = .none,
1000 },1000 },
src/link/MachO.zig+25-10
...@@ -224,7 +224,7 @@ pub fn createEmpty(...@@ -224,7 +224,7 @@ pub fn createEmpty(
224 self.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{224 self.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
225 .truncate = true,225 .truncate = true,
226 .read = true,226 .read = true,
227 .mode = link.File.determineMode(output_mode, link_mode),227 .permissions = link.File.determinePermissions(output_mode, link_mode),
228 });228 });
229229
230 // Append null file230 // Append null file
...@@ -3157,7 +3157,9 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) !?u64 {...@@ -3157,7 +3157,9 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) !?u64 {
3157 }3157 }
3158 }3158 }
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);
3161 return null;3163 return null;
3162}3164}
31633165
...@@ -3292,7 +3294,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {...@@ -3292,7 +3294,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {
3292 );3294 );
3293 defer gpa.free(d_sym_path);3295 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, .{});
3296 defer d_sym_bundle.close(io);3298 defer d_sym_bundle.close(io);
32973299
3298 self.d_sym.?.file = try d_sym_bundle.createFile(io, fs.path.basename(self.base.emit.sub_path), .{3300 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 {...@@ -3303,6 +3305,10 @@ pub fn reopenDebugInfo(self: *MachO) !void {
33033305
3304// TODO: move to ZigObject3306// TODO: move to ZigObject
3305fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {3307fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
3308 const comp = self.base.comp;
3309 const gpa = comp.gpa;
3310 const io = comp.io;
3311
3306 if (!self.base.isRelocatable()) {3312 if (!self.base.isRelocatable()) {
3307 const base_vmaddr = blk: {3313 const base_vmaddr = blk: {
3308 const pagezero_size = self.pagezero_size orelse default_pagezero_size;3314 const pagezero_size = self.pagezero_size orelse default_pagezero_size;
...@@ -3357,7 +3363,11 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {...@@ -3357,7 +3363,11 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
3357 if (options.zo.dwarf) |*dwarf| {3363 if (options.zo.dwarf) |*dwarf| {
3358 // Create dSYM bundle.3364 // Create dSYM bundle.
3359 log.debug("creating {s}.dSYM bundle", .{options.emit.sub_path});3365 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 };
3361 try self.reopenDebugInfo();3371 try self.reopenDebugInfo();
3362 try self.d_sym.?.initMetadata(self);3372 try self.d_sym.?.initMetadata(self);
3363 try dwarf.initMetadata();3373 try dwarf.initMetadata();
...@@ -3477,6 +3487,9 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo...@@ -3477,6 +3487,9 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
3477 const seg_id = self.sections.items(.segment_id)[sect_index];3487 const seg_id = self.sections.items(.segment_id)[sect_index];
3478 const seg = &self.segments.items[seg_id];3488 const seg = &self.segments.items[seg_id];
34793489
3490 const comp = self.base.comp;
3491 const io = comp.io;
3492
3480 if (!sect.isZerofill()) {3493 if (!sect.isZerofill()) {
3481 const allocated_size = self.allocatedSize(sect.offset);3494 const allocated_size = self.allocatedSize(sect.offset);
3482 if (needed_size > allocated_size) {3495 if (needed_size > allocated_size) {
...@@ -3498,7 +3511,7 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo...@@ -3498,7 +3511,7 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
34983511
3499 sect.offset = @intCast(new_offset);3512 sect.offset = @intCast(new_offset);
3500 } else if (sect.offset + allocated_size == std.math.maxInt(u64)) {3513 } 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);
3502 }3515 }
3503 seg.filesize = needed_size;3516 seg.filesize = needed_size;
3504 }3517 }
...@@ -3520,6 +3533,8 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo...@@ -3520,6 +3533,8 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo
3520}3533}
35213534
3522fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void {3535fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void {
3536 const comp = self.base.comp;
3537 const io = comp.io;
3523 const sect = &self.sections.items(.header)[sect_index];3538 const sect = &self.sections.items(.header)[sect_index];
35243539
3525 if (!sect.isZerofill()) {3540 if (!sect.isZerofill()) {
...@@ -3547,7 +3562,7 @@ fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void...@@ -3547,7 +3562,7 @@ fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void
3547 sect.offset = @intCast(new_offset);3562 sect.offset = @intCast(new_offset);
3548 sect.addr = new_addr;3563 sect.addr = new_addr;
3549 } else if (sect.offset + allocated_size == std.math.maxInt(u64)) {3564 } 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);
3551 }3566 }
3552 }3567 }
3553 sect.size = needed_size;3568 sect.size = needed_size;
...@@ -5346,12 +5361,12 @@ pub fn pwriteAll(macho_file: *MachO, bytes: []const u8, offset: u64) error{LinkF...@@ -5346,12 +5361,12 @@ pub fn pwriteAll(macho_file: *MachO, bytes: []const u8, offset: u64) error{LinkF
5346 };5361 };
5347}5362}
53485363
5349pub fn setEndPos(macho_file: *MachO, length: u64) error{LinkFailure}!void {5364pub fn setLength(macho_file: *MachO, length: u64) error{LinkFailure}!void {
5350 const comp = macho_file.base.comp;5365 const comp = macho_file.base.comp;
5366 const io = comp.io;
5351 const diags = &comp.link_diags;5367 const diags = &comp.link_diags;
5352 macho_file.base.file.?.setEndPos(length) catch |err| {5368 macho_file.base.file.?.setLength(io, length) catch |err|
5353 return diags.fail("failed to set file end pos: {s}", .{@errorName(err)});5369 return diags.fail("failed to set file end pos: {t}", .{err});
5354 };
5355}5370}
53565371
5357pub fn cast(macho_file: *MachO, comptime T: type, x: anytype) error{LinkFailure}!T {5372pub 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;...@@ -10,6 +10,7 @@ const assert = std.debug.assert;
10const linux = std.os.linux;10const linux = std.os.linux;
11const windows = std.os.windows;11const windows = std.os.windows;
1212
13io: Io,
13file: std.Io.File,14file: std.Io.File,
14flags: packed struct {15flags: packed struct {
15 block_size: std.mem.Alignment,16 block_size: std.mem.Alignment,
...@@ -36,8 +37,9 @@ pub const Error = std.posix.MMapError || std.posix.MRemapError || Io.File.Length...@@ -36,8 +37,9 @@ pub const Error = std.posix.MMapError || std.posix.MRemapError || Io.File.Length
36 NoSpaceLeft,37 NoSpaceLeft,
37};38};
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 {
40 var mf: MappedFile = .{41 var mf: MappedFile = .{
42 .io = io,
41 .file = file,43 .file = file,
42 .flags = undefined,44 .flags = undefined,
43 .section = if (is_windows) windows.INVALID_HANDLE_VALUE else {},45 .section = if (is_windows) windows.INVALID_HANDLE_VALUE else {},
...@@ -624,13 +626,14 @@ pub fn addNodeAfter(...@@ -624,13 +626,14 @@ pub fn addNodeAfter(
624}626}
625627
626fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested_size: u64) !void {628fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested_size: u64) !void {
629 const io = mf.io;
627 const node = ni.get(mf);630 const node = ni.get(mf);
628 const old_offset, const old_size = node.location().resolve(mf);631 const old_offset, const old_size = node.location().resolve(mf);
629 const new_size = node.flags.alignment.forward(@intCast(requested_size));632 const new_size = node.flags.alignment.forward(@intCast(requested_size));
630 // Resize the entire file633 // Resize the entire file
631 if (ni == Node.Index.root) {634 if (ni == Node.Index.root) {
632 try mf.ensureCapacityForSetLocation(gpa);635 try mf.ensureCapacityForSetLocation(gpa);
633 try mf.file.setEndPos(new_size);636 try mf.file.setLength(io, new_size);
634 try mf.ensureTotalCapacity(@intCast(new_size));637 try mf.ensureTotalCapacity(@intCast(new_size));
635 ni.setLocationAssumeCapacity(mf, old_offset, new_size);638 ni.setLocationAssumeCapacity(mf, old_offset, new_size);
636 return;639 return;
src/link/Wasm.zig+3-3
...@@ -3002,11 +3002,11 @@ pub fn createEmpty(...@@ -3002,11 +3002,11 @@ pub fn createEmpty(
3002 wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{3002 wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
3003 .truncate = true,3003 .truncate = true,
3004 .read = true,3004 .read = true,
3005 .mode = if (Io.File.Permissions.has_executable_bit)3005 .permissions = if (Io.File.Permissions.has_executable_bit)
3006 if (target.os.tag == .wasi and output_mode == .Exe)3006 if (target.os.tag == .wasi and output_mode == .Exe)
3007 Io.File.default_mode | 0b001_000_0003007 .executable_file
3008 else3008 else
3009 Io.File.default_mode3009 .default_file
3010 else3010 else
3011 0,3011 0,
3012 });3012 });
src/main.zig+73-82
...@@ -335,19 +335,20 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -335,19 +335,20 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
335 } else if (mem.eql(u8, cmd, "targets")) {335 } else if (mem.eql(u8, cmd, "targets")) {
336 dev.check(.targets_command);336 dev.check(.targets_command);
337 const host = std.zig.resolveTargetQueryOrFatal(io, .{});337 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);
339 try @import("print_targets.zig").cmdTargets(arena, io, cmd_args, &stdout_writer.interface, &host);339 try @import("print_targets.zig").cmdTargets(arena, io, cmd_args, &stdout_writer.interface, &host);
340 return stdout_writer.interface.flush();340 return stdout_writer.interface.flush();
341 } else if (mem.eql(u8, cmd, "version")) {341 } else if (mem.eql(u8, cmd, "version")) {
342 dev.check(.version_command);342 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");
344 return;344 return;
345 } else if (mem.eql(u8, cmd, "env")) {345 } else if (mem.eql(u8, cmd, "env")) {
346 dev.check(.env_command);346 dev.check(.env_command);
347 const host = std.zig.resolveTargetQueryOrFatal(io, .{});347 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);
349 try @import("print_env.zig").cmdEnv(349 try @import("print_env.zig").cmdEnv(
350 arena,350 arena,
351 io,
351 &stdout_writer.interface,352 &stdout_writer.interface,
352 args,353 args,
353 if (native_os == .wasi) wasi_preopens,354 if (native_os == .wasi) wasi_preopens,
...@@ -361,10 +362,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -361,10 +362,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
361 });362 });
362 } else if (mem.eql(u8, cmd, "zen")) {363 } else if (mem.eql(u8, cmd, "zen")) {
363 dev.check(.zen_command);364 dev.check(.zen_command);
364 return Io.File.stdout().writeAll(info_zen);365 return Io.File.stdout().writeStreamingAll(io, info_zen);
365 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {366 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
366 dev.check(.help_command);367 dev.check(.help_command);
367 return Io.File.stdout().writeAll(usage);368 return Io.File.stdout().writeStreamingAll(io, usage);
368 } else if (mem.eql(u8, cmd, "ast-check")) {369 } else if (mem.eql(u8, cmd, "ast-check")) {
369 return cmdAstCheck(arena, io, cmd_args);370 return cmdAstCheck(arena, io, cmd_args);
370 } else if (mem.eql(u8, cmd, "detect-cpu")) {371 } else if (mem.eql(u8, cmd, "detect-cpu")) {
...@@ -374,7 +375,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -374,7 +375,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
374 } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) {375 } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) {
375 return cmdDumpZir(arena, io, cmd_args);376 return cmdDumpZir(arena, io, cmd_args);
376 } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "llvm-ints")) {377 } 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);
378 } else {379 } else {
379 std.log.info("{s}", .{usage});380 std.log.info("{s}", .{usage});
380 fatal("unknown command: {s}", .{args[1]});381 fatal("unknown command: {s}", .{args[1]});
...@@ -701,7 +702,7 @@ const Emit = union(enum) {...@@ -701,7 +702,7 @@ const Emit = union(enum) {
701 yes: []const u8,702 yes: []const u8,
702703
703 const OutputToCacheReason = enum { listen, @"zig run", @"zig test" };704 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 {
705 return switch (emit) {706 return switch (emit) {
706 .no => .no,707 .no => .no,
707 .yes_default_path => if (output_to_cache != null) .yes_cache else .{ .yes_path = default_basename },708 .yes_default_path => if (output_to_cache != null) .yes_cache else .{ .yes_path = default_basename },
...@@ -1036,7 +1037,7 @@ fn buildOutputType(...@@ -1036,7 +1037,7 @@ fn buildOutputType(
1036 fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err });1037 fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err });
1037 } else if (mem.startsWith(u8, arg, "-")) {1038 } else if (mem.startsWith(u8, arg, "-")) {
1038 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {1039 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);
1040 return cleanExit();1041 return cleanExit();
1041 } else if (mem.eql(u8, arg, "--")) {1042 } else if (mem.eql(u8, arg, "--")) {
1042 if (arg_mode == .run) {1043 if (arg_mode == .run) {
...@@ -1858,9 +1859,7 @@ fn buildOutputType(...@@ -1858,9 +1859,7 @@ fn buildOutputType(
1858 var must_link = false;1859 var must_link = false;
1859 var file_ext: ?Compilation.FileExt = null;1860 var file_ext: ?Compilation.FileExt = null;
1860 while (it.has_next) {1861 while (it.has_next) {
1861 it.next() catch |err| {1862 it.next(io) catch |err| fatal("unable to parse command line parameters: {t}", .{err});
1862 fatal("unable to parse command line parameters: {s}", .{@errorName(err)});
1863 };
1864 switch (it.zig_equivalent) {1863 switch (it.zig_equivalent) {
1865 .target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown1864 .target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown
1866 .o => {1865 .o => {
...@@ -2836,9 +2835,9 @@ fn buildOutputType(...@@ -2836,9 +2835,9 @@ fn buildOutputType(
2836 } else if (mem.eql(u8, arg, "-V")) {2835 } else if (mem.eql(u8, arg, "-V")) {
2837 warn("ignoring request for supported emulations: unimplemented", .{});2836 warn("ignoring request for supported emulations: unimplemented", .{});
2838 } else if (mem.eql(u8, arg, "-v")) {2837 } 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");
2840 } else if (mem.eql(u8, arg, "--version")) {2839 } 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");
2842 process.exit(0);2841 process.exit(0);
2843 } else {2842 } else {
2844 fatal("unsupported linker arg: {s}", .{arg});2843 fatal("unsupported linker arg: {s}", .{arg});
...@@ -3077,14 +3076,13 @@ fn buildOutputType(...@@ -3077,14 +3076,13 @@ fn buildOutputType(
30773076
3078 const self_exe_path = switch (native_os) {3077 const self_exe_path = switch (native_os) {
3079 .wasi => {},3078 .wasi => {},
3080 else => fs.selfExePathAlloc(arena) catch |err| {3079 else => process.executablePathAlloc(io, arena) catch |err| fatal("unable to find zig self exe path: {t}", .{err}),
3081 fatal("unable to find zig self exe path: {s}", .{@errorName(err)});
3082 },
3083 };3080 };
30843081
3085 // This `init` calls `fatal` on error.3082 // This `init` calls `fatal` on error.
3086 var dirs: Compilation.Directories = .init(3083 var dirs: Compilation.Directories = .init(
3087 arena,3084 arena,
3085 io,
3088 override_lib_dir,3086 override_lib_dir,
3089 override_global_cache_dir,3087 override_global_cache_dir,
3090 s: {3088 s: {
...@@ -3097,11 +3095,9 @@ fn buildOutputType(...@@ -3097,11 +3095,9 @@ fn buildOutputType(
3097 if (native_os == .wasi) wasi_preopens,3095 if (native_os == .wasi) wasi_preopens,
3098 self_exe_path,3096 self_exe_path,
3099 );3097 );
3100 defer dirs.deinit();3098 defer dirs.deinit(io);
31013099
3102 if (linker_optimization) |o| {3100 if (linker_optimization) |o| warn("ignoring deprecated linker optimization setting '{s}'", .{o});
3103 warn("ignoring deprecated linker optimization setting '{s}'", .{o});
3104 }
31053101
3106 create_module.dirs = dirs;3102 create_module.dirs = dirs;
3107 create_module.opts.emit_llvm_ir = emit_llvm_ir != .no;3103 create_module.opts.emit_llvm_ir = emit_llvm_ir != .no;
...@@ -3324,18 +3320,18 @@ fn buildOutputType(...@@ -3324,18 +3320,18 @@ fn buildOutputType(
3324 };3320 };
33253321
3326 const default_h_basename = try std.fmt.allocPrint(arena, "{s}.h", .{root_name});3322 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
3329 const default_asm_basename = try std.fmt.allocPrint(arena, "{s}.s", .{root_name});3325 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
3332 const default_llvm_ir_basename = try std.fmt.allocPrint(arena, "{s}.ll", .{root_name});3328 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
3335 const default_llvm_bc_basename = try std.fmt.allocPrint(arena, "{s}.bc", .{root_name});3331 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
3340 const is_exe_or_dyn_lib = switch (create_module.resolved_options.output_mode) {3336 const is_exe_or_dyn_lib = switch (create_module.resolved_options.output_mode) {
3341 .Obj => false,3337 .Obj => false,
...@@ -3356,7 +3352,7 @@ fn buildOutputType(...@@ -3356,7 +3352,7 @@ fn buildOutputType(
3356 const default_implib_basename = try std.fmt.allocPrint(arena, "{s}.lib", .{root_name});3352 const default_implib_basename = try std.fmt.allocPrint(arena, "{s}.lib", .{root_name});
3357 const emit_implib_resolved: Compilation.CreateOptions.Emit = switch (emit_implib) {3353 const emit_implib_resolved: Compilation.CreateOptions.Emit = switch (emit_implib) {
3358 .no => .no,3354 .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),
3360 .yes_default_path => emit: {3356 .yes_default_path => emit: {
3361 if (output_to_cache != null) break :emit .yes_cache;3357 if (output_to_cache != null) break :emit .yes_cache;
3362 const p = try fs.path.join(arena, &.{3358 const p = try fs.path.join(arena, &.{
...@@ -3399,7 +3395,7 @@ fn buildOutputType(...@@ -3399,7 +3395,7 @@ fn buildOutputType(
3399 // for the hashing algorithm here and in the cache are the same.3395 // for the hashing algorithm here and in the cache are the same.
3400 // We are providing our own cache key, because this file has nothing3396 // We are providing our own cache key, because this file has nothing
3401 // to do with the cache manifest.3397 // to do with the cache manifest.
3402 var file_writer = f.writer(&.{});3398 var file_writer = f.writer(io, &.{});
3403 var buffer: [1000]u8 = undefined;3399 var buffer: [1000]u8 = undefined;
3404 var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);3400 var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);
3405 var stdin_reader = Io.File.stdin().readerStreaming(io, &.{});3401 var stdin_reader = Io.File.stdin().readerStreaming(io, &.{});
...@@ -3633,13 +3629,13 @@ fn buildOutputType(...@@ -3633,13 +3629,13 @@ fn buildOutputType(
3633 if (show_builtin) {3629 if (show_builtin) {
3634 const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config);3630 const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config);
3635 const source = try builtin_opts.generate(arena);3631 const source = try builtin_opts.generate(arena);
3636 return Io.File.stdout().writeAll(source);3632 return Io.File.stdout().writeStreamingAll(io, source);
3637 }3633 }
3638 switch (listen) {3634 switch (listen) {
3639 .none => {},3635 .none => {},
3640 .stdio => {3636 .stdio => {
3641 var stdin_reader = Io.File.stdin().reader(io, &stdin_buffer);3637 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);
3643 try serve(3639 try serve(
3644 comp,3640 comp,
3645 &stdin_reader.interface,3641 &stdin_reader.interface,
...@@ -3930,11 +3926,8 @@ fn createModule(...@@ -3930,11 +3926,8 @@ fn createModule(
3930 }3926 }
39313927
3932 if (target.isMinGW()) {3928 if (target.isMinGW()) {
3933 const exists = mingw.libExists(arena, target, create_module.dirs.zig_lib, lib_name) catch |err| {3929 const exists = mingw.libExists(arena, io, target, create_module.dirs.zig_lib, lib_name) catch |err|
3934 fatal("failed to check zig installation for DLL import libs: {s}", .{3930 fatal("failed to check zig installation for DLL import libs: {t}", .{err});
3935 @errorName(err),
3936 });
3937 };
3938 if (exists) {3931 if (exists) {
3939 try create_module.windows_libs.put(arena, lib_name, {});3932 try create_module.windows_libs.put(arena, lib_name, {});
3940 continue;3933 continue;
...@@ -4009,11 +4002,8 @@ fn createModule(...@@ -4009,11 +4002,8 @@ fn createModule(
4009 }4002 }
40104003
4011 if (create_module.libc_paths_file) |paths_file| {4004 if (create_module.libc_paths_file) |paths_file| {
4012 create_module.libc_installation = LibCInstallation.parse(arena, paths_file, target) catch |err| {4005 create_module.libc_installation = LibCInstallation.parse(arena, io, paths_file, target) catch |err|
4013 fatal("unable to parse libc paths file at path {s}: {s}", .{4006 fatal("unable to parse libc paths file at path {s}: {t}", .{ paths_file, err });
4014 paths_file, @errorName(err),
4015 });
4016 };
4017 }4007 }
40184008
4019 if (target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and4009 if (target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and
...@@ -4024,7 +4014,7 @@ fn createModule(...@@ -4024,7 +4014,7 @@ fn createModule(
4024 .verbose = true,4014 .verbose = true,
4025 .target = target,4015 .target = target,
4026 }) catch |err| {4016 }) catch |err| {
4027 fatal("unable to find native libc installation: {s}", .{@errorName(err)});4017 fatal("unable to find native libc installation: {t}", .{err});
4028 };4018 };
4029 }4019 }
4030 try create_module.lib_directories.ensureUnusedCapacity(arena, 2);4020 try create_module.lib_directories.ensureUnusedCapacity(arena, 2);
...@@ -4163,7 +4153,7 @@ fn serve(...@@ -4163,7 +4153,7 @@ fn serve(
41634153
4164 var child_pid: ?std.process.Child.Id = null;4154 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, .{});
4167 const file_system_inputs = comp.file_system_inputs.?;4157 const file_system_inputs = comp.file_system_inputs.?;
41684158
4169 const IncrementalDebugServer = if (build_options.enable_debug_extensions and !builtin.single_threaded)4159 const IncrementalDebugServer = if (build_options.enable_debug_extensions and !builtin.single_threaded)
...@@ -4694,7 +4684,7 @@ fn cmdTranslateC(...@@ -4694,7 +4684,7 @@ fn cmdTranslateC(
4694 });4684 });
4695 };4685 };
4696 defer zig_file.close(io);4686 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);
4698 var file_reader = zig_file.reader(io, &.{});4688 var file_reader = zig_file.reader(io, &.{});
4699 _ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited);4689 _ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited);
4700 try stdout_writer.interface.flush();4690 try stdout_writer.interface.flush();
...@@ -4744,7 +4734,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -4744,7 +4734,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
4744 if (mem.eql(u8, arg, "-m") or mem.eql(u8, arg, "--minimal")) {4734 if (mem.eql(u8, arg, "-m") or mem.eql(u8, arg, "--minimal")) {
4745 template = .minimal;4735 template = .minimal;
4746 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {4736 } 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);
4748 return cleanExit();4738 return cleanExit();
4749 } else {4739 } else {
4750 fatal("unrecognized parameter: '{s}'", .{arg});4740 fatal("unrecognized parameter: '{s}'", .{arg});
...@@ -4764,7 +4754,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -4764,7 +4754,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
4764 switch (template) {4754 switch (template) {
4765 .example => {4755 .example => {
4766 var templates = findTemplates(gpa, arena, io);4756 var templates = findTemplates(gpa, arena, io);
4767 defer templates.deinit();4757 defer templates.deinit(io);
47684758
4769 const s = fs.path.sep_str;4759 const s = fs.path.sep_str;
4770 const template_paths = [_][]const u8{4760 const template_paths = [_][]const u8{
...@@ -4898,7 +4888,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)...@@ -4898,7 +4888,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
4898 const argv_index_exe = child_argv.items.len;4888 const argv_index_exe = child_argv.items.len;
4899 _ = try child_argv.addOne();4889 _ = try child_argv.addOne();
49004890
4901 const self_exe_path = try fs.selfExePathAlloc(arena);4891 const self_exe_path = try process.executablePathAlloc(io, arena);
4902 try child_argv.append(self_exe_path);4892 try child_argv.append(self_exe_path);
49034893
4904 const argv_index_zig_lib_dir = child_argv.items.len;4894 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)...@@ -5079,7 +5069,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
50795069
5080 const work_around_btrfs_bug = native_os == .linux and5070 const work_around_btrfs_bug = native_os == .linux and
5081 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();5071 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
5082 const root_prog_node = std.Progress.start(.{5072 const root_prog_node = std.Progress.start(io, .{
5083 .disable_printing = (color == .off),5073 .disable_printing = (color == .off),
5084 .root_name = "Compile Build Script",5074 .root_name = "Compile Build Script",
5085 });5075 });
...@@ -5114,7 +5104,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)...@@ -5114,7 +5104,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
5114 const paths_file = debug_libc_paths_file orelse break :lci null;5104 const paths_file = debug_libc_paths_file orelse break :lci null;
5115 if (!build_options.enable_debug_extensions) unreachable;5105 if (!build_options.enable_debug_extensions) unreachable;
5116 const lci = try arena.create(LibCInstallation);5106 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);
5118 break :lci lci;5108 break :lci lci;
5119 };5109 };
51205110
...@@ -5129,6 +5119,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)...@@ -5129,6 +5119,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
5129 // This `init` calls `fatal` on error.5119 // This `init` calls `fatal` on error.
5130 var dirs: Compilation.Directories = .init(5120 var dirs: Compilation.Directories = .init(
5131 arena,5121 arena,
5122 io,
5132 override_lib_dir,5123 override_lib_dir,
5133 override_global_cache_dir,5124 override_global_cache_dir,
5134 .{ .override = path: {5125 .{ .override = path: {
...@@ -5138,7 +5129,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)...@@ -5138,7 +5129,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
5138 {},5129 {},
5139 self_exe_path,5130 self_exe_path,
5140 );5131 );
5141 defer dirs.deinit();5132 defer dirs.deinit(io);
51425133
5143 child_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;5134 child_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
5144 child_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;5135 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)...@@ -5421,11 +5412,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
5421 child.stderr_behavior = .Inherit;5412 child.stderr_behavior = .Inherit;
54225413
5423 const term = t: {5414 const term = t: {
5424 std.debug.lockStdErr();5415 _ = std.debug.lockStderrWriter(&.{});
5425 defer std.debug.unlockStdErr();5416 defer std.debug.unlockStderrWriter();
5426 break :t child.spawnAndWait(io) catch |err| {5417 break :t child.spawnAndWait(io) catch |err|
5427 fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err });5418 fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err });
5428 };
5429 };5419 };
54305420
5431 switch (term) {5421 switch (term) {
...@@ -5517,7 +5507,7 @@ fn jitCmd(...@@ -5517,7 +5507,7 @@ fn jitCmd(
5517 dev.check(.jit_command);5507 dev.check(.jit_command);
55185508
5519 const color: Color = .auto;5509 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, .{
5521 .disable_printing = (color == .off),5511 .disable_printing = (color == .off),
5522 });5512 });
55235513
...@@ -5529,9 +5519,8 @@ fn jitCmd(...@@ -5529,9 +5519,8 @@ fn jitCmd(
5529 .is_explicit_dynamic_linker = false,5519 .is_explicit_dynamic_linker = false,
5530 };5520 };
55315521
5532 const self_exe_path = fs.selfExePathAlloc(arena) catch |err| {5522 const self_exe_path = process.executablePathAlloc(io, arena) catch |err|
5533 fatal("unable to find self exe path: {s}", .{@errorName(err)});5523 fatal("unable to find self exe path: {t}", .{err});
5534 };
55355524
5536 const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet())5525 const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet())
5537 .Debug5526 .Debug
...@@ -5544,13 +5533,14 @@ fn jitCmd(...@@ -5544,13 +5533,14 @@ fn jitCmd(
5544 // This `init` calls `fatal` on error.5533 // This `init` calls `fatal` on error.
5545 var dirs: Compilation.Directories = .init(5534 var dirs: Compilation.Directories = .init(
5546 arena,5535 arena,
5536 io,
5547 override_lib_dir,5537 override_lib_dir,
5548 override_global_cache_dir,5538 override_global_cache_dir,
5549 .global,5539 .global,
5550 if (native_os == .wasi) wasi_preopens,5540 if (native_os == .wasi) wasi_preopens,
5551 self_exe_path,5541 self_exe_path,
5552 );5542 );
5553 defer dirs.deinit();5543 defer dirs.deinit(io);
55545544
5555 const thread_limit = @min(5545 const thread_limit = @min(
5556 @max(std.Thread.getCpuCount() catch 1, 1),5546 @max(std.Thread.getCpuCount() catch 1, 1),
...@@ -5629,7 +5619,7 @@ fn jitCmd(...@@ -5629,7 +5619,7 @@ fn jitCmd(
5629 defer comp.destroy();5619 defer comp.destroy();
56305620
5631 if (options.server) {5621 if (options.server) {
5632 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);5622 var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
5633 var server: std.zig.Server = .{5623 var server: std.zig.Server = .{
5634 .out = &stdout_writer.interface,5624 .out = &stdout_writer.interface,
5635 .in = undefined, // won't be receiving messages5625 .in = undefined, // won't be receiving messages
...@@ -5696,7 +5686,7 @@ fn jitCmd(...@@ -5696,7 +5686,7 @@ fn jitCmd(
5696 ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));5686 ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32)));
5697 }5687 }
56985688
5699 const term = try child.wait();5689 const term = try child.wait(io);
5700 switch (term) {5690 switch (term) {
5701 .Exited => |code| {5691 .Exited => |code| {
5702 if (code == 0) {5692 if (code == 0) {
...@@ -6160,7 +6150,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6160,7 +6150,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
6160 const arg = args[i];6150 const arg = args[i];
6161 if (mem.startsWith(u8, arg, "-")) {6151 if (mem.startsWith(u8, arg, "-")) {
6162 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {6152 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);
6164 return cleanExit();6154 return cleanExit();
6165 } else if (mem.eql(u8, arg, "-t")) {6155 } else if (mem.eql(u8, arg, "-t")) {
6166 want_output_text = true;6156 want_output_text = true;
...@@ -6211,7 +6201,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6211,7 +6201,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62116201
6212 const tree = try Ast.parse(arena, source, mode);6202 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);
6215 const stdout_bw = &stdout_writer.interface;6205 const stdout_bw = &stdout_writer.interface;
6216 switch (mode) {6206 switch (mode) {
6217 .zig => {6207 .zig => {
...@@ -6334,7 +6324,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {...@@ -6334,7 +6324,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
6334 const arg = args[i];6324 const arg = args[i];
6335 if (mem.startsWith(u8, arg, "-")) {6325 if (mem.startsWith(u8, arg, "-")) {
6336 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {6326 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);
6338 return cleanExit();6328 return cleanExit();
6339 } else if (mem.eql(u8, arg, "--llvm")) {6329 } else if (mem.eql(u8, arg, "--llvm")) {
6340 use_llvm = true;6330 use_llvm = true;
...@@ -6355,10 +6345,10 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {...@@ -6355,10 +6345,10 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void {
6355 const name = llvm.GetHostCPUName() orelse fatal("LLVM could not figure out the host cpu name", .{});6345 const name = llvm.GetHostCPUName() orelse fatal("LLVM could not figure out the host cpu name", .{});
6356 const features = llvm.GetHostCPUFeatures() orelse fatal("LLVM could not figure out the host cpu feature set", .{});6346 const features = llvm.GetHostCPUFeatures() orelse fatal("LLVM could not figure out the host cpu feature set", .{});
6357 const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features);6347 const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features);
6358 try printCpu(cpu);6348 try printCpu(io, cpu);
6359 } else {6349 } else {
6360 const host_target = std.zig.resolveTargetQueryOrFatal(io, .{});6350 const host_target = std.zig.resolveTargetQueryOrFatal(io, .{});
6361 try printCpu(host_target.cpu);6351 try printCpu(io, host_target.cpu);
6362 }6352 }
6363}6353}
63646354
...@@ -6425,8 +6415,8 @@ fn detectNativeCpuWithLLVM(...@@ -6425,8 +6415,8 @@ fn detectNativeCpuWithLLVM(
6425 return result;6415 return result;
6426}6416}
64276417
6428fn printCpu(cpu: std.Target.Cpu) !void {6418fn printCpu(io: Io, cpu: std.Target.Cpu) !void {
6429 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);6419 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
6430 const stdout_bw = &stdout_writer.interface;6420 const stdout_bw = &stdout_writer.interface;
64316421
6432 if (cpu.model.llvm_name) |llvm_name| {6422 if (cpu.model.llvm_name) |llvm_name| {
...@@ -6448,6 +6438,7 @@ fn printCpu(cpu: std.Target.Cpu) !void {...@@ -6448,6 +6438,7 @@ fn printCpu(cpu: std.Target.Cpu) !void {
6448fn cmdDumpLlvmInts(6438fn cmdDumpLlvmInts(
6449 gpa: Allocator,6439 gpa: Allocator,
6450 arena: Allocator,6440 arena: Allocator,
6441 io: Io,
6451 args: []const []const u8,6442 args: []const []const u8,
6452) !void {6443) !void {
6453 dev.check(.llvm_ints_command);6444 dev.check(.llvm_ints_command);
...@@ -6475,7 +6466,7 @@ fn cmdDumpLlvmInts(...@@ -6475,7 +6466,7 @@ fn cmdDumpLlvmInts(
6475 const dl = tm.createTargetDataLayout();6466 const dl = tm.createTargetDataLayout();
6476 const context = llvm.Context.create();6467 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);
6479 const stdout_bw = &stdout_writer.interface;6470 const stdout_bw = &stdout_writer.interface;
6480 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {6471 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
6481 const int_type = context.intType(bits);6472 const int_type = context.intType(bits);
...@@ -6501,7 +6492,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6501,7 +6492,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {
6501 defer f.close(io);6492 defer f.close(io);
65026493
6503 const zir = try Zcu.loadZirCache(arena, io, f);6494 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);
6505 const stdout_bw = &stdout_writer.interface;6496 const stdout_bw = &stdout_writer.interface;
6506 {6497 {
6507 const instruction_bytes = zir.instructions.len *6498 const instruction_bytes = zir.instructions.len *
...@@ -6585,7 +6576,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6585,7 +6576,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
6585 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;6576 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
6586 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);6577 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);
6589 const stdout_bw = &stdout_writer.interface;6580 const stdout_bw = &stdout_writer.interface;
6590 {6581 {
6591 try stdout_bw.print("Instruction mappings:\n", .{});6582 try stdout_bw.print("Instruction mappings:\n", .{});
...@@ -6917,7 +6908,7 @@ fn cmdFetch(...@@ -6917,7 +6908,7 @@ fn cmdFetch(
6917 const arg = args[i];6908 const arg = args[i];
6918 if (mem.startsWith(u8, arg, "-")) {6909 if (mem.startsWith(u8, arg, "-")) {
6919 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {6910 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);
6921 return cleanExit();6912 return cleanExit();
6922 } else if (mem.eql(u8, arg, "--global-cache-dir")) {6913 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
6923 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});6914 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
...@@ -6951,7 +6942,7 @@ fn cmdFetch(...@@ -6951,7 +6942,7 @@ fn cmdFetch(
69516942
6952 try http_client.initDefaultProxies(arena);6943 try http_client.initDefaultProxies(arena);
69536944
6954 var root_prog_node = std.Progress.start(.{6945 var root_prog_node = std.Progress.start(io, .{
6955 .root_name = "Fetch",6946 .root_name = "Fetch",
6956 });6947 });
6957 defer root_prog_node.end();6948 defer root_prog_node.end();
...@@ -6959,7 +6950,7 @@ fn cmdFetch(...@@ -6959,7 +6950,7 @@ fn cmdFetch(
6959 var global_cache_directory: Directory = l: {6950 var global_cache_directory: Directory = l: {
6960 const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);6951 const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);
6961 break :l .{6952 break :l .{
6962 .handle = try Io.Dir.cwd().makeOpenPath(p, .{}),6953 .handle = try Io.Dir.cwd().makeOpenPath(io, p, .{}),
6963 .path = p,6954 .path = p,
6964 };6955 };
6965 };6956 };
...@@ -7026,7 +7017,7 @@ fn cmdFetch(...@@ -7026,7 +7017,7 @@ fn cmdFetch(
70267017
7027 const name = switch (save) {7018 const name = switch (save) {
7028 .no => {7019 .no => {
7029 var stdout = Io.File.stdout().writerStreaming(&stdout_buffer);7020 var stdout = Io.File.stdout().writerStreaming(io, &stdout_buffer);
7030 try stdout.interface.print("{s}\n", .{package_hash_slice});7021 try stdout.interface.print("{s}\n", .{package_hash_slice});
7031 try stdout.interface.flush();7022 try stdout.interface.flush();
7032 return cleanExit();7023 return cleanExit();
...@@ -7044,7 +7035,7 @@ fn cmdFetch(...@@ -7044,7 +7035,7 @@ fn cmdFetch(
7044 var build_root = try findBuildRoot(arena, io, .{7035 var build_root = try findBuildRoot(arena, io, .{
7045 .cwd_path = cwd_path,7036 .cwd_path = cwd_path,
7046 });7037 });
7047 defer build_root.deinit();7038 defer build_root.deinit(io);
70487039
7049 // The name to use in case the manifest file needs to be created now.7040 // The name to use in case the manifest file needs to be created now.
7050 const init_root_name = fs.path.basename(build_root.directory.path orelse cwd_path);7041 const init_root_name = fs.path.basename(build_root.directory.path orelse cwd_path);
...@@ -7205,7 +7196,7 @@ fn createDependenciesModule(...@@ -7205,7 +7196,7 @@ fn createDependenciesModule(
7205 const rand_int = std.crypto.random.int(u64);7196 const rand_int = std.crypto.random.int(u64);
7206 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(rand_int);7197 const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(rand_int);
7207 {7198 {
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, .{});
7209 defer tmp_dir.close(io);7200 defer tmp_dir.close(io);
7210 try tmp_dir.writeFile(io, .{ .sub_path = basename, .data = source });7201 try tmp_dir.writeFile(io, .{ .sub_path = basename, .data = source });
7211 }7202 }
...@@ -7446,28 +7437,28 @@ fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const...@@ -7446,28 +7437,28 @@ fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const
7446 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });7437 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
7447 defer f.close(io);7438 defer f.close(io);
7448 var buf: [4096]u8 = undefined;7439 var buf: [4096]u8 = undefined;
7449 var fw = f.writer(&buf);7440 var fw = f.writer(io, &buf);
7450 try fw.interface.print(fmt, args);7441 try fw.interface.print(fmt, args);
7451 try fw.interface.flush();7442 try fw.interface.flush();
7452}7443}
74537444
7454fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates {7445fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates {
7455 const cwd_path = introspect.getResolvedCwd(arena) catch |err| {7446 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});
7457 };7448 };
7458 const self_exe_path = fs.selfExePathAlloc(arena) catch |err| {7449 const self_exe_path = process.executablePathAlloc(io, arena) catch |err| {
7459 fatal("unable to find self exe path: {s}", .{@errorName(err)});7450 fatal("unable to find self exe path: {t}", .{err});
7460 };7451 };
7461 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, io, cwd_path, self_exe_path) catch |err| {7452 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 });
7463 };7454 };
74647455
7465 const s = fs.path.sep_str;7456 const s = fs.path.sep_str;
7466 const template_sub_path = "init";7457 const template_sub_path = "init";
7467 const template_dir = zig_lib_directory.handle.openDir(io, template_sub_path, .{}) catch |err| {7458 const template_dir = zig_lib_directory.handle.openDir(io, template_sub_path, .{}) catch |err| {
7468 const path = zig_lib_directory.path orelse ".";7459 const path = zig_lib_directory.path orelse ".";
7469 fatal("unable to open zig project template directory '{s}{s}{s}': {s}", .{7460 fatal("unable to open zig project template directory '{s}{s}{s}': {t}", .{
7470 path, s, template_sub_path, @errorName(err),7461 path, s, template_sub_path, err,
7471 });7462 });
7472 };7463 };
74737464
src/print_env.zig+11-6
...@@ -1,13 +1,17 @@...@@ -1,13 +1,17 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const build_options = @import("build_options");2
4const Compilation = @import("Compilation.zig");3const std = @import("std");
4const Io = std.Io;
5const Allocator = std.mem.Allocator;5const Allocator = std.mem.Allocator;
6const EnvVar = std.zig.EnvVar;6const EnvVar = std.zig.EnvVar;
7const fatal = std.process.fatal;7const fatal = std.process.fatal;
88
9const build_options = @import("build_options");
10const Compilation = @import("Compilation.zig");
11
9pub fn cmdEnv(12pub fn cmdEnv(
10 arena: Allocator,13 arena: Allocator,
14 io: Io,
11 out: *std.Io.Writer,15 out: *std.Io.Writer,
12 args: []const []const u8,16 args: []const []const u8,
13 wasi_preopens: switch (builtin.target.os.tag) {17 wasi_preopens: switch (builtin.target.os.tag) {
...@@ -21,20 +25,21 @@ pub fn cmdEnv(...@@ -21,20 +25,21 @@ pub fn cmdEnv(
2125
22 const self_exe_path = switch (builtin.target.os.tag) {26 const self_exe_path = switch (builtin.target.os.tag) {
23 .wasi => args[0],27 .wasi => args[0],
24 else => std.fs.selfExePathAlloc(arena) catch |err| {28 else => std.process.executablePathAlloc(io, arena) catch |err| {
25 fatal("unable to find zig self exe path: {s}", .{@errorName(err)});29 fatal("unable to find zig self exe path: {t}", .{err});
26 },30 },
27 };31 };
2832
29 var dirs: Compilation.Directories = .init(33 var dirs: Compilation.Directories = .init(
30 arena,34 arena,
35 io,
31 override_lib_dir,36 override_lib_dir,
32 override_global_cache_dir,37 override_global_cache_dir,
33 .global,38 .global,
34 if (builtin.target.os.tag == .wasi) wasi_preopens,39 if (builtin.target.os.tag == .wasi) wasi_preopens,
35 if (builtin.target.os.tag != .wasi) self_exe_path,40 if (builtin.target.os.tag != .wasi) self_exe_path,
36 );41 );
37 defer dirs.deinit();42 defer dirs.deinit(io);
3843
39 const zig_lib_dir = dirs.zig_lib.path orelse "";44 const zig_lib_dir = dirs.zig_lib.path orelse "";
40 const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"});45 const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"});
src/print_targets.zig+8-8
...@@ -1,14 +1,16 @@...@@ -1,14 +1,16 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const fs = std.fs;3const fs = std.fs;
3const mem = std.mem;4const mem = std.mem;
4const meta = std.meta;5const meta = std.meta;
5const fatal = std.process.fatal;6const fatal = std.process.fatal;
6const Allocator = std.mem.Allocator;7const Allocator = std.mem.Allocator;
7const Target = std.Target;8const Target = std.Target;
8const target = @import("target.zig");
9const assert = std.debug.assert;9const assert = std.debug.assert;
10
10const glibc = @import("libs/glibc.zig");11const glibc = @import("libs/glibc.zig");
11const introspect = @import("introspect.zig");12const introspect = @import("introspect.zig");
13const target = @import("target.zig");
1214
13pub fn cmdTargets(15pub fn cmdTargets(
14 allocator: Allocator,16 allocator: Allocator,
...@@ -18,19 +20,19 @@ pub fn cmdTargets(...@@ -18,19 +20,19 @@ pub fn cmdTargets(
18 native_target: *const Target,20 native_target: *const Target,
19) !void {21) !void {
20 _ = args;22 _ = args;
21 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {23 var zig_lib_directory = introspect.findZigLibDir(allocator, io) catch |err|
22 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});24 fatal("unable to find zig installation directory: {t}", .{err});
23 };
24 defer zig_lib_directory.handle.close(io);25 defer zig_lib_directory.handle.close(io);
25 defer allocator.free(zig_lib_directory.path.?);26 defer allocator.free(zig_lib_directory.path.?);
2627
27 const abilists_contents = zig_lib_directory.handle.readFileAlloc(28 const abilists_contents = zig_lib_directory.handle.readFileAlloc(
29 io,
28 glibc.abilists_path,30 glibc.abilists_path,
29 allocator,31 allocator,
30 .limited(glibc.abilists_max_size),32 .limited(glibc.abilists_max_size),
31 ) catch |err| switch (err) {33 ) catch |err| switch (err) {
32 error.OutOfMemory => return error.OutOfMemory,34 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}),
34 };36 };
35 defer allocator.free(abilists_contents);37 defer allocator.free(abilists_contents);
3638
...@@ -49,9 +51,7 @@ pub fn cmdTargets(...@@ -49,9 +51,7 @@ pub fn cmdTargets(
49 {51 {
50 var libc_obj = try root_obj.beginTupleField("libc", .{});52 var libc_obj = try root_obj.beginTupleField("libc", .{});
51 for (std.zig.target.available_libcs) |libc| {53 for (std.zig.target.available_libcs) |libc| {
52 const tmp = try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{54 const tmp = try std.fmt.allocPrint(allocator, "{t}-{t}-{t}", .{ libc.arch, libc.os, libc.abi });
53 @tagName(libc.arch), @tagName(libc.os), @tagName(libc.abi),
54 });
55 defer allocator.free(tmp);55 defer allocator.free(tmp);
56 try libc_obj.field(tmp, .{});56 try libc_obj.field(tmp, .{});
57 }57 }
test/standalone/self_exe_symlink/main.zig+1-1
...@@ -9,7 +9,7 @@ pub fn main() !void {...@@ -9,7 +9,7 @@ pub fn main() !void {
9 defer threaded.deinit();9 defer threaded.deinit();
10 const io = threaded.io();10 const io = threaded.io();
1111
12 const self_path = try std.fs.selfExePathAlloc(gpa);12 const self_path = try std.process.executablePathAlloc(io, gpa);
13 defer gpa.free(self_path);13 defer gpa.free(self_path);
1414
15 var self_exe = try std.fs.openSelfExe(.{});15 var self_exe = try std.fs.openSelfExe(.{});