authorgravatar for readcuttingt@gmail.comTom Read Cutting <readcuttingt@gmail.com> 2022-04-22 16:12:51+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-04-22 11:12:51-04:00
loga430630002bf02162ccbf8d3eb10fd73e490cefd
treeb25bd6e1665a9207b88e5aaac8e5c4fa10078ac1
parent42e81cd81b8a0167c1a21aadf554cea2d882eadd
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Fix C include files not being in `whole` cache (#11365)


4 files changed, 19 insertions(+), 6 deletions(-)

src/Cache.zig+1-1
......@@ -690,7 +690,7 @@ pub const Manifest = struct {
690690 while (true) {
691691 switch (it.next() orelse return) {
692692 .target, .target_must_resolve => return,
693 .prereq => |bytes| try self.addFilePost(bytes),
693 .prereq => |file_path| try self.addFilePost(file_path),
694694 else => |err| {
695695 try err.printError(error_buf.writer());
696696 log.err("failed parsing {s}: {s}", .{ dep_file_basename, error_buf.items });
src/Compilation.zig+9-1
......@@ -44,6 +44,7 @@ bin_file: *link.File,
4444c_object_table: std.AutoArrayHashMapUnmanaged(*CObject, void) = .{},
4545/// This is a pointer to a local variable inside `update()`.
4646whole_cache_manifest: ?*Cache.Manifest = null,
47whole_cache_manifest_mutex: std.Thread.Mutex = .{},
4748
4849link_error_flags: link.File.ErrorFlags = .{},
4950
......@@ -1962,8 +1963,8 @@ pub fn update(comp: *Compilation) !void {
19621963 // We are about to obtain this lock, so here we give other processes a chance first.
19631964 comp.bin_file.releaseLock();
19641965
1965 comp.whole_cache_manifest = &man;
19661966 man = comp.cache_parent.obtain();
1967 comp.whole_cache_manifest = &man;
19671968 try comp.addNonIncrementalStuffToCacheManifest(&man);
19681969
19691970 const is_hit = man.hit() catch |err| {
......@@ -3352,6 +3353,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
33523353 const dep_basename = std.fs.path.basename(out_dep_path);
33533354 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
33543355 if (comp.whole_cache_manifest) |whole_cache_manifest| {
3356 comp.whole_cache_manifest_mutex.lock();
3357 defer comp.whole_cache_manifest_mutex.unlock();
33553358 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
33563359 }
33573360
......@@ -3693,6 +3696,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
36933696 const dep_basename = std.fs.path.basename(dep_file_path);
36943697 // Add the files depended on to the cache system.
36953698 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
3699 if (comp.whole_cache_manifest) |whole_cache_manifest| {
3700 comp.whole_cache_manifest_mutex.lock();
3701 defer comp.whole_cache_manifest_mutex.unlock();
3702 try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename);
3703 }
36963704 // Just to save disk space, we delete the file because it is never needed again.
36973705 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
36983706 log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
src/Module.zig+4
......@@ -3855,6 +3855,8 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
38553855 });
38563856 errdefer gpa.free(resolved_path);
38573857
3858 mod.comp.whole_cache_manifest_mutex.lock();
3859 defer mod.comp.whole_cache_manifest_mutex.unlock();
38583860 try man.addFilePostContents(resolved_path, source.bytes, source.stat);
38593861 }
38603862 } else {
......@@ -4336,6 +4338,8 @@ pub fn embedFile(mod: *Module, cur_file: *File, rel_file_path: []const u8) !*Emb
43364338 if (mod.comp.whole_cache_manifest) |man| {
43374339 const copied_resolved_path = try gpa.dupe(u8, resolved_path);
43384340 errdefer gpa.free(copied_resolved_path);
4341 mod.comp.whole_cache_manifest_mutex.lock();
4342 defer mod.comp.whole_cache_manifest_mutex.unlock();
43394343 try man.addFilePostContents(copied_resolved_path, bytes, stat);
43404344 }
43414345
src/stage1.zig+5-4
......@@ -455,10 +455,11 @@ export fn stage2_fetch_file(
455455 const comp = @intToPtr(*Compilation, stage1.userdata);
456456 const file_path = path_ptr[0..path_len];
457457 const max_file_size = std.math.maxInt(u32);
458 const contents = if (comp.whole_cache_manifest) |man|
459 man.addFilePostFetch(file_path, max_file_size) catch return null
460 else
461 std.fs.cwd().readFileAlloc(comp.gpa, file_path, max_file_size) catch return null;
458 const contents = if (comp.whole_cache_manifest) |man| blk: {
459 comp.whole_cache_manifest_mutex.lock();
460 defer comp.whole_cache_manifest_mutex.unlock();
461 break :blk man.addFilePostFetch(file_path, max_file_size) catch return null;
462 } else std.fs.cwd().readFileAlloc(comp.gpa, file_path, max_file_size) catch return null;
462463 result_len.* = contents.len;
463464 // TODO https://github.com/ziglang/zig/issues/3328#issuecomment-716749475
464465 if (contents.len == 0) return @intToPtr(?[*]const u8, 0x1);