authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-12 18:54:08+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-14 12:48:13-07:00
log8bf14231b23fd68b8ce291de4ee563bc30fc4e15
treea3c728990c16395b498564a7c9cabd9e9034a36e
parentd2398cf009bfc2f4274f1326b0ef7dfbb1ae8d7f

macho: put linker symlink for cache invalidation in zig-cache

Due to differences in where the output gets emitted in stage1 and stage2, we were putting the symlink next to the binary rather than in `zig-cache` directory when building with stage2.

1 files changed, 13 insertions(+), 4 deletions(-)

src/link/MachO.zig+13-4
......@@ -452,6 +452,15 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
452452 const allow_undef = is_dyn_lib and (self.base.options.allow_shlib_undefined orelse false);
453453
454454 const id_symlink_basename = "zld.id";
455 const cache_dir_handle = blk: {
456 if (use_stage1) {
457 break :blk directory.handle;
458 }
459 if (self.base.options.module) |module| {
460 break :blk module.zig_cache_artifact_directory.handle;
461 }
462 break :blk directory.handle;
463 };
455464
456465 var man: Cache.Manifest = undefined;
457466 defer if (!self.base.options.disable_lld_caching) man.deinit();
......@@ -495,7 +504,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
495504
496505 var prev_digest_buf: [digest.len]u8 = undefined;
497506 const prev_digest: []u8 = Cache.readSmallFile(
498 directory.handle,
507 cache_dir_handle,
499508 id_symlink_basename,
500509 &prev_digest_buf,
501510 ) catch |err| blk: {
......@@ -531,7 +540,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
531540 });
532541
533542 // We are about to change the output file to be different, so we invalidate the build hash now.
534 directory.handle.deleteFile(id_symlink_basename) catch |err| switch (err) {
543 cache_dir_handle.deleteFile(id_symlink_basename) catch |err| switch (err) {
535544 error.FileNotFound => {},
536545 else => |e| return e,
537546 };
......@@ -565,7 +574,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
565574 } else {
566575 if (use_stage1) {
567576 const sub_path = self.base.options.emit.?.sub_path;
568 self.base.file = try directory.handle.createFile(sub_path, .{
577 self.base.file = try cache_dir_handle.createFile(sub_path, .{
569578 .truncate = true,
570579 .read = true,
571580 .mode = link.determineMode(self.base.options),
......@@ -1025,7 +1034,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
10251034 if (use_stage1 and self.base.options.disable_lld_caching) break :cache;
10261035 // Update the file with the digest. If it fails we can continue; it only
10271036 // means that the next invocation will have an unnecessary cache miss.
1028 Cache.writeSmallFile(directory.handle, id_symlink_basename, &digest) catch |err| {
1037 Cache.writeSmallFile(cache_dir_handle, id_symlink_basename, &digest) catch |err| {
10291038 log.debug("failed to save linking hash digest file: {s}", .{@errorName(err)});
10301039 };
10311040 // Again failure here only means an unnecessary cache miss.