| ... | ... | @@ -201,6 +201,9 @@ c_source_files: []const CSourceFile, |
| 201 | 201 | rc_source_files: []const RcSourceFile, |
| 202 | 202 | global_cc_argv: []const []const u8, |
| 203 | 203 | cache_parent: *Cache, |
| 204 | /// Populated when a sub-Compilation is created during the `update` of its parent. |
| 205 | /// In this case the child must additionally add file system inputs to this object. |
| 206 | parent_whole_cache: ?ParentWholeCache, |
| 204 | 207 | /// Path to own executable for invoking `zig clang`. |
| 205 | 208 | self_exe_path: ?[]const u8, |
| 206 | 209 | zig_lib_directory: Directory, |
| ... | ... | @@ -970,6 +973,12 @@ pub const SystemLib = link.SystemLib; |
| 970 | 973 | |
| 971 | 974 | pub const CacheMode = enum { incremental, whole }; |
| 972 | 975 | |
| 976 | pub const ParentWholeCache = struct { |
| 977 | manifest: *Cache.Manifest, |
| 978 | mutex: *std.Thread.Mutex, |
| 979 | prefix_map: [4]u8, |
| 980 | }; |
| 981 | |
| 973 | 982 | const CacheUse = union(CacheMode) { |
| 974 | 983 | incremental: *Incremental, |
| 975 | 984 | whole: *Whole, |
| ... | ... | @@ -1207,6 +1216,8 @@ pub const CreateOptions = struct { |
| 1207 | 1216 | /// Tracks all files that can cause the Compilation to be invalidated and need a rebuild. |
| 1208 | 1217 | file_system_inputs: ?*std.ArrayListUnmanaged(u8) = null, |
| 1209 | 1218 | |
| 1219 | parent_whole_cache: ?ParentWholeCache = null, |
| 1220 | |
| 1210 | 1221 | pub const Entry = link.File.OpenOptions.Entry; |
| 1211 | 1222 | }; |
| 1212 | 1223 | |
| ... | ... | @@ -1563,6 +1574,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1563 | 1574 | .link_eh_frame_hdr = link_eh_frame_hdr, |
| 1564 | 1575 | .global_cc_argv = options.global_cc_argv, |
| 1565 | 1576 | .file_system_inputs = options.file_system_inputs, |
| 1577 | .parent_whole_cache = options.parent_whole_cache, |
| 1566 | 1578 | }; |
| 1567 | 1579 | |
| 1568 | 1580 | // Prevent some footguns by making the "any" fields of config reflect |
| ... | ... | @@ -2106,6 +2118,11 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2106 | 2118 | if (is_hit) { |
| 2107 | 2119 | // In this case the cache hit contains the full set of file system inputs. Nice! |
| 2108 | 2120 | if (comp.file_system_inputs) |buf| try man.populateFileSystemInputs(buf); |
| 2121 | if (comp.parent_whole_cache) |pwc| { |
| 2122 | pwc.mutex.lock(); |
| 2123 | defer pwc.mutex.unlock(); |
| 2124 | try man.populateOtherManifest(pwc.manifest, pwc.prefix_map); |
| 2125 | } |
| 2109 | 2126 | |
| 2110 | 2127 | comp.last_update_was_cache_hit = true; |
| 2111 | 2128 | log.debug("CacheMode.whole cache hit for {s}", .{comp.root_name}); |
| ... | ... | @@ -2303,6 +2320,11 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2303 | 2320 | switch (comp.cache_use) { |
| 2304 | 2321 | .whole => |whole| { |
| 2305 | 2322 | if (comp.file_system_inputs) |buf| try man.populateFileSystemInputs(buf); |
| 2323 | if (comp.parent_whole_cache) |pwc| { |
| 2324 | pwc.mutex.lock(); |
| 2325 | defer pwc.mutex.unlock(); |
| 2326 | try man.populateOtherManifest(pwc.manifest, pwc.prefix_map); |
| 2327 | } |
| 2306 | 2328 | |
| 2307 | 2329 | const digest = man.final(); |
| 2308 | 2330 | |
| ... | ... | @@ -6420,14 +6442,29 @@ fn buildOutputFromZig( |
| 6420 | 6442 | .output_mode = output_mode, |
| 6421 | 6443 | }); |
| 6422 | 6444 | |
| 6445 | const parent_whole_cache: ?ParentWholeCache = switch (comp.cache_use) { |
| 6446 | .whole => |whole| .{ |
| 6447 | .manifest = whole.cache_manifest.?, |
| 6448 | .mutex = &whole.cache_manifest_mutex, |
| 6449 | .prefix_map = .{ |
| 6450 | 0, // cwd is the same |
| 6451 | 1, // zig lib dir is the same |
| 6452 | 3, // local cache is mapped to global cache |
| 6453 | 3, // global cache is the same |
| 6454 | }, |
| 6455 | }, |
| 6456 | .incremental => null, |
| 6457 | }; |
| 6458 | |
| 6423 | 6459 | const sub_compilation = try Compilation.create(gpa, arena, .{ |
| 6424 | 6460 | .global_cache_directory = comp.global_cache_directory, |
| 6425 | 6461 | .local_cache_directory = comp.global_cache_directory, |
| 6426 | 6462 | .zig_lib_directory = comp.zig_lib_directory, |
| 6463 | .cache_mode = .whole, |
| 6464 | .parent_whole_cache = parent_whole_cache, |
| 6427 | 6465 | .self_exe_path = comp.self_exe_path, |
| 6428 | 6466 | .config = config, |
| 6429 | 6467 | .root_mod = root_mod, |
| 6430 | | .cache_mode = .whole, |
| 6431 | 6468 | .root_name = root_name, |
| 6432 | 6469 | .thread_pool = comp.thread_pool, |
| 6433 | 6470 | .libc_installation = comp.libc_installation, |