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

Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
This commit is contained in:
Alex Rønne Petersen 2025-12-05 10:18:05 +01:00
parent 38415911c1
commit d22231c039
No known key found for this signature in database
2 changed files with 33 additions and 1 deletions

View file

@ -123,7 +123,7 @@ pub const HexDigest = [hex_digest_len]u8;
/// This is currently just an arbitrary non-empty string that can't match another manifest line.
const manifest_header = "0";
const manifest_file_size_max = 100 * 1024 * 1024;
pub const manifest_file_size_max = 100 * 1024 * 1024;
/// The type used for hashing file contents. Currently, this is SipHash128(1, 3), because it
/// provides enough collision resistance for the Manifest use cases, while being one of our

View file

@ -6419,6 +6419,38 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
if (out_dep_path) |dep_file_path| {
const dep_basename = fs.path.basename(dep_file_path);
if (comp.file_system_inputs != null) {
// Use the same file size limit as the cache code does for dependency files.
const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, gpa, .limited(Cache.manifest_file_size_max));
defer gpa.free(dep_file_contents);
var str_buf: std.ArrayList(u8) = .empty;
defer str_buf.deinit(gpa);
var it: std.Build.Cache.DepTokenizer = .{ .bytes = dep_file_contents };
while (it.next()) |token| {
const input_path: Compilation.Path = switch (token) {
.target, .target_must_resolve => continue,
.prereq => |file_path| try .fromUnresolved(arena, comp.dirs, &.{file_path}),
.prereq_must_resolve => p: {
try token.resolve(gpa, &str_buf);
break :p try .fromUnresolved(arena, comp.dirs, &.{str_buf.items});
},
else => |err| {
try err.printError(gpa, &str_buf);
log.err("failed parsing {s}: {s}", .{ dep_basename, str_buf.items });
return error.InvalidDepFile;
},
};
// There may be concurrent calls to `appendFileSystemInput` from other C objects.
comp.mutex.lock();
defer comp.mutex.unlock();
try comp.appendFileSystemInput(input_path);
}
}
// Add the files depended on to the cache system.
try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
switch (comp.cache_use) {