authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-05 10:18:05+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-05 11:22:10+01:00
logd22231c039ce8f087b2499a97eb769fb800f2000
tree4afa93c1dc0136af3619be8197672762fb8b0ead
parent38415911c10055b67d6932d7cbafd14e0b8b6775
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Compilation: track indirect file system inputs from clang's depfile

Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>

2 files changed, 33 insertions(+), 1 deletions(-)

lib/std/Build/Cache.zig+1-1
......@@ -123,7 +123,7 @@ pub const HexDigest = [hex_digest_len]u8;
123123
124124/// This is currently just an arbitrary non-empty string that can't match another manifest line.
125125const manifest_header = "0";
126const manifest_file_size_max = 100 * 1024 * 1024;
126pub const manifest_file_size_max = 100 * 1024 * 1024;
127127
128128/// The type used for hashing file contents. Currently, this is SipHash128(1, 3), because it
129129/// provides enough collision resistance for the Manifest use cases, while being one of our
src/Compilation.zig+32
......@@ -6419,6 +6419,38 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
64196419
64206420 if (out_dep_path) |dep_file_path| {
64216421 const dep_basename = fs.path.basename(dep_file_path);
6422
6423 if (comp.file_system_inputs != null) {
6424 // Use the same file size limit as the cache code does for dependency files.
6425 const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, gpa, .limited(Cache.manifest_file_size_max));
6426 defer gpa.free(dep_file_contents);
6427
6428 var str_buf: std.ArrayList(u8) = .empty;
6429 defer str_buf.deinit(gpa);
6430
6431 var it: std.Build.Cache.DepTokenizer = .{ .bytes = dep_file_contents };
6432 while (it.next()) |token| {
6433 const input_path: Compilation.Path = switch (token) {
6434 .target, .target_must_resolve => continue,
6435 .prereq => |file_path| try .fromUnresolved(arena, comp.dirs, &.{file_path}),
6436 .prereq_must_resolve => p: {
6437 try token.resolve(gpa, &str_buf);
6438 break :p try .fromUnresolved(arena, comp.dirs, &.{str_buf.items});
6439 },
6440 else => |err| {
6441 try err.printError(gpa, &str_buf);
6442 log.err("failed parsing {s}: {s}", .{ dep_basename, str_buf.items });
6443 return error.InvalidDepFile;
6444 },
6445 };
6446
6447 // There may be concurrent calls to `appendFileSystemInput` from other C objects.
6448 comp.mutex.lock();
6449 defer comp.mutex.unlock();
6450 try comp.appendFileSystemInput(input_path);
6451 }
6452 }
6453
64226454 // Add the files depended on to the cache system.
64236455 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
64246456 switch (comp.cache_use) {