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 {...@@ -452,6 +452,15 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
452 const allow_undef = is_dyn_lib and (self.base.options.allow_shlib_undefined orelse false);452 const allow_undef = is_dyn_lib and (self.base.options.allow_shlib_undefined orelse false);
453453
454 const id_symlink_basename = "zld.id";454 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
456 var man: Cache.Manifest = undefined;465 var man: Cache.Manifest = undefined;
457 defer if (!self.base.options.disable_lld_caching) man.deinit();466 defer if (!self.base.options.disable_lld_caching) man.deinit();
...@@ -495,7 +504,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -495,7 +504,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
495504
496 var prev_digest_buf: [digest.len]u8 = undefined;505 var prev_digest_buf: [digest.len]u8 = undefined;
497 const prev_digest: []u8 = Cache.readSmallFile(506 const prev_digest: []u8 = Cache.readSmallFile(
498 directory.handle,507 cache_dir_handle,
499 id_symlink_basename,508 id_symlink_basename,
500 &prev_digest_buf,509 &prev_digest_buf,
501 ) catch |err| blk: {510 ) catch |err| blk: {
...@@ -531,7 +540,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -531,7 +540,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
531 });540 });
532541
533 // We are about to change the output file to be different, so we invalidate the build hash now.542 // 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) {
535 error.FileNotFound => {},544 error.FileNotFound => {},
536 else => |e| return e,545 else => |e| return e,
537 };546 };
...@@ -565,7 +574,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -565,7 +574,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
565 } else {574 } else {
566 if (use_stage1) {575 if (use_stage1) {
567 const sub_path = self.base.options.emit.?.sub_path;576 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, .{
569 .truncate = true,578 .truncate = true,
570 .read = true,579 .read = true,
571 .mode = link.determineMode(self.base.options),580 .mode = link.determineMode(self.base.options),
...@@ -1025,7 +1034,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -1025,7 +1034,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
1025 if (use_stage1 and self.base.options.disable_lld_caching) break :cache;1034 if (use_stage1 and self.base.options.disable_lld_caching) break :cache;
1026 // Update the file with the digest. If it fails we can continue; it only1035 // Update the file with the digest. If it fails we can continue; it only
1027 // means that the next invocation will have an unnecessary cache miss.1036 // 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| {
1029 log.debug("failed to save linking hash digest file: {s}", .{@errorName(err)});1038 log.debug("failed to save linking hash digest file: {s}", .{@errorName(err)});
1030 };1039 };
1031 // Again failure here only means an unnecessary cache miss.1040 // Again failure here only means an unnecessary cache miss.