authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-08-18 14:35:03+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-08-19 19:09:12+02:00
logb4343074d2d6ee81f8e589395a9c045031b86b83
tree514fad342ae16a032e1556dec827955334aee2ff
parent43f73af3595c3174b8e67e9f2792c3774f2192e9
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

replace Compilation.Emit with std.Build.Cache.Path

This type is exactly the same as std.Build.Cache.Path, except for one function which is not used anymore. Therefore we can replace it without consequences.

13 files changed, 80 insertions(+), 94 deletions(-)

src/Compilation.zig+21-44
......@@ -72,9 +72,9 @@ bin_file: ?*link.File,
7272/// The root path for the dynamic linker and system libraries (as well as frameworks on Darwin)
7373sysroot: ?[]const u8,
7474/// This is `null` when not building a Windows DLL, or when `-fno-emit-implib` is used.
75implib_emit: ?Emit,
75implib_emit: ?Path,
7676/// This is non-null when `-femit-docs` is provided.
77docs_emit: ?Emit,
77docs_emit: ?Path,
7878root_name: [:0]const u8,
7979include_compiler_rt: bool,
8080objects: []Compilation.LinkObject,
......@@ -275,29 +275,6 @@ file_system_inputs: ?*std.ArrayListUnmanaged(u8),
275275/// This digest will be known after update() is called.
276276digest: ?[Cache.bin_digest_len]u8 = null,
277277
278/// TODO(robin): Remove because it is the same as Cache.Path
279pub const Emit = struct {
280 /// Where the output will go.
281 directory: Directory,
282 /// Path to the output file, relative to `directory`.
283 sub_path: []const u8,
284
285 /// Returns the full path to `basename` if it were in the same directory as the
286 /// `Emit` sub_path.
287 pub fn basenamePath(emit: Emit, arena: Allocator, basename: []const u8) ![:0]const u8 {
288 const full_path = if (emit.directory.path) |p|
289 try std.fs.path.join(arena, &[_][]const u8{ p, emit.sub_path })
290 else
291 emit.sub_path;
292
293 if (std.fs.path.dirname(full_path)) |dirname| {
294 return try std.fs.path.joinZ(arena, &.{ dirname, basename });
295 } else {
296 return try arena.dupeZ(u8, basename);
297 }
298 }
299};
300
301278pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size;
302279pub const SemaError = Zcu.SemaError;
303280
......@@ -1695,8 +1672,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
16951672 comp.cache_use = .{ .incremental = incremental };
16961673
16971674 if (options.emit_bin) |emit_bin| {
1698 const emit: Emit = .{
1699 .directory = emit_bin.directory orelse artifact_directory,
1675 const emit: Path = .{
1676 .root_dir = emit_bin.directory orelse artifact_directory,
17001677 .sub_path = emit_bin.basename,
17011678 };
17021679 comp.bin_file = try link.File.open(arena, comp, emit, lf_open_opts);
......@@ -1704,14 +1681,14 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17041681
17051682 if (options.emit_implib) |emit_implib| {
17061683 comp.implib_emit = .{
1707 .directory = emit_implib.directory orelse artifact_directory,
1684 .root_dir = emit_implib.directory orelse artifact_directory,
17081685 .sub_path = emit_implib.basename,
17091686 };
17101687 }
17111688
17121689 if (options.emit_docs) |emit_docs| {
17131690 comp.docs_emit = .{
1714 .directory = emit_docs.directory orelse artifact_directory,
1691 .root_dir = emit_docs.directory orelse artifact_directory,
17151692 .sub_path = emit_docs.basename,
17161693 };
17171694 }
......@@ -2164,21 +2141,21 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21642141
21652142 if (whole.implib_sub_path) |sub_path| {
21662143 comp.implib_emit = .{
2167 .directory = tmp_artifact_directory,
2144 .root_dir = tmp_artifact_directory,
21682145 .sub_path = std.fs.path.basename(sub_path),
21692146 };
21702147 }
21712148
21722149 if (whole.docs_sub_path) |sub_path| {
21732150 comp.docs_emit = .{
2174 .directory = tmp_artifact_directory,
2151 .root_dir = tmp_artifact_directory,
21752152 .sub_path = std.fs.path.basename(sub_path),
21762153 };
21772154 }
21782155
21792156 if (whole.bin_sub_path) |sub_path| {
2180 const emit: Emit = .{
2181 .directory = tmp_artifact_directory,
2157 const emit: Path = .{
2158 .root_dir = tmp_artifact_directory,
21822159 .sub_path = std.fs.path.basename(sub_path),
21832160 };
21842161 comp.bin_file = try link.File.createEmpty(arena, comp, emit, whole.lf_open_opts);
......@@ -2394,7 +2371,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
23942371 // references object file paths.
23952372 if (comp.bin_file) |lf| {
23962373 lf.emit = .{
2397 .directory = comp.local_cache_directory,
2374 .root_dir = comp.local_cache_directory,
23982375 .sub_path = whole.bin_sub_path.?,
23992376 };
24002377
......@@ -2543,7 +2520,7 @@ fn wholeCacheModeSetBinFilePath(
25432520 @memcpy(sub_path[digest_start..][0..digest.len], digest);
25442521
25452522 comp.implib_emit = .{
2546 .directory = comp.local_cache_directory,
2523 .root_dir = comp.local_cache_directory,
25472524 .sub_path = sub_path,
25482525 };
25492526 }
......@@ -2552,7 +2529,7 @@ fn wholeCacheModeSetBinFilePath(
25522529 @memcpy(sub_path[digest_start..][0..digest.len], digest);
25532530
25542531 comp.docs_emit = .{
2555 .directory = comp.local_cache_directory,
2532 .root_dir = comp.local_cache_directory,
25562533 .sub_path = sub_path,
25572534 };
25582535 }
......@@ -3045,7 +3022,7 @@ pub fn saveState(comp: *Compilation) !void {
30453022
30463023 // Using an atomic file prevents a crash or power failure from corrupting
30473024 // the previous incremental compilation state.
3048 var af = try lf.emit.directory.handle.atomicFile(basename, .{});
3025 var af = try lf.emit.root_dir.handle.atomicFile(basename, .{});
30493026 defer af.deinit();
30503027 try af.file.pwritevAll(bufs.items, 0);
30513028 try af.finish();
......@@ -4010,11 +3987,11 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
40103987 return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{});
40113988
40123989 const emit = comp.docs_emit.?;
4013 var out_dir = emit.directory.handle.makeOpenPath(emit.sub_path, .{}) catch |err| {
3990 var out_dir = emit.root_dir.handle.makeOpenPath(emit.sub_path, .{}) catch |err| {
40143991 return comp.lockAndSetMiscFailure(
40153992 .docs_copy,
40163993 "unable to create output directory '{}{s}': {s}",
4017 .{ emit.directory, emit.sub_path, @errorName(err) },
3994 .{ emit.root_dir, emit.sub_path, @errorName(err) },
40183995 );
40193996 };
40203997 defer out_dir.close();
......@@ -4034,7 +4011,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
40344011 return comp.lockAndSetMiscFailure(
40354012 .docs_copy,
40364013 "unable to create '{}{s}/sources.tar': {s}",
4037 .{ emit.directory, emit.sub_path, @errorName(err) },
4014 .{ emit.root_dir, emit.sub_path, @errorName(err) },
40384015 );
40394016 };
40404017 defer tar_file.close();
......@@ -4233,11 +4210,11 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
42334210 try comp.updateSubCompilation(sub_compilation, .docs_wasm, prog_node);
42344211
42354212 const emit = comp.docs_emit.?;
4236 var out_dir = emit.directory.handle.makeOpenPath(emit.sub_path, .{}) catch |err| {
4213 var out_dir = emit.root_dir.handle.makeOpenPath(emit.sub_path, .{}) catch |err| {
42374214 return comp.lockAndSetMiscFailure(
42384215 .docs_copy,
42394216 "unable to create output directory '{}{s}': {s}",
4240 .{ emit.directory, emit.sub_path, @errorName(err) },
4217 .{ emit.root_dir, emit.sub_path, @errorName(err) },
42414218 );
42424219 };
42434220 defer out_dir.close();
......@@ -4251,7 +4228,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
42514228 return comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{}{s}' to '{}{s}': {s}", .{
42524229 sub_compilation.local_cache_directory,
42534230 sub_compilation.cache_use.whole.bin_sub_path.?,
4254 emit.directory,
4231 emit.root_dir,
42554232 emit.sub_path,
42564233 @errorName(err),
42574234 });
......@@ -4803,7 +4780,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
48034780 try argv.appendSlice(c_object.src.cache_exempt_flags);
48044781
48054782 const out_obj_path = if (comp.bin_file) |lf|
4806 try lf.emit.directory.join(arena, &.{lf.emit.sub_path})
4783 try lf.emit.root_dir.join(arena, &.{lf.emit.sub_path})
48074784 else
48084785 "/dev/null";
48094786
src/link.zig+10-9
......@@ -11,6 +11,7 @@ const wasi_libc = @import("wasi_libc.zig");
1111const Air = @import("Air.zig");
1212const Allocator = std.mem.Allocator;
1313const Cache = std.Build.Cache;
14const Path = Cache.Path;
1415const Compilation = @import("Compilation.zig");
1516const LibCInstallation = std.zig.LibCInstallation;
1617const Liveness = @import("Liveness.zig");
......@@ -56,7 +57,7 @@ pub const File = struct {
5657
5758 /// The owner of this output File.
5859 comp: *Compilation,
59 emit: Compilation.Emit,
60 emit: Path,
6061
6162 file: ?fs.File,
6263 /// When linking with LLD, this linker code will output an object file only at
......@@ -189,7 +190,7 @@ pub const File = struct {
189190 pub fn open(
190191 arena: Allocator,
191192 comp: *Compilation,
192 emit: Compilation.Emit,
193 emit: Path,
193194 options: OpenOptions,
194195 ) !*File {
195196 switch (Tag.fromObjectFormat(comp.root_mod.resolved_target.result.ofmt)) {
......@@ -204,7 +205,7 @@ pub const File = struct {
204205 pub fn createEmpty(
205206 arena: Allocator,
206207 comp: *Compilation,
207 emit: Compilation.Emit,
208 emit: Path,
208209 options: OpenOptions,
209210 ) !*File {
210211 switch (Tag.fromObjectFormat(comp.root_mod.resolved_target.result.ofmt)) {
......@@ -243,8 +244,8 @@ pub const File = struct {
243244 emit.sub_path, std.crypto.random.int(u32),
244245 });
245246 defer gpa.free(tmp_sub_path);
246 try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{});
247 try emit.directory.handle.rename(tmp_sub_path, emit.sub_path);
247 try emit.root_dir.handle.copyFile(emit.sub_path, emit.root_dir.handle, tmp_sub_path, .{});
248 try emit.root_dir.handle.rename(tmp_sub_path, emit.sub_path);
248249 switch (builtin.os.tag) {
249250 .linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| {
250251 log.warn("ptrace failure: {s}", .{@errorName(err)});
......@@ -260,7 +261,7 @@ pub const File = struct {
260261 const use_lld = build_options.have_llvm and comp.config.use_lld;
261262 const output_mode = comp.config.output_mode;
262263 const link_mode = comp.config.link_mode;
263 base.file = try emit.directory.handle.createFile(emit.sub_path, .{
264 base.file = try emit.root_dir.handle.createFile(emit.sub_path, .{
264265 .truncate = false,
265266 .read = true,
266267 .mode = determineMode(use_lld, output_mode, link_mode),
......@@ -603,7 +604,7 @@ pub const File = struct {
603604 // Until then, we do `lld -r -o output.o input.o` even though the output is the same
604605 // as the input. For the preprocessing case (`zig cc -E -o foo`) we copy the file
605606 // to the final location. See also the corresponding TODO in Coff linking.
606 const full_out_path = try emit.directory.join(gpa, &[_][]const u8{emit.sub_path});
607 const full_out_path = try emit.root_dir.join(gpa, &[_][]const u8{emit.sub_path});
607608 defer gpa.free(full_out_path);
608609 assert(comp.c_object_table.count() == 1);
609610 const the_key = comp.c_object_table.keys()[0];
......@@ -751,7 +752,7 @@ pub const File = struct {
751752 const comp = base.comp;
752753 const gpa = comp.gpa;
753754
754 const directory = base.emit.directory; // Just an alias to make it shorter to type.
755 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.
755756 const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path});
756757 const full_out_path_z = try arena.dupeZ(u8, full_out_path);
757758 const opt_zcu = comp.module;
......@@ -1030,7 +1031,7 @@ pub const File = struct {
10301031 prog_node: std.Progress.Node,
10311032 ) !void {
10321033 return base.comp.emitLlvmObject(arena, .{
1033 .root_dir = base.emit.directory,
1034 .root_dir = base.emit.root_dir,
10341035 .sub_path = std.fs.path.dirname(base.emit.sub_path) orelse "",
10351036 }, .{
10361037 .directory = null,
src/link/C.zig+4-3
......@@ -3,6 +3,7 @@ const mem = std.mem;
33const assert = std.debug.assert;
44const Allocator = std.mem.Allocator;
55const fs = std.fs;
6const Path = std.Build.Cache.Path;
67
78const C = @This();
89const build_options = @import("build_options");
......@@ -104,7 +105,7 @@ pub fn addString(this: *C, s: []const u8) Allocator.Error!String {
104105pub fn open(
105106 arena: Allocator,
106107 comp: *Compilation,
107 emit: Compilation.Emit,
108 emit: Path,
108109 options: link.File.OpenOptions,
109110) !*C {
110111 return createEmpty(arena, comp, emit, options);
......@@ -113,7 +114,7 @@ pub fn open(
113114pub fn createEmpty(
114115 arena: Allocator,
115116 comp: *Compilation,
116 emit: Compilation.Emit,
117 emit: Path,
117118 options: link.File.OpenOptions,
118119) !*C {
119120 const target = comp.root_mod.resolved_target.result;
......@@ -127,7 +128,7 @@ pub fn createEmpty(
127128 assert(!use_lld);
128129 assert(!use_llvm);
129130
130 const file = try emit.directory.handle.createFile(emit.sub_path, .{
131 const file = try emit.root_dir.handle.createFile(emit.sub_path, .{
131132 // Truncation is done on `flush`.
132133 .truncate = false,
133134 });
src/link/Coff.zig+4-3
......@@ -219,7 +219,7 @@ pub const min_text_capacity = padToIdeal(minimum_text_block_size);
219219pub fn createEmpty(
220220 arena: Allocator,
221221 comp: *Compilation,
222 emit: Compilation.Emit,
222 emit: Path,
223223 options: link.File.OpenOptions,
224224) !*Coff {
225225 const target = comp.root_mod.resolved_target.result;
......@@ -315,7 +315,7 @@ pub fn createEmpty(
315315 // If using LLD to link, this code should produce an object file so that it
316316 // can be passed to LLD.
317317 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;
318 self.base.file = try emit.directory.handle.createFile(sub_path, .{
318 self.base.file = try emit.root_dir.handle.createFile(sub_path, .{
319319 .truncate = true,
320320 .read = true,
321321 .mode = link.File.determineMode(use_lld, output_mode, link_mode),
......@@ -416,7 +416,7 @@ pub fn createEmpty(
416416pub fn open(
417417 arena: Allocator,
418418 comp: *Compilation,
419 emit: Compilation.Emit,
419 emit: Path,
420420 options: link.File.OpenOptions,
421421) !*Coff {
422422 // TODO: restore saved linker state, don't truncate the file, and
......@@ -2714,6 +2714,7 @@ const math = std.math;
27142714const mem = std.mem;
27152715
27162716const Allocator = std.mem.Allocator;
2717const Path = std.Build.Cache.Path;
27172718
27182719const codegen = @import("../codegen.zig");
27192720const link = @import("../link.zig");
src/link/Coff/lld.zig+2-2
......@@ -27,7 +27,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
2727 const comp = self.base.comp;
2828 const gpa = comp.gpa;
2929
30 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.
30 const directory = self.base.emit.root_dir; // Just an alias to make it shorter to type.
3131 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
3232
3333 // If there is no Zig code to compile, then we should skip flushing the output file because it
......@@ -248,7 +248,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
248248 try argv.append(try allocPrint(arena, "-OUT:{s}", .{full_out_path}));
249249
250250 if (comp.implib_emit) |emit| {
251 const implib_out_path = try emit.directory.join(arena, &[_][]const u8{emit.sub_path});
251 const implib_out_path = try emit.root_dir.join(arena, &[_][]const u8{emit.sub_path});
252252 try argv.append(try allocPrint(arena, "-IMPLIB:{s}", .{implib_out_path}));
253253 }
254254
src/link/Elf.zig+7-6
......@@ -204,7 +204,7 @@ pub const SortSection = enum { name, alignment };
204204pub fn createEmpty(
205205 arena: Allocator,
206206 comp: *Compilation,
207 emit: Compilation.Emit,
207 emit: Path,
208208 options: link.File.OpenOptions,
209209) !*Elf {
210210 const target = comp.root_mod.resolved_target.result;
......@@ -321,7 +321,7 @@ pub fn createEmpty(
321321 // If using LLD to link, this code should produce an object file so that it
322322 // can be passed to LLD.
323323 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;
324 self.base.file = try emit.directory.handle.createFile(sub_path, .{
324 self.base.file = try emit.root_dir.handle.createFile(sub_path, .{
325325 .truncate = true,
326326 .read = true,
327327 .mode = link.File.determineMode(use_lld, output_mode, link_mode),
......@@ -401,7 +401,7 @@ pub fn createEmpty(
401401pub fn open(
402402 arena: Allocator,
403403 comp: *Compilation,
404 emit: Compilation.Emit,
404 emit: Path,
405405 options: link.File.OpenOptions,
406406) !*Elf {
407407 // TODO: restore saved linker state, don't truncate the file, and
......@@ -999,7 +999,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
999999
10001000 const target = comp.root_mod.resolved_target.result;
10011001 const link_mode = comp.config.link_mode;
1002 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.
1002 const directory = self.base.emit.root_dir; // Just an alias to make it shorter to type.
10031003 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
10041004 const module_obj_path: ?[]const u8 = if (self.base.zcu_object_sub_path) |path| blk: {
10051005 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -1356,7 +1356,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
13561356
13571357 const target = self.base.comp.root_mod.resolved_target.result;
13581358 const link_mode = self.base.comp.config.link_mode;
1359 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.
1359 const directory = self.base.emit.root_dir; // Just an alias to make it shorter to type.
13601360 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
13611361 const module_obj_path: ?[]const u8 = if (self.base.zcu_object_sub_path) |path| blk: {
13621362 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -2054,7 +2054,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
20542054 const comp = self.base.comp;
20552055 const gpa = comp.gpa;
20562056
2057 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.
2057 const directory = self.base.emit.root_dir; // Just an alias to make it shorter to type.
20582058 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
20592059
20602060 // If there is no Zig code to compile, then we should skip flushing the output file because it
......@@ -6016,6 +6016,7 @@ const Allocator = std.mem.Allocator;
60166016const Archive = @import("Elf/Archive.zig");
60176017pub const Atom = @import("Elf/Atom.zig");
60186018const Cache = std.Build.Cache;
6019const Path = Cache.Path;
60196020const Compilation = @import("../Compilation.zig");
60206021const ComdatGroupSection = synthetic_sections.ComdatGroupSection;
60216022const CopyRelSection = synthetic_sections.CopyRelSection;
src/link/MachO.zig+9-8
......@@ -156,7 +156,7 @@ pub fn hashAddFrameworks(man: *Cache.Manifest, hm: []const Framework) !void {
156156pub fn createEmpty(
157157 arena: Allocator,
158158 comp: *Compilation,
159 emit: Compilation.Emit,
159 emit: Path,
160160 options: link.File.OpenOptions,
161161) !*MachO {
162162 const target = comp.root_mod.resolved_target.result;
......@@ -221,7 +221,7 @@ pub fn createEmpty(
221221 }
222222 errdefer self.base.destroy();
223223
224 self.base.file = try emit.directory.handle.createFile(emit.sub_path, .{
224 self.base.file = try emit.root_dir.handle.createFile(emit.sub_path, .{
225225 .truncate = true,
226226 .read = true,
227227 .mode = link.File.determineMode(false, output_mode, link_mode),
......@@ -260,7 +260,7 @@ pub fn createEmpty(
260260pub fn open(
261261 arena: Allocator,
262262 comp: *Compilation,
263 emit: Compilation.Emit,
263 emit: Path,
264264 options: link.File.OpenOptions,
265265) !*MachO {
266266 // TODO: restore saved linker state, don't truncate the file, and
......@@ -353,7 +353,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
353353 const sub_prog_node = prog_node.start("MachO Flush", 0);
354354 defer sub_prog_node.end();
355355
356 const directory = self.base.emit.directory;
356 const directory = self.base.emit.root_dir;
357357 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
358358 const module_obj_path: ?[]const u8 = if (self.base.zcu_object_sub_path) |path| blk: {
359359 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -586,7 +586,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
586586 if (codesig) |*csig| {
587587 try self.writeCodeSignature(csig); // code signing always comes last
588588 const emit = self.base.emit;
589 try invalidateKernelCache(emit.directory.handle, emit.sub_path);
589 try invalidateKernelCache(emit.root_dir.handle, emit.sub_path);
590590 }
591591}
592592
......@@ -597,7 +597,7 @@ fn dumpArgv(self: *MachO, comp: *Compilation) !void {
597597 defer arena_allocator.deinit();
598598 const arena = arena_allocator.allocator();
599599
600 const directory = self.base.emit.directory;
600 const directory = self.base.emit.root_dir;
601601 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
602602 const module_obj_path: ?[]const u8 = if (self.base.zcu_object_sub_path) |path| blk: {
603603 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -3199,7 +3199,7 @@ fn copyRangeAllZeroOut(self: *MachO, old_offset: u64, new_offset: u64, size: u64
31993199}
32003200
32013201const InitMetadataOptions = struct {
3202 emit: Compilation.Emit,
3202 emit: Path,
32033203 zo: *ZigObject,
32043204 symbol_count_hint: u64,
32053205 program_code_size_hint: u64,
......@@ -3271,7 +3271,7 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void {
32713271 );
32723272 defer gpa.free(d_sym_path);
32733273
3274 var d_sym_bundle = try options.emit.directory.handle.makeOpenPath(d_sym_path, .{});
3274 var d_sym_bundle = try options.emit.root_dir.handle.makeOpenPath(d_sym_path, .{});
32753275 defer d_sym_bundle.close();
32763276
32773277 const d_sym_file = try d_sym_bundle.createFile(options.emit.sub_path, .{
......@@ -4603,6 +4603,7 @@ pub const Atom = @import("MachO/Atom.zig");
46034603const AtomicBool = std.atomic.Value(bool);
46044604const Bind = bind.Bind;
46054605const Cache = std.Build.Cache;
4606const Path = Cache.Path;
46064607const CodeSignature = @import("MachO/CodeSignature.zig");
46074608const Compilation = @import("../Compilation.zig");
46084609const DataInCode = synthetic.DataInCode;
src/link/MachO/load_commands.zig+2-2
......@@ -53,7 +53,7 @@ pub fn calcLoadCommandsSize(macho_file: *MachO, assume_max_path_len: bool) !u32
5353 if (macho_file.base.isDynLib()) {
5454 const emit = macho_file.base.emit;
5555 const install_name = macho_file.install_name orelse
56 try emit.directory.join(gpa, &.{emit.sub_path});
56 try emit.root_dir.join(gpa, &.{emit.sub_path});
5757 defer if (macho_file.install_name == null) gpa.free(install_name);
5858 sizeofcmds += calcInstallNameLen(
5959 @sizeOf(macho.dylib_command),
......@@ -237,7 +237,7 @@ pub fn writeDylibIdLC(macho_file: *MachO, writer: anytype) !void {
237237 assert(comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic);
238238 const emit = macho_file.base.emit;
239239 const install_name = macho_file.install_name orelse
240 try emit.directory.join(gpa, &.{emit.sub_path});
240 try emit.root_dir.join(gpa, &.{emit.sub_path});
241241 defer if (macho_file.install_name == null) gpa.free(install_name);
242242 const curr = comp.version orelse std.SemanticVersion{
243243 .major = 1,
src/link/NvPtx.zig+3-2
......@@ -11,6 +11,7 @@ const builtin = @import("builtin");
1111const Allocator = std.mem.Allocator;
1212const assert = std.debug.assert;
1313const log = std.log.scoped(.link);
14const Path = std.Build.Cache.Path;
1415
1516const Zcu = @import("../Zcu.zig");
1617const InternPool = @import("../InternPool.zig");
......@@ -28,7 +29,7 @@ llvm_object: LlvmObject.Ptr,
2829pub fn createEmpty(
2930 arena: Allocator,
3031 comp: *Compilation,
31 emit: Compilation.Emit,
32 emit: Path,
3233 options: link.File.OpenOptions,
3334) !*NvPtx {
3435 const target = comp.root_mod.resolved_target.result;
......@@ -70,7 +71,7 @@ pub fn createEmpty(
7071pub fn open(
7172 arena: Allocator,
7273 comp: *Compilation,
73 emit: Compilation.Emit,
74 emit: Path,
7475 options: link.File.OpenOptions,
7576) !*NvPtx {
7677 const target = comp.root_mod.resolved_target.result;
src/link/Plan9.zig+4-3
......@@ -23,6 +23,7 @@ const mem = std.mem;
2323const Allocator = std.mem.Allocator;
2424const log = std.log.scoped(.link);
2525const assert = std.debug.assert;
26const Path = std.Build.Cache.Path;
2627
2728base: link.File,
2829sixtyfour_bit: bool,
......@@ -275,7 +276,7 @@ pub fn defaultBaseAddrs(arch: std.Target.Cpu.Arch) Bases {
275276pub fn createEmpty(
276277 arena: Allocator,
277278 comp: *Compilation,
278 emit: Compilation.Emit,
279 emit: Path,
279280 options: link.File.OpenOptions,
280281) !*Plan9 {
281282 const target = comp.root_mod.resolved_target.result;
......@@ -1199,7 +1200,7 @@ pub fn deinit(self: *Plan9) void {
11991200pub fn open(
12001201 arena: Allocator,
12011202 comp: *Compilation,
1202 emit: Compilation.Emit,
1203 emit: Path,
12031204 options: link.File.OpenOptions,
12041205) !*Plan9 {
12051206 const target = comp.root_mod.resolved_target.result;
......@@ -1213,7 +1214,7 @@ pub fn open(
12131214 const self = try createEmpty(arena, comp, emit, options);
12141215 errdefer self.base.destroy();
12151216
1216 const file = try emit.directory.handle.createFile(emit.sub_path, .{
1217 const file = try emit.root_dir.handle.createFile(emit.sub_path, .{
12171218 .read = true,
12181219 .mode = link.File.determineMode(
12191220 use_lld,
src/link/SpirV.zig+4-3
......@@ -26,6 +26,7 @@ const std = @import("std");
2626const Allocator = std.mem.Allocator;
2727const assert = std.debug.assert;
2828const log = std.log.scoped(.link);
29const Path = std.Build.Cache.Path;
2930
3031const Zcu = @import("../Zcu.zig");
3132const InternPool = @import("../InternPool.zig");
......@@ -54,7 +55,7 @@ object: codegen.Object,
5455pub fn createEmpty(
5556 arena: Allocator,
5657 comp: *Compilation,
57 emit: Compilation.Emit,
58 emit: Path,
5859 options: link.File.OpenOptions,
5960) !*SpirV {
6061 const gpa = comp.gpa;
......@@ -95,7 +96,7 @@ pub fn createEmpty(
9596pub fn open(
9697 arena: Allocator,
9798 comp: *Compilation,
98 emit: Compilation.Emit,
99 emit: Path,
99100 options: link.File.OpenOptions,
100101) !*SpirV {
101102 const target = comp.root_mod.resolved_target.result;
......@@ -110,7 +111,7 @@ pub fn open(
110111 errdefer spirv.base.destroy();
111112
112113 // TODO: read the file and keep valid parts instead of truncating
113 const file = try emit.directory.handle.createFile(emit.sub_path, .{
114 const file = try emit.root_dir.handle.createFile(emit.sub_path, .{
114115 .truncate = true,
115116 .read = true,
116117 });
src/link/Wasm.zig+6-5
......@@ -22,6 +22,7 @@ const Air = @import("../Air.zig");
2222const Allocator = std.mem.Allocator;
2323const Archive = @import("Wasm/Archive.zig");
2424const Cache = std.Build.Cache;
25const Path = Cache.Path;
2526const CodeGen = @import("../arch/wasm/CodeGen.zig");
2627const Compilation = @import("../Compilation.zig");
2728const Dwarf = @import("Dwarf.zig");
......@@ -346,7 +347,7 @@ pub const StringTable = struct {
346347pub fn open(
347348 arena: Allocator,
348349 comp: *Compilation,
349 emit: Compilation.Emit,
350 emit: Path,
350351 options: link.File.OpenOptions,
351352) !*Wasm {
352353 // TODO: restore saved linker state, don't truncate the file, and
......@@ -357,7 +358,7 @@ pub fn open(
357358pub fn createEmpty(
358359 arena: Allocator,
359360 comp: *Compilation,
360 emit: Compilation.Emit,
361 emit: Path,
361362 options: link.File.OpenOptions,
362363) !*Wasm {
363364 const gpa = comp.gpa;
......@@ -430,7 +431,7 @@ pub fn createEmpty(
430431 // can be passed to LLD.
431432 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;
432433
433 wasm.base.file = try emit.directory.handle.createFile(sub_path, .{
434 wasm.base.file = try emit.root_dir.handle.createFile(sub_path, .{
434435 .truncate = true,
435436 .read = true,
436437 .mode = if (fs.has_executable_bit)
......@@ -2496,7 +2497,7 @@ pub fn flushModule(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
24962497 const sub_prog_node = prog_node.start("Wasm Flush", 0);
24972498 defer sub_prog_node.end();
24982499
2499 const directory = wasm.base.emit.directory; // Just an alias to make it shorter to type.
2500 const directory = wasm.base.emit.root_dir; // Just an alias to make it shorter to type.
25002501 const full_out_path = try directory.join(arena, &[_][]const u8{wasm.base.emit.sub_path});
25012502 const module_obj_path: ?[]const u8 = if (wasm.base.zcu_object_sub_path) |path| blk: {
25022503 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -3346,7 +3347,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
33463347
33473348 const gpa = comp.gpa;
33483349
3349 const directory = wasm.base.emit.directory; // Just an alias to make it shorter to type.
3350 const directory = wasm.base.emit.root_dir; // Just an alias to make it shorter to type.
33503351 const full_out_path = try directory.join(arena, &[_][]const u8{wasm.base.emit.sub_path});
33513352
33523353 // If there is no Zig code to compile, then we should skip flushing the output file because it
src/main.zig+4-4
......@@ -3519,7 +3519,7 @@ fn buildOutputType(
35193519 if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
35203520 // Default to using `zig run` to execute the produced .c code from `zig test`.
35213521 const c_code_loc = emit_bin_loc orelse break :default_exec_args;
3522 const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.directory;
3522 const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.root_dir;
35233523 const c_code_path = try fs.path.join(arena, &[_][]const u8{
35243524 c_code_directory.path orelse ".", c_code_loc.basename,
35253525 });
......@@ -4256,7 +4256,7 @@ fn runOrTest(
42564256 // A naive `directory.join` here will indeed get the correct path to the binary,
42574257 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.
42584258 const exe_path = try fs.path.join(arena, &[_][]const u8{
4259 lf.emit.directory.path orelse ".", lf.emit.sub_path,
4259 lf.emit.root_dir.path orelse ".", lf.emit.sub_path,
42604260 });
42614261
42624262 var argv = std.ArrayList([]const u8).init(gpa);
......@@ -4368,7 +4368,7 @@ fn runOrTestHotSwap(
43684368 // tmp zig-cache and use it to spawn the child process. This way we are free to update
43694369 // the binary with each requested hot update.
43704370 .windows => blk: {
4371 try lf.emit.directory.handle.copyFile(lf.emit.sub_path, comp.local_cache_directory.handle, lf.emit.sub_path, .{});
4371 try lf.emit.root_dir.handle.copyFile(lf.emit.sub_path, comp.local_cache_directory.handle, lf.emit.sub_path, .{});
43724372 break :blk try fs.path.join(gpa, &[_][]const u8{
43734373 comp.local_cache_directory.path orelse ".", lf.emit.sub_path,
43744374 });
......@@ -4377,7 +4377,7 @@ fn runOrTestHotSwap(
43774377 // A naive `directory.join` here will indeed get the correct path to the binary,
43784378 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.
43794379 else => try fs.path.join(gpa, &[_][]const u8{
4380 lf.emit.directory.path orelse ".", lf.emit.sub_path,
4380 lf.emit.root_dir.path orelse ".", lf.emit.sub_path,
43814381 }),
43824382 };
43834383 defer gpa.free(exe_path);