authorgravatar for michael.larouche@gmail.commlarouche <michael.larouche@gmail.com> 2020-10-09 16:50:43-04:00
committergravatar for michael.larouche@gmail.commlarouche <michael.larouche@gmail.com> 2020-10-09 16:50:43-04:00
log57912964af0247a7aa940f76d09a8994d8fe1ec8
tree89d818f19130c03b55926d4b6beb927be9bc85c2
parent04b0ffdd13e32be0ef5cc84983f8bb830db7520f

Use regular file for caching stage 1 hash digest instead of symlink, fix zig build caching on Windows

Fix #6500

7 files changed, 36 insertions(+), 27 deletions(-)

lib/std/fs.zig+9
......@@ -1490,6 +1490,15 @@ pub const Dir = struct {
14901490 return os.windows.ReadLink(self.fd, sub_path_w, buffer);
14911491 }
14921492
1493 /// Read all of file contents using a preallocated buffer
1494 pub fn readFile(self: Dir, file_path: []const u8, buffer: []u8) ![]u8 {
1495 var file = try self.openFile(file_path, .{});
1496 defer file.close();
1497
1498 const end_index = try file.readAll(buffer);
1499 return buffer[0..end_index];
1500 }
1501
14931502 /// On success, caller owns returned buffer.
14941503 /// If the file is larger than `max_bytes`, returns `error.FileTooBig`.
14951504 pub fn readFileAlloc(self: Dir, allocator: *mem.Allocator, file_path: []const u8, max_bytes: usize) ![]u8 {
src/Compilation.zig+4-4
......@@ -2605,8 +2605,8 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
26052605
26062606 // We use an extra hex-encoded byte here to store some flags.
26072607 var prev_digest_buf: [digest.len + 2]u8 = undefined;
2608 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
2609 log.debug("stage1 {} new_digest={} readlink error: {}", .{ mod.root_pkg.root_src_path, digest, @errorName(err) });
2608 const prev_digest: []u8 = directory.handle.readFile(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
2609 log.debug("stage1 {} new_digest={} readFile error: {}", .{ mod.root_pkg.root_src_path, digest, @errorName(err) });
26102610 // Handle this as a cache miss.
26112611 break :blk prev_digest_buf[0..0];
26122612 };
......@@ -2792,8 +2792,8 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
27922792 log.debug("saved digest + flags: '{s}' (byte = {}) have_winmain_crt_startup={}", .{
27932793 digest_plus_flags, stage1_flags_byte, mod.stage1_flags.have_winmain_crt_startup,
27942794 });
2795 directory.handle.symLink(&digest_plus_flags, id_symlink_basename, .{}) catch |err| {
2796 log.warn("failed to save stage1 hash digest symlink: {}", .{@errorName(err)});
2795 directory.handle.writeFile(id_symlink_basename, &digest_plus_flags) catch |err| {
2796 log.warn("failed to save stage1 hash digest file: {}", .{@errorName(err)});
27972797 };
27982798 // Again failure here only means an unnecessary cache miss.
27992799 man.writeManifest() catch |err| {
src/link.zig+4-4
......@@ -466,8 +466,8 @@ pub const File = struct {
466466 const digest = ch.final();
467467
468468 var prev_digest_buf: [digest.len]u8 = undefined;
469 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| b: {
470 log.debug("archive new_digest={} readlink error: {}", .{ digest, @errorName(err) });
469 const prev_digest: []u8 = directory.handle.readFile(id_symlink_basename, &prev_digest_buf) catch |err| b: {
470 log.debug("archive new_digest={} readFile error: {}", .{ digest, @errorName(err) });
471471 break :b prev_digest_buf[0..0];
472472 };
473473 if (mem.eql(u8, prev_digest, &digest)) {
......@@ -512,8 +512,8 @@ pub const File = struct {
512512 const bad = llvm.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_type);
513513 if (bad) return error.UnableToWriteArchive;
514514
515 directory.handle.symLink(&digest, id_symlink_basename, .{}) catch |err| {
516 std.log.warn("failed to save archive hash digest symlink: {}", .{@errorName(err)});
515 directory.handle.writeFile(id_symlink_basename, &digest) catch |err| {
516 std.log.warn("failed to save archive hash digest file: {}", .{@errorName(err)});
517517 };
518518
519519 ch.writeManifest() catch |err| {
src/link/Coff.zig+5-5
......@@ -854,8 +854,8 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
854854 _ = try man.hit();
855855 digest = man.final();
856856 var prev_digest_buf: [digest.len]u8 = undefined;
857 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
858 log.debug("COFF LLD new_digest={} readlink error: {}", .{ digest, @errorName(err) });
857 const prev_digest: []u8 = directory.handle.readFile(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
858 log.debug("COFF LLD new_digest={} readFile error: {}", .{ digest, @errorName(err) });
859859 // Handle this as a cache miss.
860860 break :blk prev_digest_buf[0..0];
861861 };
......@@ -1180,10 +1180,10 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
11801180 }
11811181
11821182 if (!self.base.options.disable_lld_caching) {
1183 // Update the dangling symlink with the digest. If it fails we can continue; it only
1183 // Update the dangling file with the digest. If it fails we can continue; it only
11841184 // means that the next invocation will have an unnecessary cache miss.
1185 directory.handle.symLink(&digest, id_symlink_basename, .{}) catch |err| {
1186 std.log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});
1185 directory.handle.writeFile(id_symlink_basename, &digest) catch |err| {
1186 std.log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});
11871187 };
11881188 // Again failure here only means an unnecessary cache miss.
11891189 man.writeManifest() catch |err| {
src/link/Elf.zig+5-5
......@@ -1326,8 +1326,8 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13261326 digest = man.final();
13271327
13281328 var prev_digest_buf: [digest.len]u8 = undefined;
1329 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
1330 log.debug("ELF LLD new_digest={} readlink error: {}", .{ digest, @errorName(err) });
1329 const prev_digest: []u8 = directory.handle.readFile(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
1330 log.debug("ELF LLD new_digest={} readFile error: {}", .{ digest, @errorName(err) });
13311331 // Handle this as a cache miss.
13321332 break :blk prev_digest_buf[0..0];
13331333 };
......@@ -1647,10 +1647,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
16471647 }
16481648
16491649 if (!self.base.options.disable_lld_caching) {
1650 // Update the dangling symlink with the digest. If it fails we can continue; it only
1650 // Update the dangling file with the digest. If it fails we can continue; it only
16511651 // means that the next invocation will have an unnecessary cache miss.
1652 directory.handle.symLink(&digest, id_symlink_basename, .{}) catch |err| {
1653 std.log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});
1652 directory.handle.writeFile(id_symlink_basename, &digest) catch |err| {
1653 std.log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});
16541654 };
16551655 // Again failure here only means an unnecessary cache miss.
16561656 man.writeManifest() catch |err| {
src/link/MachO.zig+5-5
......@@ -419,8 +419,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
419419 digest = man.final();
420420
421421 var prev_digest_buf: [digest.len]u8 = undefined;
422 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
423 log.debug("MachO LLD new_digest={} readlink error: {}", .{ digest, @errorName(err) });
422 const prev_digest: []u8 = directory.handle.readFile(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
423 log.debug("MachO LLD new_digest={} readFile error: {}", .{ digest, @errorName(err) });
424424 // Handle this as a cache miss.
425425 break :blk prev_digest_buf[0..0];
426426 };
......@@ -674,10 +674,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
674674 }
675675
676676 if (!self.base.options.disable_lld_caching) {
677 // Update the dangling symlink with the digest. If it fails we can continue; it only
677 // Update the dangling file with the digest. If it fails we can continue; it only
678678 // means that the next invocation will have an unnecessary cache miss.
679 directory.handle.symLink(&digest, id_symlink_basename, .{}) catch |err| {
680 std.log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});
679 directory.handle.writeFile(id_symlink_basename, &digest) catch |err| {
680 std.log.warn("failed to save linking hash digest file: {}", .{@errorName(err)});
681681 };
682682 // Again failure here only means an unnecessary cache miss.
683683 man.writeManifest() catch |err| {
src/link/Wasm.zig+4-4
......@@ -310,8 +310,8 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
310310 digest = man.final();
311311
312312 var prev_digest_buf: [digest.len]u8 = undefined;
313 const prev_digest: []u8 = directory.handle.readLink(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
314 log.debug("WASM LLD new_digest={} readlink error: {}", .{ digest, @errorName(err) });
313 const prev_digest: []u8 = directory.handle.readFile(id_symlink_basename, &prev_digest_buf) catch |err| blk: {
314 log.debug("WASM LLD new_digest={} readFile error: {}", .{ digest, @errorName(err) });
315315 // Handle this as a cache miss.
316316 break :blk prev_digest_buf[0..0];
317317 };
......@@ -424,9 +424,9 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
424424 }
425425
426426 if (!self.base.options.disable_lld_caching) {
427 // Update the dangling symlink with the digest. If it fails we can continue; it only
427 // Update the dangling file with the digest. If it fails we can continue; it only
428428 // means that the next invocation will have an unnecessary cache miss.
429 directory.handle.symLink(&digest, id_symlink_basename, .{}) catch |err| {
429 directory.handle.writeFile(id_symlink_basename, &digest) catch |err| {
430430 std.log.warn("failed to save linking hash digest symlink: {}", .{@errorName(err)});
431431 };
432432 // Again failure here only means an unnecessary cache miss.