| author | |
| committer | |
| log | 16f8af1b9a7a287ac6fdefec5949725c55cbe179 |
| tree | 2a1a3e3fb9f7ad20da5480e1dc21a337b02830c4 |
| parent | e1cf753db72425fd944f6fe9f2a991fb1de3f942 |
32 files changed, 228 insertions(+), 219 deletions(-)
lib/compiler/aro/main.zig+1-1| ... | ... | @@ -43,7 +43,7 @@ pub fn main() u8 { |
| 43 | 43 | return 1; |
| 44 | 44 | }; |
| 45 | 45 | |
| 46 | const aro_name = std.fs.selfExePathAlloc(gpa) catch { | |
| 46 | const aro_name = process.executablePathAlloc(io, gpa) catch { | |
| 47 | 47 | std.debug.print("unable to find Aro executable path\n", .{}); |
| 48 | 48 | if (fast_exit) process.exit(1); |
| 49 | 49 | return 1; |
lib/std/Build/Cache.zig+4-4| ... | ... | @@ -1330,7 +1330,7 @@ test "cache file and then recall it" { |
| 1330 | 1330 | var cache: Cache = .{ |
| 1331 | 1331 | .io = io, |
| 1332 | 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 | 1335 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1336 | 1336 | defer cache.manifest_dir.close(io); |
| ... | ... | @@ -1396,7 +1396,7 @@ test "check that changing a file makes cache fail" { |
| 1396 | 1396 | var cache: Cache = .{ |
| 1397 | 1397 | .io = io, |
| 1398 | 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 | 1401 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1402 | 1402 | defer cache.manifest_dir.close(io); |
| ... | ... | @@ -1456,7 +1456,7 @@ test "no file inputs" { |
| 1456 | 1456 | var cache: Cache = .{ |
| 1457 | 1457 | .io = io, |
| 1458 | 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 | 1461 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1462 | 1462 | defer cache.manifest_dir.close(io); |
| ... | ... | @@ -1515,7 +1515,7 @@ test "Manifest with files added after initial hash work" { |
| 1515 | 1515 | var cache: Cache = .{ |
| 1516 | 1516 | .io = io, |
| 1517 | 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 | 1520 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1521 | 1521 | defer cache.manifest_dir.close(io); |
lib/std/Build/Cache/Path.zig+2-2| ... | ... | @@ -84,14 +84,14 @@ pub fn openDir( |
| 84 | 84 | return p.root_dir.handle.openDir(io, joined_path, args); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir { | |
| 87 | pub fn makeOpenPath(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir { | |
| 88 | 88 | var buf: [fs.max_path_bytes]u8 = undefined; |
| 89 | 89 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 90 | 90 | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 91 | 91 | p.sub_path, sub_path, |
| 92 | 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 | } |
| 96 | 96 | |
| 97 | 97 | pub 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 | 1588 | |
| 1589 | 1589 | pub const CopyFileError = File.OpenError || File.StatError || |
| 1590 | 1590 | File.Atomic.InitError || File.Atomic.FinishError || |
| 1591 | File.Reader.Error || File.WriteError || error{InvalidFileName}; | |
| 1591 | File.Reader.Error || File.Writer.Error || error{InvalidFileName}; | |
| 1592 | 1592 | |
| 1593 | 1593 | /// Atomically creates a new file at `dest_path` within `dest_dir` with the |
| 1594 | 1594 | /// 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 | 242 | } |
| 243 | 243 | |
| 244 | 244 | pub const AddCertsFromFileError = Allocator.Error || |
| 245 | Io.File.GetSeekPosError || | |
| 246 | Io.File.ReadError || | |
| 245 | Io.File.Reader.Error || | |
| 247 | 246 | ParseCertError || |
| 248 | 247 | std.base64.Error || |
| 249 | 248 | error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming }; |
lib/std/crypto/Certificate/Bundle/macos.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const mem = std.mem; |
| 6 | 6 | const Allocator = std.mem.Allocator; |
| 7 | 7 | const Bundle = @import("../Bundle.zig"); |
| 8 | 8 | |
| 9 | pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.ReadError || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream}; | |
| 9 | pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.Reader.Error || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream}; | |
| 10 | 10 | |
| 11 | 11 | pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void { |
| 12 | 12 | cb.bytes.clearRetainingCapacity(); |
lib/std/fs/test.zig+7-7| ... | ... | @@ -213,7 +213,7 @@ test "Dir.readLink" { |
| 213 | 213 | // test 3: relative path symlink |
| 214 | 214 | const parent_file = ".." ++ fs.path.sep_str ++ "target.txt"; |
| 215 | 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 | 217 | defer subdir.close(io); |
| 218 | 218 | try setupSymlink(io, subdir, canonical_parent_file, "relative-link.txt", .{}); |
| 219 | 219 | try testReadLink(io, subdir, canonical_parent_file, "relative-link.txt"); |
| ... | ... | @@ -411,7 +411,7 @@ test "openDir non-cwd parent '..'" { |
| 411 | 411 | var tmp = tmpDir(.{}); |
| 412 | 412 | defer tmp.cleanup(); |
| 413 | 413 | |
| 414 | var subdir = try tmp.dir.makeOpenPath("subdir", .{}); | |
| 414 | var subdir = try tmp.dir.makeOpenPath(io, "subdir", .{}); | |
| 415 | 415 | defer subdir.close(io); |
| 416 | 416 | |
| 417 | 417 | var dir = try subdir.openDir(io, "..", .{}); |
| ... | ... | @@ -613,7 +613,7 @@ test "Dir.Iterator but dir is deleted during iteration" { |
| 613 | 613 | defer tmp.cleanup(); |
| 614 | 614 | |
| 615 | 615 | // 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 | 617 | defer subdir.close(io); |
| 618 | 618 | |
| 619 | 619 | var iterator = subdir.iterate(); |
| ... | ... | @@ -862,7 +862,7 @@ test "makeOpenPath parent dirs do not exist" { |
| 862 | 862 | var tmp_dir = tmpDir(.{}); |
| 863 | 863 | defer tmp_dir.cleanup(); |
| 864 | 864 | |
| 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 | 866 | dir.close(io); |
| 867 | 867 | |
| 868 | 868 | // double check that the full directory structure was created |
| ... | ... | @@ -1010,7 +1010,7 @@ test "Dir.rename directory onto non-empty dir" { |
| 1010 | 1010 | |
| 1011 | 1011 | try ctx.dir.makeDir(io, test_dir_path, .default_dir); |
| 1012 | 1012 | |
| 1013 | var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{}); | |
| 1013 | var target_dir = try ctx.dir.makeOpenPath(io, target_dir_path, .{}); | |
| 1014 | 1014 | var file = try target_dir.createFile(io, "test_file", .{ .read = true }); |
| 1015 | 1015 | file.close(io); |
| 1016 | 1016 | target_dir.close(io); |
| ... | ... | @@ -1147,7 +1147,7 @@ test "deleteTree does not follow symlinks" { |
| 1147 | 1147 | |
| 1148 | 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 | 1151 | defer a.close(io); |
| 1152 | 1152 | |
| 1153 | 1153 | try setupSymlink(io, a, "../b", "b", .{ .is_directory = true }); |
| ... | ... | @@ -1346,7 +1346,7 @@ test "makepath ignores '.'" { |
| 1346 | 1346 | fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void { |
| 1347 | 1347 | // 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 | 1350 | defer maxed_dir.close(io); |
| 1351 | 1351 | |
| 1352 | 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 | 142 | const target_name = "link-target"; |
| 143 | 143 | const link_name = "newlink"; |
| 144 | 144 | |
| 145 | const subdir = try tmp.dir.makeOpenPath("subdir", .{}); | |
| 145 | const subdir = try tmp.dir.makeOpenPath(io, "subdir", .{}); | |
| 146 | 146 | |
| 147 | 147 | defer tmp.dir.deleteFile(io, target_name) catch {}; |
| 148 | 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 | 117 | return record; |
| 118 | 118 | } |
| 119 | 119 | |
| 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 | 121 | ZipNoEndRecord, |
| 122 | 122 | EndOfStream, |
| 123 | 123 | ReadFailed, |
| ... | ... | @@ -560,7 +560,7 @@ pub const Iterator = struct { |
| 560 | 560 | |
| 561 | 561 | const out_file = blk: { |
| 562 | 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 | 564 | defer parent_dir.close(io); |
| 565 | 565 | |
| 566 | 566 | const basename = std.fs.path.basename(filename); |
src/Compilation.zig+15-15| ... | ... | @@ -832,7 +832,7 @@ pub const Directories = struct { |
| 832 | 832 | const nonempty_path = if (path.len == 0) "." else path; |
| 833 | 833 | const handle_or_err = switch (thing) { |
| 834 | 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 | 837 | return .{ |
| 838 | 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 | 2111 | cache.* = .{ |
| 2112 | 2112 | .gpa = gpa, |
| 2113 | 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 | 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 | 2161 | // to redundantly happen for each AstGen operation. |
| 2162 | 2162 | const zir_sub_dir = "z"; |
| 2163 | 2163 | |
| 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 | 2165 | return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = zir_sub_dir, .err = err } }); |
| 2166 | 2166 | }; |
| 2167 | 2167 | errdefer local_zir_dir.close(io); |
| ... | ... | @@ -2169,7 +2169,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, |
| 2169 | 2169 | .handle = local_zir_dir, |
| 2170 | 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 | 2173 | return diag.fail(.{ .create_cache_path = .{ .which = .global, .sub = zir_sub_dir, .err = err } }); |
| 2174 | 2174 | }; |
| 2175 | 2175 | errdefer global_zir_dir.close(io); |
| ... | ... | @@ -2440,7 +2440,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, |
| 2440 | 2440 | const digest = hash.final(); |
| 2441 | 2441 | |
| 2442 | 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 | 2444 | return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = artifact_sub_dir, .err = err } }); |
| 2445 | 2445 | }; |
| 2446 | 2446 | errdefer artifact_dir.close(io); |
| ... | ... | @@ -2895,7 +2895,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE |
| 2895 | 2895 | tmp_dir_rand_int = std.crypto.random.int(u64); |
| 2896 | 2896 | const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int); |
| 2897 | 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 | 2899 | return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err }); |
| 2900 | 2900 | }; |
| 2901 | 2901 | break :d .{ .path = path, .handle = handle }; |
| ... | ... | @@ -2976,7 +2976,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE |
| 2976 | 2976 | tmp_dir_rand_int = std.crypto.random.int(u64); |
| 2977 | 2977 | const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int); |
| 2978 | 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 | 2980 | return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err }); |
| 2981 | 2981 | }; |
| 2982 | 2982 | break :d .{ .path = path, .handle = handle }; |
| ... | ... | @@ -5267,7 +5267,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void { |
| 5267 | 5267 | const io = comp.io; |
| 5268 | 5268 | |
| 5269 | 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 | 5271 | return comp.lockAndSetMiscFailure( |
| 5272 | 5272 | .docs_copy, |
| 5273 | 5273 | "unable to create output directory '{f}': {s}", |
| ... | ... | @@ -5509,7 +5509,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU |
| 5509 | 5509 | assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory |
| 5510 | 5510 | |
| 5511 | 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 | 5513 | comp.lockAndSetMiscFailure( |
| 5514 | 5514 | .docs_copy, |
| 5515 | 5515 | "unable to create output directory '{f}': {t}", |
| ... | ... | @@ -5699,7 +5699,7 @@ pub fn translateC( |
| 5699 | 5699 | const tmp_basename = std.fmt.hex(std.crypto.random.int(u64)); |
| 5700 | 5700 | const tmp_sub_path = "tmp" ++ fs.path.sep_str ++ tmp_basename; |
| 5701 | 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 | 5703 | defer cache_tmp_dir.close(io); |
| 5704 | 5704 | |
| 5705 | 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 | 6274 | // We can't know the digest until we do the C compiler invocation, |
| 6275 | 6275 | // so we need a temporary filename. |
| 6276 | 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 | 6278 | defer zig_cache_tmp_dir.close(io); |
| 6279 | 6279 | |
| 6280 | 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 | 6439 | // Rename into place. |
| 6440 | 6440 | const digest = man.final(); |
| 6441 | 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 | 6443 | defer o_dir.close(io); |
| 6444 | 6444 | const tmp_basename = fs.path.basename(out_obj_path); |
| 6445 | 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 | 6528 | const digest = man.final(); |
| 6529 | 6529 | |
| 6530 | 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 | 6532 | defer o_dir.close(io); |
| 6533 | 6533 | |
| 6534 | 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 | 6616 | const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len]; |
| 6617 | 6617 | |
| 6618 | 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 | 6620 | defer zig_cache_tmp_dir.close(io); |
| 6621 | 6621 | |
| 6622 | 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 | 6687 | // Rename into place. |
| 6688 | 6688 | const digest = man.final(); |
| 6689 | 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 | 6691 | defer o_dir.close(io); |
| 6692 | 6692 | const tmp_basename = fs.path.basename(out_res_path); |
| 6693 | 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 | 500 | var tmp_directory: Cache.Directory = .{ |
| 501 | 501 | .path = tmp_directory_path, |
| 502 | 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 | 504 | .iterate = true, |
| 505 | 505 | }) catch |err| { |
| 506 | 506 | try eb.addRootErrorMessage(.{ |
| 507 | .msg = try eb.printString("unable to create temporary directory '{s}': {s}", .{ | |
| 508 | tmp_directory_path, @errorName(err), | |
| 507 | .msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{ | |
| 508 | tmp_directory_path, err, | |
| 509 | 509 | }), |
| 510 | 510 | }); |
| 511 | 511 | return error.FetchFailed; |
| ... | ... | @@ -524,7 +524,7 @@ fn runResource( |
| 524 | 524 | if (native_os == .linux and f.job_queue.work_around_btrfs_bug) { |
| 525 | 525 | // https://github.com/ziglang/zig/issues/17095 |
| 526 | 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 | 528 | .iterate = true, |
| 529 | 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 | 1366 | // we do not attempt to replicate the exact structure of a real .git |
| 1367 | 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 | 1370 | defer pack_dir.close(io); |
| 1371 | 1371 | var pack_file = try pack_dir.createFile(io, "pkg.pack", .{ .read = true }); |
| 1372 | 1372 | defer pack_file.close(io); |
| ... | ... | @@ -1743,7 +1743,7 @@ const HashedFile = struct { |
| 1743 | 1743 | |
| 1744 | 1744 | const Error = |
| 1745 | 1745 | Io.File.OpenError || |
| 1746 | Io.File.ReadError || | |
| 1746 | Io.File.Reader.Error || | |
| 1747 | 1747 | Io.File.StatError || |
| 1748 | 1748 | Io.File.ChmodError || |
| 1749 | 1749 | Io.Dir.ReadLinkError; |
| ... | ... | @@ -2258,7 +2258,7 @@ const TestFetchBuilder = struct { |
| 2258 | 2258 | cache_parent_dir: std.Io.Dir, |
| 2259 | 2259 | path_or_url: []const u8, |
| 2260 | 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", .{}); | |
| 2262 | 2262 | |
| 2263 | 2263 | self.http_client = .{ .allocator = allocator, .io = io }; |
| 2264 | 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 | 1720 | var pack_file_reader = pack_file.reader(io, &pack_file_buffer); |
| 1721 | 1721 | |
| 1722 | 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 | 1724 | defer worktree.close(io); |
| 1725 | 1725 | |
| 1726 | var git_dir = try worktree.makeOpenPath(".git", .{}); | |
| 1726 | var git_dir = try worktree.makeOpenPath(io, ".git", .{}); | |
| 1727 | 1727 | defer git_dir.close(io); |
| 1728 | 1728 | |
| 1729 | 1729 | std.debug.print("Starting index...\n", .{}); |
src/Zcu.zig+1-1| ... | ... | @@ -1200,7 +1200,7 @@ pub const EmbedFile = struct { |
| 1200 | 1200 | /// `.none` means the file was not loaded, so `stat` is undefined. |
| 1201 | 1201 | val: InternPool.Index, |
| 1202 | 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 | 1204 | stat: Cache.File.Stat, |
| 1205 | 1205 | |
| 1206 | 1206 | pub const Index = enum(u32) { |
src/crash_report.zig+5-5| ... | ... | @@ -95,19 +95,19 @@ fn dumpCrashContext() Io.Writer.Error!void { |
| 95 | 95 | |
| 96 | 96 | // TODO: this does mean that a different thread could grab the stderr mutex between the context |
| 97 | 97 | // and the actual panic printing, which would be quite confusing. |
| 98 | const stderr, _ = std.debug.lockStderrWriter(&.{}); | |
| 98 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 99 | 99 | defer std.debug.unlockStderrWriter(); |
| 100 | 100 | |
| 101 | try stderr.writeAll("Compiler crash context:\n"); | |
| 101 | try stderr.interface.writeAll("Compiler crash context:\n"); | |
| 102 | 102 | |
| 103 | 103 | if (CodegenFunc.current) |*cg| { |
| 104 | 104 | const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav; |
| 105 | 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 | 107 | } else if (AnalyzeBody.current) |anal| { |
| 108 | try dumpCrashContextSema(anal, stderr, &S.crash_heap); | |
| 108 | try dumpCrashContextSema(anal, &stderr.interface, &S.crash_heap); | |
| 109 | 109 | } else { |
| 110 | try stderr.writeAll("(no context)\n\n"); | |
| 110 | try stderr.interface.writeAll("(no context)\n\n"); | |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | fn 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 | 59 | const arg = args[i]; |
| 60 | 60 | if (mem.startsWith(u8, arg, "-")) { |
| 61 | 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 | 63 | return process.cleanExit(); |
| 64 | 64 | } else if (mem.eql(u8, arg, "--color")) { |
| 65 | 65 | if (i + 1 >= args.len) { |
| ... | ... | @@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 154 | 154 | process.exit(code); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | return Io.File.stdout().writeAll(formatted); | |
| 157 | return Io.File.stdout().writeStreamingAll(io, formatted); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 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 | 162 | } |
| 163 | 163 | |
| 164 | 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); | |
| 166 | 166 | |
| 167 | 167 | var fmt: Fmt = .{ |
| 168 | 168 | .gpa = gpa, |
| ... | ... | @@ -231,7 +231,7 @@ fn fmtPathDir( |
| 231 | 231 | if (try fmt.seen.fetchPut(stat.inode, {})) |_| return; |
| 232 | 232 | |
| 233 | 233 | var dir_it = dir.iterate(); |
| 234 | while (try dir_it.next()) |entry| { | |
| 234 | while (try dir_it.next(io)) |entry| { | |
| 235 | 235 | const is_dir = entry.kind == .directory; |
| 236 | 236 | |
| 237 | 237 | if (mem.startsWith(u8, entry.name, ".")) continue; |
| ... | ... | @@ -244,7 +244,7 @@ fn fmtPathDir( |
| 244 | 244 | try fmtPathDir(fmt, full_path, check_mode, dir, entry.name); |
| 245 | 245 | } else { |
| 246 | 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 | 248 | fmt.any_error = true; |
| 249 | 249 | return; |
| 250 | 250 | }; |
| ... | ... | @@ -355,7 +355,7 @@ fn fmtPathFile( |
| 355 | 355 | try fmt.stdout_writer.interface.print("{s}\n", .{file_path}); |
| 356 | 356 | fmt.any_error = true; |
| 357 | 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 | 359 | defer af.deinit(); |
| 360 | 360 | |
| 361 | 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 | 3 | |
| 4 | 4 | const std = @import("std"); |
| 5 | 5 | const Io = std.Io; |
| 6 | const Dir = std.Io.Dir; | |
| 6 | 7 | const mem = std.mem; |
| 7 | 8 | const Allocator = std.mem.Allocator; |
| 8 | const os = std.os; | |
| 9 | const fs = std.fs; | |
| 10 | 9 | const Cache = std.Build.Cache; |
| 11 | 10 | |
| 12 | 11 | const Compilation = @import("Compilation.zig"); |
| ... | ... | @@ -16,11 +15,11 @@ const Package = @import("Package.zig"); |
| 16 | 15 | /// The path of the returned Directory is relative to `base`. |
| 17 | 16 | /// The handle of the returned Directory is open. |
| 18 | 17 | fn 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"; | |
| 20 | 19 | |
| 21 | 20 | zig_dir: { |
| 22 | 21 | // 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 | 23 | var test_zig_dir = base_dir.openDir(io, lib_zig, .{}) catch break :zig_dir; |
| 25 | 24 | const file = test_zig_dir.openFile(io, test_index_file, .{}) catch { |
| 26 | 25 | test_zig_dir.close(io); |
| ... | ... | @@ -44,13 +43,13 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory { |
| 44 | 43 | pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory { |
| 45 | 44 | const cwd_path = try getResolvedCwd(gpa); |
| 46 | 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 | 47 | defer gpa.free(self_exe_path); |
| 49 | 48 | |
| 50 | 49 | return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path); |
| 51 | 50 | } |
| 52 | 51 | |
| 53 | /// Like `std.process.getCwdAlloc`, but also resolves the path with `std.fs.path.resolve`. This | |
| 52 | /// Like `std.process.getCwdAlloc`, but also resolves the path with `Dir.path.resolve`. This | |
| 54 | 53 | /// means the path has no repeated separators, no "." or ".." components, and no trailing separator. |
| 55 | 54 | /// On WASI, "" is returned instead of ".". |
| 56 | 55 | pub fn getResolvedCwd(gpa: Allocator) error{ |
| ... | ... | @@ -68,8 +67,8 @@ pub fn getResolvedCwd(gpa: Allocator) error{ |
| 68 | 67 | } |
| 69 | 68 | const cwd = try std.process.getCwdAlloc(gpa); |
| 70 | 69 | defer gpa.free(cwd); |
| 71 | const resolved = try fs.path.resolve(gpa, &.{cwd}); | |
| 72 | std.debug.assert(fs.path.isAbsolute(resolved)); | |
| 70 | const resolved = try Dir.path.resolve(gpa, &.{cwd}); | |
| 71 | std.debug.assert(Dir.path.isAbsolute(resolved)); | |
| 73 | 72 | return resolved; |
| 74 | 73 | } |
| 75 | 74 | |
| ... | ... | @@ -84,12 +83,12 @@ pub fn findZigLibDirFromSelfExe( |
| 84 | 83 | ) error{ OutOfMemory, FileNotFound }!Cache.Directory { |
| 85 | 84 | const cwd = Io.Dir.cwd(); |
| 86 | 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 | 87 | var base_dir = cwd.openDir(io, dirname, .{}) catch continue; |
| 89 | 88 | defer base_dir.close(io); |
| 90 | 89 | |
| 91 | 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 | 92 | defer allocator.free(p); |
| 94 | 93 | |
| 95 | 94 | const resolved = try resolvePath(allocator, cwd_path, &.{p}); |
| ... | ... | @@ -113,18 +112,18 @@ pub fn resolveGlobalCacheDir(allocator: Allocator) ![]u8 { |
| 113 | 112 | if (builtin.os.tag != .windows) { |
| 114 | 113 | if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| { |
| 115 | 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 | 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 | } |
| 123 | 122 | |
| 124 | return fs.getAppDataDir(allocator, appname); | |
| 123 | return std.fs.getAppDataDir(allocator, appname); | |
| 125 | 124 | } |
| 126 | 125 | |
| 127 | /// Similar to `fs.path.resolve`, but converts to a cwd-relative path, or, if that would | |
| 126 | /// Similar to `Dir.path.resolve`, but converts to a cwd-relative path, or, if that would | |
| 128 | 127 | /// start with a relative up-dir (".."), an absolute path based on the cwd. Also, the cwd |
| 129 | 128 | /// returns the empty string ("") instead of ".". |
| 130 | 129 | pub fn resolvePath( |
| ... | ... | @@ -136,7 +135,7 @@ pub fn resolvePath( |
| 136 | 135 | ) Allocator.Error![]u8 { |
| 137 | 136 | if (builtin.target.os.tag == .wasi) { |
| 138 | 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 | 139 | if (mem.eql(u8, res, ".")) { |
| 141 | 140 | gpa.free(res); |
| 142 | 141 | return ""; |
| ... | ... | @@ -146,16 +145,16 @@ pub fn resolvePath( |
| 146 | 145 | |
| 147 | 146 | // Heuristic for a fast path: if no component is absolute and ".." never appears, we just need to resolve `paths`. |
| 148 | 147 | for (paths) |p| { |
| 149 | if (fs.path.isAbsolute(p)) break; // absolute path | |
| 148 | if (Dir.path.isAbsolute(p)) break; // absolute path | |
| 150 | 149 | if (mem.indexOf(u8, p, "..") != null) break; // may contain up-dir |
| 151 | 150 | } else { |
| 152 | 151 | // no absolute path, no "..". |
| 153 | const res = try fs.path.resolve(gpa, paths); | |
| 152 | const res = try Dir.path.resolve(gpa, paths); | |
| 154 | 153 | if (mem.eql(u8, res, ".")) { |
| 155 | 154 | gpa.free(res); |
| 156 | 155 | return ""; |
| 157 | 156 | } |
| 158 | std.debug.assert(!fs.path.isAbsolute(res)); | |
| 157 | std.debug.assert(!Dir.path.isAbsolute(res)); | |
| 159 | 158 | std.debug.assert(!isUpDir(res)); |
| 160 | 159 | return res; |
| 161 | 160 | } |
| ... | ... | @@ -164,19 +163,19 @@ pub fn resolvePath( |
| 164 | 163 | // Optimization: `paths` often has just one element. |
| 165 | 164 | const path_resolved = switch (paths.len) { |
| 166 | 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 | 167 | else => r: { |
| 169 | 168 | const all_paths = try gpa.alloc([]const u8, paths.len + 1); |
| 170 | 169 | defer gpa.free(all_paths); |
| 171 | 170 | all_paths[0] = cwd_resolved; |
| 172 | 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 | 175 | errdefer gpa.free(path_resolved); |
| 177 | 176 | |
| 178 | std.debug.assert(fs.path.isAbsolute(path_resolved)); | |
| 179 | std.debug.assert(fs.path.isAbsolute(cwd_resolved)); | |
| 177 | std.debug.assert(Dir.path.isAbsolute(path_resolved)); | |
| 178 | std.debug.assert(Dir.path.isAbsolute(cwd_resolved)); | |
| 180 | 179 | |
| 181 | 180 | if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd |
| 182 | 181 | if (path_resolved.len == cwd_resolved.len) { |
| ... | ... | @@ -184,7 +183,7 @@ pub fn resolvePath( |
| 184 | 183 | gpa.free(path_resolved); |
| 185 | 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) | |
| 188 | 187 | |
| 189 | 188 | // in cwd; extract sub path |
| 190 | 189 | const sub_path = try gpa.dupe(u8, path_resolved[cwd_resolved.len + 1 ..]); |
| ... | ... | @@ -192,9 +191,8 @@ pub fn resolvePath( |
| 192 | 191 | return sub_path; |
| 193 | 192 | } |
| 194 | 193 | |
| 195 | /// TODO move this to std.fs.path | |
| 196 | 194 | pub 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 | } |
| 199 | 197 | |
| 200 | 198 | pub const default_local_zig_cache_basename = ".zig-cache"; |
| ... | ... | @@ -205,12 +203,12 @@ pub const default_local_zig_cache_basename = ".zig-cache"; |
| 205 | 203 | pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 { |
| 206 | 204 | var cur_dir = cwd; |
| 207 | 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 | 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 | 209 | } else |err| switch (err) { |
| 212 | 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 | 212 | continue; |
| 215 | 213 | }, |
| 216 | 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 | 444 | var cache: Cache = .{ |
| 445 | 445 | .gpa = gpa, |
| 446 | 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 | 449 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 450 | 450 | cache.addPrefix(comp.dirs.zig_lib); |
| ... | ... | @@ -477,7 +477,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 477 | 477 | const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); |
| 478 | 478 | |
| 479 | 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 | 481 | .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}), |
| 482 | 482 | }; |
| 483 | 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 | 679 | var cache: Cache = .{ |
| 680 | 680 | .gpa = gpa, |
| 681 | 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 | 684 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 685 | 685 | cache.addPrefix(comp.dirs.zig_lib); |
| ... | ... | @@ -712,7 +712,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 712 | 712 | const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); |
| 713 | 713 | |
| 714 | 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 | 716 | .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}), |
| 717 | 717 | }; |
| 718 | 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 | 258 | var cache: Cache = .{ |
| 259 | 259 | .gpa = gpa, |
| 260 | 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 | 263 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 264 | 264 | cache.addPrefix(comp.dirs.zig_lib); |
| ... | ... | @@ -297,7 +297,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 297 | 297 | |
| 298 | 298 | const digest = man.final(); |
| 299 | 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 | 301 | defer o_dir.close(io); |
| 302 | 302 | |
| 303 | 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 | 385 | var cache: Cache = .{ |
| 386 | 386 | .gpa = gpa, |
| 387 | 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 | 390 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 391 | 391 | cache.addPrefix(comp.dirs.zig_lib); |
| ... | ... | @@ -418,7 +418,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 418 | 418 | const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); |
| 419 | 419 | |
| 420 | 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 | 422 | .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}), |
| 423 | 423 | }; |
| 424 | 424 | defer o_directory.handle.close(io); |
src/link.zig+7-8| ... | ... | @@ -2170,28 +2170,27 @@ fn resolvePathInputLib( |
| 2170 | 2170 | }) { |
| 2171 | 2171 | var file = test_path.root_dir.handle.openFile(io, test_path.sub_path, .{}) catch |err| switch (err) { |
| 2172 | 2172 | error.FileNotFound => return .no_match, |
| 2173 | else => |e| fatal("unable to search for {s} library '{f}': {s}", .{ | |
| 2174 | @tagName(link_mode), std.fmt.alt(test_path, .formatEscapeChar), @errorName(e), | |
| 2173 | else => |e| fatal("unable to search for {t} library '{f}': {t}", .{ | |
| 2174 | link_mode, std.fmt.alt(test_path, .formatEscapeChar), e, | |
| 2175 | 2175 | }), |
| 2176 | 2176 | }; |
| 2177 | 2177 | errdefer file.close(io); |
| 2178 | 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}", .{ | |
| 2180 | std.fmt.alt(test_path, .formatEscapeChar), @errorName(err), | |
| 2181 | }); | |
| 2179 | const n = file.readPositionalAll(io, ld_script_bytes.items, 0) catch |err| | |
| 2180 | fatal("failed to read '{f}': {t}", .{ std.fmt.alt(test_path, .formatEscapeChar), err }); | |
| 2182 | 2181 | const buf = ld_script_bytes.items[0..n]; |
| 2183 | 2182 | if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) { |
| 2184 | 2183 | // Appears to be an ELF or archive file. |
| 2185 | 2184 | return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query); |
| 2186 | 2185 | } |
| 2187 | 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 | 2188 | const size = std.math.cast(u32, stat.size) orelse |
| 2190 | 2189 | fatal("{f}: linker script too big", .{test_path}); |
| 2191 | 2190 | try ld_script_bytes.resize(gpa, size); |
| 2192 | 2191 | const buf2 = ld_script_bytes.items[n..]; |
| 2193 | const n2 = file.preadAll(buf2, n) catch |err| | |
| 2194 | fatal("failed to read {f}: {s}", .{ test_path, @errorName(err) }); | |
| 2192 | const n2 = file.readPositionalAll(io, buf2, n) catch |err| | |
| 2193 | fatal("failed to read {f}: {t}", .{ test_path, err }); | |
| 2195 | 2194 | if (n2 != buf2.len) fatal("failed to read {f}: unexpected end of file", .{test_path}); |
| 2196 | 2195 | |
| 2197 | 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 | 636 | const coff = try arena.create(Coff); |
| 637 | 637 | const file = try path.root_dir.handle.createFile(io, path.sub_path, .{ |
| 638 | 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 | 641 | errdefer file.close(io); |
| 642 | 642 | coff.* = .{ |
| ... | ... | @@ -653,7 +653,7 @@ fn create( |
| 653 | 653 | .allow_shlib_undefined = false, |
| 654 | 654 | .stack_size = 0, |
| 655 | 655 | }, |
| 656 | .mf = try .init(file, comp.gpa), | |
| 656 | .mf = try .init(file, comp.gpa, io), | |
| 657 | 657 | .nodes = .empty, |
| 658 | 658 | .import_table = .{ |
| 659 | 659 | .ni = .none, |
src/link/Dwarf.zig-1| ... | ... | @@ -52,7 +52,6 @@ pub const UpdateError = error{ |
| 52 | 52 | codegen.GenerateSymbolError || |
| 53 | 53 | Io.File.OpenError || |
| 54 | 54 | Io.File.LengthError || |
| 55 | Io.File.CopyRangeError || | |
| 56 | 55 | Io.File.ReadPositionalError || |
| 57 | 56 | Io.File.WritePositionalError; |
| 58 | 57 |
src/link/Elf.zig+1-1| ... | ... | @@ -320,7 +320,7 @@ pub fn createEmpty( |
| 320 | 320 | self.base.file = try emit.root_dir.handle.createFile(io, sub_path, .{ |
| 321 | 321 | .truncate = true, |
| 322 | 322 | .read = true, |
| 323 | .mode = link.File.determineMode(output_mode, link_mode), | |
| 323 | .permissions = link.File.determinePermissions(output_mode, link_mode), | |
| 324 | 324 | }); |
| 325 | 325 | |
| 326 | 326 | const gpa = comp.gpa; |
src/link/Elf2.zig+2-2| ... | ... | @@ -976,7 +976,7 @@ fn create( |
| 976 | 976 | const elf = try arena.create(Elf); |
| 977 | 977 | const file = try path.root_dir.handle.createFile(io, path.sub_path, .{ |
| 978 | 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 | 981 | errdefer file.close(io); |
| 982 | 982 | elf.* = .{ |
| ... | ... | @@ -994,7 +994,7 @@ fn create( |
| 994 | 994 | .stack_size = 0, |
| 995 | 995 | }, |
| 996 | 996 | .options = options, |
| 997 | .mf = try .init(file, comp.gpa), | |
| 997 | .mf = try .init(file, comp.gpa, io), | |
| 998 | 998 | .ni = .{ |
| 999 | 999 | .tls = .none, |
| 1000 | 1000 | }, |
src/link/MachO.zig+25-10| ... | ... | @@ -224,7 +224,7 @@ pub fn createEmpty( |
| 224 | 224 | self.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{ |
| 225 | 225 | .truncate = true, |
| 226 | 226 | .read = true, |
| 227 | .mode = link.File.determineMode(output_mode, link_mode), | |
| 227 | .permissions = link.File.determinePermissions(output_mode, link_mode), | |
| 228 | 228 | }); |
| 229 | 229 | |
| 230 | 230 | // Append null file |
| ... | ... | @@ -3157,7 +3157,9 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) !?u64 { |
| 3157 | 3157 | } |
| 3158 | 3158 | } |
| 3159 | 3159 | |
| 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 | 3163 | return null; |
| 3162 | 3164 | } |
| 3163 | 3165 | |
| ... | ... | @@ -3292,7 +3294,7 @@ pub fn reopenDebugInfo(self: *MachO) !void { |
| 3292 | 3294 | ); |
| 3293 | 3295 | defer gpa.free(d_sym_path); |
| 3294 | 3296 | |
| 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 | 3298 | defer d_sym_bundle.close(io); |
| 3297 | 3299 | |
| 3298 | 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 | 3305 | |
| 3304 | 3306 | // TODO: move to ZigObject |
| 3305 | 3307 | fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { |
| 3308 | const comp = self.base.comp; | |
| 3309 | const gpa = comp.gpa; | |
| 3310 | const io = comp.io; | |
| 3311 | ||
| 3306 | 3312 | if (!self.base.isRelocatable()) { |
| 3307 | 3313 | const base_vmaddr = blk: { |
| 3308 | 3314 | const pagezero_size = self.pagezero_size orelse default_pagezero_size; |
| ... | ... | @@ -3357,7 +3363,11 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { |
| 3357 | 3363 | if (options.zo.dwarf) |*dwarf| { |
| 3358 | 3364 | // Create dSYM bundle. |
| 3359 | 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 | 3371 | try self.reopenDebugInfo(); |
| 3362 | 3372 | try self.d_sym.?.initMetadata(self); |
| 3363 | 3373 | try dwarf.initMetadata(); |
| ... | ... | @@ -3477,6 +3487,9 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo |
| 3477 | 3487 | const seg_id = self.sections.items(.segment_id)[sect_index]; |
| 3478 | 3488 | const seg = &self.segments.items[seg_id]; |
| 3479 | 3489 | |
| 3490 | const comp = self.base.comp; | |
| 3491 | const io = comp.io; | |
| 3492 | ||
| 3480 | 3493 | if (!sect.isZerofill()) { |
| 3481 | 3494 | const allocated_size = self.allocatedSize(sect.offset); |
| 3482 | 3495 | if (needed_size > allocated_size) { |
| ... | ... | @@ -3498,7 +3511,7 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo |
| 3498 | 3511 | |
| 3499 | 3512 | sect.offset = @intCast(new_offset); |
| 3500 | 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 | 3516 | seg.filesize = needed_size; |
| 3504 | 3517 | } |
| ... | ... | @@ -3520,6 +3533,8 @@ fn growSectionNonRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !vo |
| 3520 | 3533 | } |
| 3521 | 3534 | |
| 3522 | 3535 | fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void { |
| 3536 | const comp = self.base.comp; | |
| 3537 | const io = comp.io; | |
| 3523 | 3538 | const sect = &self.sections.items(.header)[sect_index]; |
| 3524 | 3539 | |
| 3525 | 3540 | if (!sect.isZerofill()) { |
| ... | ... | @@ -3547,7 +3562,7 @@ fn growSectionRelocatable(self: *MachO, sect_index: u8, needed_size: u64) !void |
| 3547 | 3562 | sect.offset = @intCast(new_offset); |
| 3548 | 3563 | sect.addr = new_addr; |
| 3549 | 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 | 3568 | sect.size = needed_size; |
| ... | ... | @@ -5346,12 +5361,12 @@ pub fn pwriteAll(macho_file: *MachO, bytes: []const u8, offset: u64) error{LinkF |
| 5346 | 5361 | }; |
| 5347 | 5362 | } |
| 5348 | 5363 | |
| 5349 | pub fn setEndPos(macho_file: *MachO, length: u64) error{LinkFailure}!void { | |
| 5364 | pub fn setLength(macho_file: *MachO, length: u64) error{LinkFailure}!void { | |
| 5350 | 5365 | const comp = macho_file.base.comp; |
| 5366 | const io = comp.io; | |
| 5351 | 5367 | const diags = &comp.link_diags; |
| 5352 | macho_file.base.file.?.setEndPos(length) catch |err| { | |
| 5353 | return diags.fail("failed to set file end pos: {s}", .{@errorName(err)}); | |
| 5354 | }; | |
| 5368 | macho_file.base.file.?.setLength(io, length) catch |err| | |
| 5369 | return diags.fail("failed to set file end pos: {t}", .{err}); | |
| 5355 | 5370 | } |
| 5356 | 5371 | |
| 5357 | 5372 | pub 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 | 10 | const linux = std.os.linux; |
| 11 | 11 | const windows = std.os.windows; |
| 12 | 12 | |
| 13 | io: Io, | |
| 13 | 14 | file: std.Io.File, |
| 14 | 15 | flags: packed struct { |
| 15 | 16 | block_size: std.mem.Alignment, |
| ... | ... | @@ -36,8 +37,9 @@ pub const Error = std.posix.MMapError || std.posix.MRemapError || Io.File.Length |
| 36 | 37 | NoSpaceLeft, |
| 37 | 38 | }; |
| 38 | 39 | |
| 39 | pub fn init(file: std.Io.File, gpa: std.mem.Allocator) !MappedFile { | |
| 40 | pub fn init(file: std.Io.File, gpa: std.mem.Allocator, io: Io) !MappedFile { | |
| 40 | 41 | var mf: MappedFile = .{ |
| 42 | .io = io, | |
| 41 | 43 | .file = file, |
| 42 | 44 | .flags = undefined, |
| 43 | 45 | .section = if (is_windows) windows.INVALID_HANDLE_VALUE else {}, |
| ... | ... | @@ -624,13 +626,14 @@ pub fn addNodeAfter( |
| 624 | 626 | } |
| 625 | 627 | |
| 626 | 628 | fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested_size: u64) !void { |
| 629 | const io = mf.io; | |
| 627 | 630 | const node = ni.get(mf); |
| 628 | 631 | const old_offset, const old_size = node.location().resolve(mf); |
| 629 | 632 | const new_size = node.flags.alignment.forward(@intCast(requested_size)); |
| 630 | 633 | // Resize the entire file |
| 631 | 634 | if (ni == Node.Index.root) { |
| 632 | 635 | try mf.ensureCapacityForSetLocation(gpa); |
| 633 | try mf.file.setEndPos(new_size); | |
| 636 | try mf.file.setLength(io, new_size); | |
| 634 | 637 | try mf.ensureTotalCapacity(@intCast(new_size)); |
| 635 | 638 | ni.setLocationAssumeCapacity(mf, old_offset, new_size); |
| 636 | 639 | return; |
src/link/Wasm.zig+3-3| ... | ... | @@ -3002,11 +3002,11 @@ pub fn createEmpty( |
| 3002 | 3002 | wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{ |
| 3003 | 3003 | .truncate = true, |
| 3004 | 3004 | .read = true, |
| 3005 | .mode = if (Io.File.Permissions.has_executable_bit) | |
| 3005 | .permissions = if (Io.File.Permissions.has_executable_bit) | |
| 3006 | 3006 | if (target.os.tag == .wasi and output_mode == .Exe) |
| 3007 | Io.File.default_mode | 0b001_000_000 | |
| 3007 | .executable_file | |
| 3008 | 3008 | else |
| 3009 | Io.File.default_mode | |
| 3009 | .default_file | |
| 3010 | 3010 | else |
| 3011 | 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 | 335 | } else if (mem.eql(u8, cmd, "targets")) { |
| 336 | 336 | dev.check(.targets_command); |
| 337 | 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 | 339 | try @import("print_targets.zig").cmdTargets(arena, io, cmd_args, &stdout_writer.interface, &host); |
| 340 | 340 | return stdout_writer.interface.flush(); |
| 341 | 341 | } else if (mem.eql(u8, cmd, "version")) { |
| 342 | 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 | 344 | return; |
| 345 | 345 | } else if (mem.eql(u8, cmd, "env")) { |
| 346 | 346 | dev.check(.env_command); |
| 347 | 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 | 349 | try @import("print_env.zig").cmdEnv( |
| 350 | 350 | arena, |
| 351 | io, | |
| 351 | 352 | &stdout_writer.interface, |
| 352 | 353 | args, |
| 353 | 354 | if (native_os == .wasi) wasi_preopens, |
| ... | ... | @@ -361,10 +362,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 361 | 362 | }); |
| 362 | 363 | } else if (mem.eql(u8, cmd, "zen")) { |
| 363 | 364 | dev.check(.zen_command); |
| 364 | return Io.File.stdout().writeAll(info_zen); | |
| 365 | return Io.File.stdout().writeStreamingAll(io, info_zen); | |
| 365 | 366 | } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) { |
| 366 | 367 | dev.check(.help_command); |
| 367 | return Io.File.stdout().writeAll(usage); | |
| 368 | return Io.File.stdout().writeStreamingAll(io, usage); | |
| 368 | 369 | } else if (mem.eql(u8, cmd, "ast-check")) { |
| 369 | 370 | return cmdAstCheck(arena, io, cmd_args); |
| 370 | 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 | 375 | } else if (build_options.enable_debug_extensions and mem.eql(u8, cmd, "dump-zir")) { |
| 375 | 376 | return cmdDumpZir(arena, io, cmd_args); |
| 376 | 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 | 379 | } else { |
| 379 | 380 | std.log.info("{s}", .{usage}); |
| 380 | 381 | fatal("unknown command: {s}", .{args[1]}); |
| ... | ... | @@ -701,7 +702,7 @@ const Emit = union(enum) { |
| 701 | 702 | yes: []const u8, |
| 702 | 703 | |
| 703 | 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 | 706 | return switch (emit) { |
| 706 | 707 | .no => .no, |
| 707 | 708 | .yes_default_path => if (output_to_cache != null) .yes_cache else .{ .yes_path = default_basename }, |
| ... | ... | @@ -1036,7 +1037,7 @@ fn buildOutputType( |
| 1036 | 1037 | fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err }); |
| 1037 | 1038 | } else if (mem.startsWith(u8, arg, "-")) { |
| 1038 | 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 | 1041 | return cleanExit(); |
| 1041 | 1042 | } else if (mem.eql(u8, arg, "--")) { |
| 1042 | 1043 | if (arg_mode == .run) { |
| ... | ... | @@ -1858,9 +1859,7 @@ fn buildOutputType( |
| 1858 | 1859 | var must_link = false; |
| 1859 | 1860 | var file_ext: ?Compilation.FileExt = null; |
| 1860 | 1861 | while (it.has_next) { |
| 1861 | it.next() catch |err| { | |
| 1862 | fatal("unable to parse command line parameters: {s}", .{@errorName(err)}); | |
| 1863 | }; | |
| 1862 | it.next(io) catch |err| fatal("unable to parse command line parameters: {t}", .{err}); | |
| 1864 | 1863 | switch (it.zig_equivalent) { |
| 1865 | 1864 | .target => target_arch_os_abi = it.only_arg, // example: -target riscv64-linux-unknown |
| 1866 | 1865 | .o => { |
| ... | ... | @@ -2836,9 +2835,9 @@ fn buildOutputType( |
| 2836 | 2835 | } else if (mem.eql(u8, arg, "-V")) { |
| 2837 | 2836 | warn("ignoring request for supported emulations: unimplemented", .{}); |
| 2838 | 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 | 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 | 2841 | process.exit(0); |
| 2843 | 2842 | } else { |
| 2844 | 2843 | fatal("unsupported linker arg: {s}", .{arg}); |
| ... | ... | @@ -3077,14 +3076,13 @@ fn buildOutputType( |
| 3077 | 3076 | |
| 3078 | 3077 | const self_exe_path = switch (native_os) { |
| 3079 | 3078 | .wasi => {}, |
| 3080 | else => fs.selfExePathAlloc(arena) catch |err| { | |
| 3081 | fatal("unable to find zig self exe path: {s}", .{@errorName(err)}); | |
| 3082 | }, | |
| 3079 | else => process.executablePathAlloc(io, arena) catch |err| fatal("unable to find zig self exe path: {t}", .{err}), | |
| 3083 | 3080 | }; |
| 3084 | 3081 | |
| 3085 | 3082 | // This `init` calls `fatal` on error. |
| 3086 | 3083 | var dirs: Compilation.Directories = .init( |
| 3087 | 3084 | arena, |
| 3085 | io, | |
| 3088 | 3086 | override_lib_dir, |
| 3089 | 3087 | override_global_cache_dir, |
| 3090 | 3088 | s: { |
| ... | ... | @@ -3097,11 +3095,9 @@ fn buildOutputType( |
| 3097 | 3095 | if (native_os == .wasi) wasi_preopens, |
| 3098 | 3096 | self_exe_path, |
| 3099 | 3097 | ); |
| 3100 | defer dirs.deinit(); | |
| 3098 | defer dirs.deinit(io); | |
| 3101 | 3099 | |
| 3102 | if (linker_optimization) |o| { | |
| 3103 | warn("ignoring deprecated linker optimization setting '{s}'", .{o}); | |
| 3104 | } | |
| 3100 | if (linker_optimization) |o| warn("ignoring deprecated linker optimization setting '{s}'", .{o}); | |
| 3105 | 3101 | |
| 3106 | 3102 | create_module.dirs = dirs; |
| 3107 | 3103 | create_module.opts.emit_llvm_ir = emit_llvm_ir != .no; |
| ... | ... | @@ -3324,18 +3320,18 @@ fn buildOutputType( |
| 3324 | 3320 | }; |
| 3325 | 3321 | |
| 3326 | 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); | |
| 3328 | 3324 | |
| 3329 | 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); | |
| 3331 | 3327 | |
| 3332 | 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); | |
| 3334 | 3330 | |
| 3335 | 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); | |
| 3337 | 3333 | |
| 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); | |
| 3339 | 3335 | |
| 3340 | 3336 | const is_exe_or_dyn_lib = switch (create_module.resolved_options.output_mode) { |
| 3341 | 3337 | .Obj => false, |
| ... | ... | @@ -3356,7 +3352,7 @@ fn buildOutputType( |
| 3356 | 3352 | const default_implib_basename = try std.fmt.allocPrint(arena, "{s}.lib", .{root_name}); |
| 3357 | 3353 | const emit_implib_resolved: Compilation.CreateOptions.Emit = switch (emit_implib) { |
| 3358 | 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 | 3356 | .yes_default_path => emit: { |
| 3361 | 3357 | if (output_to_cache != null) break :emit .yes_cache; |
| 3362 | 3358 | const p = try fs.path.join(arena, &.{ |
| ... | ... | @@ -3399,7 +3395,7 @@ fn buildOutputType( |
| 3399 | 3395 | // for the hashing algorithm here and in the cache are the same. |
| 3400 | 3396 | // We are providing our own cache key, because this file has nothing |
| 3401 | 3397 | // to do with the cache manifest. |
| 3402 | var file_writer = f.writer(&.{}); | |
| 3398 | var file_writer = f.writer(io, &.{}); | |
| 3403 | 3399 | var buffer: [1000]u8 = undefined; |
| 3404 | 3400 | var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer); |
| 3405 | 3401 | var stdin_reader = Io.File.stdin().readerStreaming(io, &.{}); |
| ... | ... | @@ -3633,13 +3629,13 @@ fn buildOutputType( |
| 3633 | 3629 | if (show_builtin) { |
| 3634 | 3630 | const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config); |
| 3635 | 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 | 3634 | switch (listen) { |
| 3639 | 3635 | .none => {}, |
| 3640 | 3636 | .stdio => { |
| 3641 | 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 | 3639 | try serve( |
| 3644 | 3640 | comp, |
| 3645 | 3641 | &stdin_reader.interface, |
| ... | ... | @@ -3930,11 +3926,8 @@ fn createModule( |
| 3930 | 3926 | } |
| 3931 | 3927 | |
| 3932 | 3928 | if (target.isMinGW()) { |
| 3933 | const exists = mingw.libExists(arena, target, create_module.dirs.zig_lib, lib_name) catch |err| { | |
| 3934 | fatal("failed to check zig installation for DLL import libs: {s}", .{ | |
| 3935 | @errorName(err), | |
| 3936 | }); | |
| 3937 | }; | |
| 3929 | const exists = mingw.libExists(arena, io, target, create_module.dirs.zig_lib, lib_name) catch |err| | |
| 3930 | fatal("failed to check zig installation for DLL import libs: {t}", .{err}); | |
| 3938 | 3931 | if (exists) { |
| 3939 | 3932 | try create_module.windows_libs.put(arena, lib_name, {}); |
| 3940 | 3933 | continue; |
| ... | ... | @@ -4009,11 +4002,8 @@ fn createModule( |
| 4009 | 4002 | } |
| 4010 | 4003 | |
| 4011 | 4004 | if (create_module.libc_paths_file) |paths_file| { |
| 4012 | create_module.libc_installation = LibCInstallation.parse(arena, paths_file, target) catch |err| { | |
| 4013 | fatal("unable to parse libc paths file at path {s}: {s}", .{ | |
| 4014 | paths_file, @errorName(err), | |
| 4015 | }); | |
| 4016 | }; | |
| 4005 | create_module.libc_installation = LibCInstallation.parse(arena, io, paths_file, target) catch |err| | |
| 4006 | fatal("unable to parse libc paths file at path {s}: {t}", .{ paths_file, err }); | |
| 4017 | 4007 | } |
| 4018 | 4008 | |
| 4019 | 4009 | if (target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and |
| ... | ... | @@ -4024,7 +4014,7 @@ fn createModule( |
| 4024 | 4014 | .verbose = true, |
| 4025 | 4015 | .target = target, |
| 4026 | 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 | 4020 | try create_module.lib_directories.ensureUnusedCapacity(arena, 2); |
| ... | ... | @@ -4163,7 +4153,7 @@ fn serve( |
| 4163 | 4153 | |
| 4164 | 4154 | var child_pid: ?std.process.Child.Id = null; |
| 4165 | 4155 | |
| 4166 | const main_progress_node = std.Progress.start(.{}); | |
| 4156 | const main_progress_node = std.Progress.start(io, .{}); | |
| 4167 | 4157 | const file_system_inputs = comp.file_system_inputs.?; |
| 4168 | 4158 | |
| 4169 | 4159 | const IncrementalDebugServer = if (build_options.enable_debug_extensions and !builtin.single_threaded) |
| ... | ... | @@ -4694,7 +4684,7 @@ fn cmdTranslateC( |
| 4694 | 4684 | }); |
| 4695 | 4685 | }; |
| 4696 | 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 | 4688 | var file_reader = zig_file.reader(io, &.{}); |
| 4699 | 4689 | _ = try stdout_writer.interface.sendFileAll(&file_reader, .unlimited); |
| 4700 | 4690 | try stdout_writer.interface.flush(); |
| ... | ... | @@ -4744,7 +4734,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 4744 | 4734 | if (mem.eql(u8, arg, "-m") or mem.eql(u8, arg, "--minimal")) { |
| 4745 | 4735 | template = .minimal; |
| 4746 | 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 | 4738 | return cleanExit(); |
| 4749 | 4739 | } else { |
| 4750 | 4740 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| ... | ... | @@ -4764,7 +4754,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 4764 | 4754 | switch (template) { |
| 4765 | 4755 | .example => { |
| 4766 | 4756 | var templates = findTemplates(gpa, arena, io); |
| 4767 | defer templates.deinit(); | |
| 4757 | defer templates.deinit(io); | |
| 4768 | 4758 | |
| 4769 | 4759 | const s = fs.path.sep_str; |
| 4770 | 4760 | const template_paths = [_][]const u8{ |
| ... | ... | @@ -4898,7 +4888,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 4898 | 4888 | const argv_index_exe = child_argv.items.len; |
| 4899 | 4889 | _ = try child_argv.addOne(); |
| 4900 | 4890 | |
| 4901 | const self_exe_path = try fs.selfExePathAlloc(arena); | |
| 4891 | const self_exe_path = try process.executablePathAlloc(io, arena); | |
| 4902 | 4892 | try child_argv.append(self_exe_path); |
| 4903 | 4893 | |
| 4904 | 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 | 5069 | |
| 5080 | 5070 | const work_around_btrfs_bug = native_os == .linux and |
| 5081 | 5071 | EnvVar.ZIG_BTRFS_WORKAROUND.isSet(); |
| 5082 | const root_prog_node = std.Progress.start(.{ | |
| 5072 | const root_prog_node = std.Progress.start(io, .{ | |
| 5083 | 5073 | .disable_printing = (color == .off), |
| 5084 | 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 | 5104 | const paths_file = debug_libc_paths_file orelse break :lci null; |
| 5115 | 5105 | if (!build_options.enable_debug_extensions) unreachable; |
| 5116 | 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 | 5108 | break :lci lci; |
| 5119 | 5109 | }; |
| 5120 | 5110 | |
| ... | ... | @@ -5129,6 +5119,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5129 | 5119 | // This `init` calls `fatal` on error. |
| 5130 | 5120 | var dirs: Compilation.Directories = .init( |
| 5131 | 5121 | arena, |
| 5122 | io, | |
| 5132 | 5123 | override_lib_dir, |
| 5133 | 5124 | override_global_cache_dir, |
| 5134 | 5125 | .{ .override = path: { |
| ... | ... | @@ -5138,7 +5129,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5138 | 5129 | {}, |
| 5139 | 5130 | self_exe_path, |
| 5140 | 5131 | ); |
| 5141 | defer dirs.deinit(); | |
| 5132 | defer dirs.deinit(io); | |
| 5142 | 5133 | |
| 5143 | 5134 | child_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path; |
| 5144 | 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 | 5412 | child.stderr_behavior = .Inherit; |
| 5422 | 5413 | |
| 5423 | 5414 | const term = t: { |
| 5424 | std.debug.lockStdErr(); | |
| 5425 | defer std.debug.unlockStdErr(); | |
| 5426 | break :t child.spawnAndWait(io) catch |err| { | |
| 5415 | _ = std.debug.lockStderrWriter(&.{}); | |
| 5416 | defer std.debug.unlockStderrWriter(); | |
| 5417 | break :t child.spawnAndWait(io) catch |err| | |
| 5427 | 5418 | fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err }); |
| 5428 | }; | |
| 5429 | 5419 | }; |
| 5430 | 5420 | |
| 5431 | 5421 | switch (term) { |
| ... | ... | @@ -5517,7 +5507,7 @@ fn jitCmd( |
| 5517 | 5507 | dev.check(.jit_command); |
| 5518 | 5508 | |
| 5519 | 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 | 5511 | .disable_printing = (color == .off), |
| 5522 | 5512 | }); |
| 5523 | 5513 | |
| ... | ... | @@ -5529,9 +5519,8 @@ fn jitCmd( |
| 5529 | 5519 | .is_explicit_dynamic_linker = false, |
| 5530 | 5520 | }; |
| 5531 | 5521 | |
| 5532 | const self_exe_path = fs.selfExePathAlloc(arena) catch |err| { | |
| 5533 | fatal("unable to find self exe path: {s}", .{@errorName(err)}); | |
| 5534 | }; | |
| 5522 | const self_exe_path = process.executablePathAlloc(io, arena) catch |err| | |
| 5523 | fatal("unable to find self exe path: {t}", .{err}); | |
| 5535 | 5524 | |
| 5536 | 5525 | const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet()) |
| 5537 | 5526 | .Debug |
| ... | ... | @@ -5544,13 +5533,14 @@ fn jitCmd( |
| 5544 | 5533 | // This `init` calls `fatal` on error. |
| 5545 | 5534 | var dirs: Compilation.Directories = .init( |
| 5546 | 5535 | arena, |
| 5536 | io, | |
| 5547 | 5537 | override_lib_dir, |
| 5548 | 5538 | override_global_cache_dir, |
| 5549 | 5539 | .global, |
| 5550 | 5540 | if (native_os == .wasi) wasi_preopens, |
| 5551 | 5541 | self_exe_path, |
| 5552 | 5542 | ); |
| 5553 | defer dirs.deinit(); | |
| 5543 | defer dirs.deinit(io); | |
| 5554 | 5544 | |
| 5555 | 5545 | const thread_limit = @min( |
| 5556 | 5546 | @max(std.Thread.getCpuCount() catch 1, 1), |
| ... | ... | @@ -5629,7 +5619,7 @@ fn jitCmd( |
| 5629 | 5619 | defer comp.destroy(); |
| 5630 | 5620 | |
| 5631 | 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 | 5623 | var server: std.zig.Server = .{ |
| 5634 | 5624 | .out = &stdout_writer.interface, |
| 5635 | 5625 | .in = undefined, // won't be receiving messages |
| ... | ... | @@ -5696,7 +5686,7 @@ fn jitCmd( |
| 5696 | 5686 | ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32))); |
| 5697 | 5687 | } |
| 5698 | 5688 | |
| 5699 | const term = try child.wait(); | |
| 5689 | const term = try child.wait(io); | |
| 5700 | 5690 | switch (term) { |
| 5701 | 5691 | .Exited => |code| { |
| 5702 | 5692 | if (code == 0) { |
| ... | ... | @@ -6160,7 +6150,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6160 | 6150 | const arg = args[i]; |
| 6161 | 6151 | if (mem.startsWith(u8, arg, "-")) { |
| 6162 | 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 | 6154 | return cleanExit(); |
| 6165 | 6155 | } else if (mem.eql(u8, arg, "-t")) { |
| 6166 | 6156 | want_output_text = true; |
| ... | ... | @@ -6211,7 +6201,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6211 | 6201 | |
| 6212 | 6202 | const tree = try Ast.parse(arena, source, mode); |
| 6213 | 6203 | |
| 6214 | var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer); | |
| 6204 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); | |
| 6215 | 6205 | const stdout_bw = &stdout_writer.interface; |
| 6216 | 6206 | switch (mode) { |
| 6217 | 6207 | .zig => { |
| ... | ... | @@ -6334,7 +6324,7 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void { |
| 6334 | 6324 | const arg = args[i]; |
| 6335 | 6325 | if (mem.startsWith(u8, arg, "-")) { |
| 6336 | 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 | 6328 | return cleanExit(); |
| 6339 | 6329 | } else if (mem.eql(u8, arg, "--llvm")) { |
| 6340 | 6330 | use_llvm = true; |
| ... | ... | @@ -6355,10 +6345,10 @@ fn cmdDetectCpu(io: Io, args: []const []const u8) !void { |
| 6355 | 6345 | const name = llvm.GetHostCPUName() orelse fatal("LLVM could not figure out the host cpu name", .{}); |
| 6356 | 6346 | const features = llvm.GetHostCPUFeatures() orelse fatal("LLVM could not figure out the host cpu feature set", .{}); |
| 6357 | 6347 | const cpu = try detectNativeCpuWithLLVM(builtin.cpu.arch, name, features); |
| 6358 | try printCpu(cpu); | |
| 6348 | try printCpu(io, cpu); | |
| 6359 | 6349 | } else { |
| 6360 | 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 | } |
| 6364 | 6354 | |
| ... | ... | @@ -6425,8 +6415,8 @@ fn detectNativeCpuWithLLVM( |
| 6425 | 6415 | return result; |
| 6426 | 6416 | } |
| 6427 | 6417 | |
| 6428 | fn printCpu(cpu: std.Target.Cpu) !void { | |
| 6429 | var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer); | |
| 6418 | fn printCpu(io: Io, cpu: std.Target.Cpu) !void { | |
| 6419 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); | |
| 6430 | 6420 | const stdout_bw = &stdout_writer.interface; |
| 6431 | 6421 | |
| 6432 | 6422 | if (cpu.model.llvm_name) |llvm_name| { |
| ... | ... | @@ -6448,6 +6438,7 @@ fn printCpu(cpu: std.Target.Cpu) !void { |
| 6448 | 6438 | fn cmdDumpLlvmInts( |
| 6449 | 6439 | gpa: Allocator, |
| 6450 | 6440 | arena: Allocator, |
| 6441 | io: Io, | |
| 6451 | 6442 | args: []const []const u8, |
| 6452 | 6443 | ) !void { |
| 6453 | 6444 | dev.check(.llvm_ints_command); |
| ... | ... | @@ -6475,7 +6466,7 @@ fn cmdDumpLlvmInts( |
| 6475 | 6466 | const dl = tm.createTargetDataLayout(); |
| 6476 | 6467 | const context = llvm.Context.create(); |
| 6477 | 6468 | |
| 6478 | var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer); | |
| 6469 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); | |
| 6479 | 6470 | const stdout_bw = &stdout_writer.interface; |
| 6480 | 6471 | for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| { |
| 6481 | 6472 | const int_type = context.intType(bits); |
| ... | ... | @@ -6501,7 +6492,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6501 | 6492 | defer f.close(io); |
| 6502 | 6493 | |
| 6503 | 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 | 6496 | const stdout_bw = &stdout_writer.interface; |
| 6506 | 6497 | { |
| 6507 | 6498 | const instruction_bytes = zir.instructions.len * |
| ... | ... | @@ -6585,7 +6576,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6585 | 6576 | var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty; |
| 6586 | 6577 | try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map); |
| 6587 | 6578 | |
| 6588 | var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer); | |
| 6579 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); | |
| 6589 | 6580 | const stdout_bw = &stdout_writer.interface; |
| 6590 | 6581 | { |
| 6591 | 6582 | try stdout_bw.print("Instruction mappings:\n", .{}); |
| ... | ... | @@ -6917,7 +6908,7 @@ fn cmdFetch( |
| 6917 | 6908 | const arg = args[i]; |
| 6918 | 6909 | if (mem.startsWith(u8, arg, "-")) { |
| 6919 | 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 | 6912 | return cleanExit(); |
| 6922 | 6913 | } else if (mem.eql(u8, arg, "--global-cache-dir")) { |
| 6923 | 6914 | if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); |
| ... | ... | @@ -6951,7 +6942,7 @@ fn cmdFetch( |
| 6951 | 6942 | |
| 6952 | 6943 | try http_client.initDefaultProxies(arena); |
| 6953 | 6944 | |
| 6954 | var root_prog_node = std.Progress.start(.{ | |
| 6945 | var root_prog_node = std.Progress.start(io, .{ | |
| 6955 | 6946 | .root_name = "Fetch", |
| 6956 | 6947 | }); |
| 6957 | 6948 | defer root_prog_node.end(); |
| ... | ... | @@ -6959,7 +6950,7 @@ fn cmdFetch( |
| 6959 | 6950 | var global_cache_directory: Directory = l: { |
| 6960 | 6951 | const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena); |
| 6961 | 6952 | break :l .{ |
| 6962 | .handle = try Io.Dir.cwd().makeOpenPath(p, .{}), | |
| 6953 | .handle = try Io.Dir.cwd().makeOpenPath(io, p, .{}), | |
| 6963 | 6954 | .path = p, |
| 6964 | 6955 | }; |
| 6965 | 6956 | }; |
| ... | ... | @@ -7026,7 +7017,7 @@ fn cmdFetch( |
| 7026 | 7017 | |
| 7027 | 7018 | const name = switch (save) { |
| 7028 | 7019 | .no => { |
| 7029 | var stdout = Io.File.stdout().writerStreaming(&stdout_buffer); | |
| 7020 | var stdout = Io.File.stdout().writerStreaming(io, &stdout_buffer); | |
| 7030 | 7021 | try stdout.interface.print("{s}\n", .{package_hash_slice}); |
| 7031 | 7022 | try stdout.interface.flush(); |
| 7032 | 7023 | return cleanExit(); |
| ... | ... | @@ -7044,7 +7035,7 @@ fn cmdFetch( |
| 7044 | 7035 | var build_root = try findBuildRoot(arena, io, .{ |
| 7045 | 7036 | .cwd_path = cwd_path, |
| 7046 | 7037 | }); |
| 7047 | defer build_root.deinit(); | |
| 7038 | defer build_root.deinit(io); | |
| 7048 | 7039 | |
| 7049 | 7040 | // The name to use in case the manifest file needs to be created now. |
| 7050 | 7041 | const init_root_name = fs.path.basename(build_root.directory.path orelse cwd_path); |
| ... | ... | @@ -7205,7 +7196,7 @@ fn createDependenciesModule( |
| 7205 | 7196 | const rand_int = std.crypto.random.int(u64); |
| 7206 | 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 | 7200 | defer tmp_dir.close(io); |
| 7210 | 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 | 7437 | const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true }); |
| 7447 | 7438 | defer f.close(io); |
| 7448 | 7439 | var buf: [4096]u8 = undefined; |
| 7449 | var fw = f.writer(&buf); | |
| 7440 | var fw = f.writer(io, &buf); | |
| 7450 | 7441 | try fw.interface.print(fmt, args); |
| 7451 | 7442 | try fw.interface.flush(); |
| 7452 | 7443 | } |
| 7453 | 7444 | |
| 7454 | 7445 | fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates { |
| 7455 | 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| { | |
| 7459 | fatal("unable to find self exe path: {s}", .{@errorName(err)}); | |
| 7449 | const self_exe_path = process.executablePathAlloc(io, arena) catch |err| { | |
| 7450 | fatal("unable to find self exe path: {t}", .{err}); | |
| 7460 | 7451 | }; |
| 7461 | 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 | }; |
| 7464 | 7455 | |
| 7465 | 7456 | const s = fs.path.sep_str; |
| 7466 | 7457 | const template_sub_path = "init"; |
| 7467 | 7458 | const template_dir = zig_lib_directory.handle.openDir(io, template_sub_path, .{}) catch |err| { |
| 7468 | 7459 | const path = zig_lib_directory.path orelse "."; |
| 7469 | fatal("unable to open zig project template directory '{s}{s}{s}': {s}", .{ | |
| 7470 | path, s, template_sub_path, @errorName(err), | |
| 7460 | fatal("unable to open zig project template directory '{s}{s}{s}': {t}", .{ | |
| 7461 | path, s, template_sub_path, err, | |
| 7471 | 7462 | }); |
| 7472 | 7463 | }; |
| 7473 | 7464 |
src/print_env.zig+11-6| ... | ... | @@ -1,13 +1,17 @@ |
| 1 | const std = @import("std"); | |
| 2 | 1 | const builtin = @import("builtin"); |
| 3 | const build_options = @import("build_options"); | |
| 4 | const Compilation = @import("Compilation.zig"); | |
| 2 | ||
| 3 | const std = @import("std"); | |
| 4 | const Io = std.Io; | |
| 5 | 5 | const Allocator = std.mem.Allocator; |
| 6 | 6 | const EnvVar = std.zig.EnvVar; |
| 7 | 7 | const fatal = std.process.fatal; |
| 8 | 8 | |
| 9 | const build_options = @import("build_options"); | |
| 10 | const Compilation = @import("Compilation.zig"); | |
| 11 | ||
| 9 | 12 | pub fn cmdEnv( |
| 10 | 13 | arena: Allocator, |
| 14 | io: Io, | |
| 11 | 15 | out: *std.Io.Writer, |
| 12 | 16 | args: []const []const u8, |
| 13 | 17 | wasi_preopens: switch (builtin.target.os.tag) { |
| ... | ... | @@ -21,20 +25,21 @@ pub fn cmdEnv( |
| 21 | 25 | |
| 22 | 26 | const self_exe_path = switch (builtin.target.os.tag) { |
| 23 | 27 | .wasi => args[0], |
| 24 | else => std.fs.selfExePathAlloc(arena) catch |err| { | |
| 25 | fatal("unable to find zig self exe path: {s}", .{@errorName(err)}); | |
| 28 | else => std.process.executablePathAlloc(io, arena) catch |err| { | |
| 29 | fatal("unable to find zig self exe path: {t}", .{err}); | |
| 26 | 30 | }, |
| 27 | 31 | }; |
| 28 | 32 | |
| 29 | 33 | var dirs: Compilation.Directories = .init( |
| 30 | 34 | arena, |
| 35 | io, | |
| 31 | 36 | override_lib_dir, |
| 32 | 37 | override_global_cache_dir, |
| 33 | 38 | .global, |
| 34 | 39 | if (builtin.target.os.tag == .wasi) wasi_preopens, |
| 35 | 40 | if (builtin.target.os.tag != .wasi) self_exe_path, |
| 36 | 41 | ); |
| 37 | defer dirs.deinit(); | |
| 42 | defer dirs.deinit(io); | |
| 38 | 43 | |
| 39 | 44 | const zig_lib_dir = dirs.zig_lib.path orelse ""; |
| 40 | 45 | const zig_std_dir = try dirs.zig_lib.join(arena, &.{"std"}); |
src/print_targets.zig+8-8| ... | ... | @@ -1,14 +1,16 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const Io = std.Io; | |
| 2 | 3 | const fs = std.fs; |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | const meta = std.meta; |
| 5 | 6 | const fatal = std.process.fatal; |
| 6 | 7 | const Allocator = std.mem.Allocator; |
| 7 | 8 | const Target = std.Target; |
| 8 | const target = @import("target.zig"); | |
| 9 | 9 | const assert = std.debug.assert; |
| 10 | ||
| 10 | 11 | const glibc = @import("libs/glibc.zig"); |
| 11 | 12 | const introspect = @import("introspect.zig"); |
| 13 | const target = @import("target.zig"); | |
| 12 | 14 | |
| 13 | 15 | pub fn cmdTargets( |
| 14 | 16 | allocator: Allocator, |
| ... | ... | @@ -18,19 +20,19 @@ pub fn cmdTargets( |
| 18 | 20 | native_target: *const Target, |
| 19 | 21 | ) !void { |
| 20 | 22 | _ = args; |
| 21 | var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| { | |
| 22 | fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)}); | |
| 23 | }; | |
| 23 | var zig_lib_directory = introspect.findZigLibDir(allocator, io) catch |err| | |
| 24 | fatal("unable to find zig installation directory: {t}", .{err}); | |
| 24 | 25 | defer zig_lib_directory.handle.close(io); |
| 25 | 26 | defer allocator.free(zig_lib_directory.path.?); |
| 26 | 27 | |
| 27 | 28 | const abilists_contents = zig_lib_directory.handle.readFileAlloc( |
| 29 | io, | |
| 28 | 30 | glibc.abilists_path, |
| 29 | 31 | allocator, |
| 30 | 32 | .limited(glibc.abilists_max_size), |
| 31 | 33 | ) catch |err| switch (err) { |
| 32 | 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 | 37 | defer allocator.free(abilists_contents); |
| 36 | 38 | |
| ... | ... | @@ -49,9 +51,7 @@ pub fn cmdTargets( |
| 49 | 51 | { |
| 50 | 52 | var libc_obj = try root_obj.beginTupleField("libc", .{}); |
| 51 | 53 | for (std.zig.target.available_libcs) |libc| { |
| 52 | const tmp = try std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ | |
| 53 | @tagName(libc.arch), @tagName(libc.os), @tagName(libc.abi), | |
| 54 | }); | |
| 54 | const tmp = try std.fmt.allocPrint(allocator, "{t}-{t}-{t}", .{ libc.arch, libc.os, libc.abi }); | |
| 55 | 55 | defer allocator.free(tmp); |
| 56 | 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 | 9 | defer threaded.deinit(); |
| 10 | 10 | const io = threaded.io(); |
| 11 | 11 | |
| 12 | const self_path = try std.fs.selfExePathAlloc(gpa); | |
| 12 | const self_path = try std.process.executablePathAlloc(io, gpa); | |
| 13 | 13 | defer gpa.free(self_path); |
| 14 | 14 | |
| 15 | 15 | var self_exe = try std.fs.openSelfExe(.{}); |