authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-13 20:38:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-16 13:12:47-07:00
log79a7b7c0f033787215471beb9eab99264c1b7003
treec3eaff834225cde266a0d66a3c2cf09001a3c9e3
parent88f3896522fa5314fa4b19b06a2fd3675233ddc3

compiler: update to new std.Build.Cache API


3 files changed, 13 insertions(+), 22 deletions(-)

src/Compilation.zig+10-15
...@@ -2828,11 +2828,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2828,11 +2828,6 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2828 });2828 });
2829 },2829 },
2830 },2830 },
2831 error.InvalidFormat => return comp.setMiscFailure(
2832 .check_whole_cache,
2833 "failed to check cache: invalid manifest file format",
2834 .{},
2835 ),
2836 };2831 };
2837 if (status == .hit and !ignore_hit) {2832 if (status == .hit and !ignore_hit) {
2838 // In this case the cache hit contains the full set of file system inputs. Nice!2833 // In this case the cache hit contains the full set of file system inputs. Nice!
...@@ -2845,7 +2840,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2845,7 +2840,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
28452840
2846 comp.last_update_was_cache_hit = true;2841 comp.last_update_was_cache_hit = true;
2847 log.debug("CacheMode.whole cache hit for {s}", .{comp.root_name});2842 log.debug("CacheMode.whole cache hit for {s}", .{comp.root_name});
2848 const bin_digest = man.finalBin();2843 const bin_digest = man.hitDigest();
28492844
2850 comp.digest = bin_digest;2845 comp.digest = bin_digest;
28512846
...@@ -3054,7 +3049,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -3054,7 +3049,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
3054 try man.populateOtherManifest(pwc.manifest, pwc.prefix_map);3049 try man.populateOtherManifest(pwc.manifest, pwc.prefix_map);
3055 }3050 }
30563051
3057 const bin_digest = man.finalBin();3052 const bin_digest = man.missDigest();
3058 const hex_digest = Cache.binToHex(bin_digest);3053 const hex_digest = Cache.binToHex(bin_digest);
30593054
3060 // Work around windows `AccessDenied` if any files within this3055 // Work around windows `AccessDenied` if any files within this
...@@ -5125,9 +5120,9 @@ pub fn translateC(...@@ -5125,9 +5120,9 @@ pub fn translateC(
5125 var reader: std.Io.Reader = .fixed(stdout);5120 var reader: std.Io.Reader = .fixed(stdout);
5126 const MessageHeader = std.zig.Server.Message.Header;5121 const MessageHeader = std.zig.Server.Message.Header;
5127 const header = reader.takeStruct(MessageHeader, .little) catch |err|5122 const header = reader.takeStruct(MessageHeader, .little) catch |err|
5128 fatal("unable to read translate-c MessageHeader: {s}", .{@errorName(err)});5123 fatal("unable to read translate-c MessageHeader: {t}", .{err});
5129 const body = reader.take(header.bytes_len) catch |err|5124 const body = reader.take(header.bytes_len) catch |err|
5130 fatal("unable to read {}-byte translate-c message body: {s}", .{ header.bytes_len, @errorName(err) });5125 fatal("unable to read {d}-byte translate-c message body: {t}", .{ header.bytes_len, err });
5131 switch (header.tag) {5126 switch (header.tag) {
5132 .error_bundle => {5127 .error_bundle => {
5133 const error_bundle = try std.zig.Server.allocErrorBundle(gpa, body);5128 const error_bundle = try std.zig.Server.allocErrorBundle(gpa, body);
...@@ -5137,11 +5132,11 @@ pub fn translateC(...@@ -5137,11 +5132,11 @@ pub fn translateC(
5137 .errors = error_bundle,5132 .errors = error_bundle,
5138 };5133 };
5139 },5134 },
5140 else => fatal("unexpected message type received from translate-c: {s}", .{@tagName(header.tag)}),5135 else => fatal("unexpected message type received from translate-c: {t}", .{header.tag}),
5141 }5136 }
5142 }5137 }
51435138
5144 const bin_digest = man.finalBin();5139 const bin_digest = man.missDigest();
5145 const hex_digest = Cache.binToHex(bin_digest);5140 const hex_digest = Cache.binToHex(bin_digest);
5146 const o_sub_path = "o" ++ fs.path.sep_str ++ hex_digest;5141 const o_sub_path = "o" ++ fs.path.sep_str ++ hex_digest;
51475142
...@@ -5878,10 +5873,10 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -5878,10 +5873,10 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
5878 const rc_basename = try std.fmt.allocPrint(arena, "{s}.rc", .{src_basename});5873 const rc_basename = try std.fmt.allocPrint(arena, "{s}.rc", .{src_basename});
5879 const res_basename = try std.fmt.allocPrint(arena, "{s}.res", .{src_basename});5874 const res_basename = try std.fmt.allocPrint(arena, "{s}.res", .{src_basename});
58805875
5881 const digest = if (.hit == try man.check(child_progress_node)) man.final() else blk: {5876 const digest = if (.hit == try man.check(child_progress_node)) man.hitDigestHex() else blk: {
5882 // The digest only depends on the .manifest file, so we can5877 // The digest only depends on the .manifest file, so we can
5883 // get the digest now and write the .res directly to the cache5878 // get the digest now and write the .res directly to the cache
5884 const digest = man.final();5879 const digest = man.missDigestHex();
58855880
5886 const o_sub_path = try fs.path.join(arena, &.{ "o", &digest });5881 const o_sub_path = try fs.path.join(arena, &.{ "o", &digest });
5887 var o_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, o_sub_path, .{});5882 var o_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, o_sub_path, .{});
...@@ -5970,7 +5965,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -5970,7 +5965,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
59705965
5971 const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len];5966 const rc_basename_noext = src_basename[0 .. src_basename.len - fs.path.extension(src_basename).len];
59725967
5973 const digest = if (.hit == try man.check(child_progress_node)) man.final() else blk: {5968 const digest = if (.hit == try man.check(child_progress_node)) man.hitDigestHex() else blk: {
5974 var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, "tmp", .{});5969 var zig_cache_tmp_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, "tmp", .{});
5975 defer zig_cache_tmp_dir.close(io);5970 defer zig_cache_tmp_dir.close(io);
59765971
...@@ -6042,7 +6037,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -6042,7 +6037,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6042 }6037 }
60436038
6044 // Rename into place.6039 // Rename into place.
6045 const digest = man.final();6040 const digest = man.missDigestHex();
6046 const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });6041 const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });
6047 var o_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, o_sub_path, .{});6042 var o_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, o_sub_path, .{});
6048 defer o_dir.close(io);6043 defer o_dir.close(io);
src/libs/mingw.zig+2-6
...@@ -266,13 +266,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P...@@ -266,13 +266,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P
266 },266 },
267 },267 },
268 error.OutOfMemory, error.Canceled => |e| return e,268 error.OutOfMemory, error.Canceled => |e| return e,
269 error.InvalidFormat => {
270 comp.setMiscFailure(.windows_import_lib, "checking cache failed: invalid manifest file format", .{});
271 return error.AlreadyReported;
272 },
273 };269 };
274 if (status == .hit) {270 if (status == .hit) {
275 const digest = man.final();271 const digest = man.hitDigestHex();
276 const sub_path = try std.fs.path.join(gpa, &.{ "o", &digest, final_lib_basename });272 const sub_path = try std.fs.path.join(gpa, &.{ "o", &digest, final_lib_basename });
277 errdefer gpa.free(sub_path);273 errdefer gpa.free(sub_path);
278274
...@@ -291,7 +287,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P...@@ -291,7 +287,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P
291 return crt_file_path;287 return crt_file_path;
292 }288 }
293289
294 const digest = man.final();290 const digest = man.missDigestHex();
295 const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });291 const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
296 var o_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, o_sub_path, .{});292 var o_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, o_sub_path, .{});
297 defer o_dir.close(io);293 defer o_dir.close(io);
src/main.zig+1-1
...@@ -4879,7 +4879,7 @@ fn cmdTranslateC(...@@ -4879,7 +4879,7 @@ fn cmdTranslateC(
4879 fatal("unable to process {q}: {t}", .{ c_source_file.src_path, err });4879 fatal("unable to process {q}: {t}", .{ c_source_file.src_path, err });
48804880
4881 const result: Compilation.TranslateCResult = if (.hit == try man.check(prog_node)) .{4881 const result: Compilation.TranslateCResult = if (.hit == try man.check(prog_node)) .{
4882 .digest = man.finalBin(),4882 .digest = man.hitDigest(),
4883 .cache_hit = true,4883 .cache_hit = true,
4884 .errors = std.zig.ErrorBundle.empty,4884 .errors = std.zig.ErrorBundle.empty,
4885 } else result: {4885 } else result: {