| ... | ... | @@ -283,11 +283,11 @@ pub fn main(init: process.Init.Minimal) !void { |
| 283 | 283 | cache_poison = .poisoned; |
| 284 | 284 | configure_argv.appendAssumeCapacity("--cache-poison=poisoned"); |
| 285 | 285 | } else if (mem.cutPrefix(u8, arg, "--cache-poison=")) |rest| { |
| 286 | | // Allow the configurer process to report parse failure. |
| 287 | | if (stringToEnum(std.Build.Graph.CachePoison, rest)) |poison| { |
| 288 | | cache_poison = poison; |
| 289 | | } |
| 290 | | configure_argv.appendAssumeCapacity(arg); |
| 286 | // We have to report parse failure here otherwise we would |
| 287 | // potentially get false positive cache hits for misspellings. |
| 288 | cache_poison = stringToEnum(std.Build.Graph.CachePoison, rest) orelse |
| 289 | fatalWithHint("expected --cache-poison=[pure|poisoned|disallowed|ignored]; found: {s}", .{arg}); |
| 290 | if (cache_poison != .pure) configure_argv.appendAssumeCapacity(arg); |
| 291 | 291 | } else if (mem.eql(u8, arg, "--verbose")) { |
| 292 | 292 | // Intentionally is added both to make and configure but |
| 293 | 293 | // does not go into the cache hash. |
| ... | ... | @@ -316,6 +316,8 @@ pub fn main(init: process.Init.Minimal) !void { |
| 316 | 316 | try forks.append(arena, .init(rest)); |
| 317 | 317 | } else if (mem.eql(u8, arg, "--fork")) { |
| 318 | 318 | try forks.append(arena, .init(nextArgOrFatal(args, &arg_i))); |
| 319 | } else if (mem.startsWith(u8, arg, "--zig-lib=")) { |
| 320 | fatal("--zig-lib= argument is special and must be first", .{}); |
| 319 | 321 | } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 320 | 322 | help_menu = true; |
| 321 | 323 | } else if (mem.eql(u8, arg, "-l") or mem.eql(u8, arg, "--list-steps")) { |
| ... | ... | @@ -981,27 +983,35 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 981 | 983 | // This loop is re-evaluated when the build script exits with an indication that it |
| 982 | 984 | // could not continue due to missing lazy dependencies. |
| 983 | 985 | const configuration_path: Path, var configuration_lock: ?Cache.Lock = cp: while (true) { |
| 986 | build_mod.deps.clearRetainingCapacity(); |
| 987 | deps_mod.deps.clearRetainingCapacity(); |
| 988 | |
| 984 | 989 | // Cache lookup for configure options. If we get a match, we can skip |
| 985 | 990 | // execution of the configure script. If not, we get the file path to pass |
| 986 | 991 | // to the configure process. |
| 987 | 992 | // |
| 988 | 993 | // In the hot path, we only check this cache, which means that also |
| 989 | 994 | // configure source files need to go in here. |
| 990 | | var config_man = graph.cache.obtain(); |
| 991 | | defer config_man.deinit(); |
| 995 | var config_man_allocation: Cache.Manifest = undefined; |
| 996 | const config_man: ?*Cache.Manifest = switch (options.cache_poison) { |
| 997 | .pure, .disallowed, .ignored => m: { |
| 998 | config_man_allocation = graph.cache.obtain(); |
| 992 | 999 | |
| 993 | | for (options.cached_passthru_configure) |i| |
| 994 | | config_man.hash.addBytes(configure_argv[i]); |
| 1000 | for (options.cached_passthru_configure) |i| |
| 1001 | config_man_allocation.hash.addBytes(configure_argv[i]); |
| 995 | 1002 | |
| 996 | | if (target_arch_os_abi) |triple| |
| 997 | | config_man.hash.addBytes(triple); |
| 1003 | if (target_arch_os_abi) |triple| |
| 1004 | config_man_allocation.hash.addBytes(triple); |
| 998 | 1005 | |
| 999 | | // Prevents a `zig build` from getting a false positive cache hit following |
| 1000 | | // a `zig build --cache-poison=ignored`. |
| 1001 | | config_man.hash.add(options.cache_poison == .ignored); |
| 1006 | // Prevents a `zig build` from getting a false positive cache hit following |
| 1007 | // a `zig build --cache-poison=ignored`. |
| 1008 | config_man_allocation.hash.add(options.cache_poison == .ignored); |
| 1002 | 1009 | |
| 1003 | | build_mod.deps.clearRetainingCapacity(); |
| 1004 | | deps_mod.deps.clearRetainingCapacity(); |
| 1010 | break :m &config_man_allocation; |
| 1011 | }, |
| 1012 | .poisoned => null, |
| 1013 | }; |
| 1014 | defer if (config_man) |man| man.deinit(); |
| 1005 | 1015 | |
| 1006 | 1016 | // We want to release all the locks before executing the child process, so we make a nice |
| 1007 | 1017 | // big block here to ensure the cleanup gets run when we extract out our argv. |
| ... | ... | @@ -1217,26 +1227,24 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1217 | 1227 | const compile_prog_node = options.parent_progress_node.start("Compile Configure Script", 0); |
| 1218 | 1228 | defer compile_prog_node.end(); |
| 1219 | 1229 | |
| 1220 | | switch (options.cache_poison) { |
| 1221 | | .pure, .disallowed, .ignored => if (try config_man.hit(compile_prog_node)) { |
| 1222 | | const digest = config_man.final(); |
| 1230 | if (config_man) |man| { |
| 1231 | if (try man.hit(compile_prog_node)) { |
| 1232 | const digest = man.final(); |
| 1223 | 1233 | break :cp .{ |
| 1224 | 1234 | .{ |
| 1225 | 1235 | .root_dir = graph.local_cache_root, |
| 1226 | 1236 | .sub_path = try arena.print("c/{s}", .{&digest}), |
| 1227 | 1237 | }, |
| 1228 | | config_man.toOwnedLock(), |
| 1238 | man.toOwnedLock(), |
| 1229 | 1239 | }; |
| 1230 | | }, |
| 1231 | | .poisoned => {}, // Don't bother checking for cache hit. |
| 1240 | } |
| 1232 | 1241 | } |
| 1233 | | |
| 1234 | 1242 | const configure_exe_path: Path = if (std.zig.buildExeSubprocess(gpa, io, .{ |
| 1235 | 1243 | .argv = build_configurer_argv.items, |
| 1236 | 1244 | .cache_root = graph.local_cache_root, |
| 1237 | 1245 | .root_name = configurer_exe_name, |
| 1238 | 1246 | .environ_map = &graph.environ_map, |
| 1239 | | .cache_manifest = &config_man, |
| 1247 | .cache_manifest = config_man, |
| 1240 | 1248 | .arch_os_abi = target_arch_os_abi, |
| 1241 | 1249 | .progress_node = compile_prog_node, |
| 1242 | 1250 | .skip_log_cmdline_on_compile_errors = !graph.verbose, |
| ... | ... | @@ -1318,20 +1326,21 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1318 | 1326 | continue :cp; |
| 1319 | 1327 | } |
| 1320 | 1328 | |
| 1321 | | for (configuration.path_deps) |path_dep| { |
| 1329 | if (config_man) |man| for (configuration.path_deps) |path_dep| { |
| 1322 | 1330 | switch (path_dep.flags.mode) { |
| 1323 | 1331 | .directory => {}, // TODO |
| 1324 | | .contents => try config_man.addPathPost(confPathDepToCachePath(graph, &configuration, path_dep)), |
| 1332 | .contents => try man.addPathPost(confPathDepToCachePath(graph, &configuration, path_dep)), |
| 1325 | 1333 | .metadata => {}, // TODO |
| 1326 | 1334 | } |
| 1327 | | } |
| 1335 | }; |
| 1328 | 1336 | |
| 1329 | 1337 | // If it is poisoned, there is no point in moving it to cached |
| 1330 | 1338 | // location. Just leave it in the tmp directory. |
| 1331 | 1339 | if (configuration.poisoned) { |
| 1332 | 1340 | break :cp .{ config_tmp_path, null }; |
| 1333 | 1341 | } else { |
| 1334 | | const digest = config_man.final(); |
| 1342 | const man = config_man.?; |
| 1343 | const digest = man.final(); |
| 1335 | 1344 | const final_path: Path = .{ |
| 1336 | 1345 | .root_dir = graph.local_cache_root, |
| 1337 | 1346 | .sub_path = try arena.print("c/{s}", .{&digest}), |
| ... | ... | @@ -1362,8 +1371,8 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1362 | 1371 | config_tmp_path, final_path, e, |
| 1363 | 1372 | }); |
| 1364 | 1373 | }; |
| 1365 | | config_man.writeManifest() catch |err| log.warn("failed to write cache manifest: {t}", .{err}); |
| 1366 | | break :cp .{ final_path, config_man.toOwnedLock() }; |
| 1374 | man.writeManifest() catch |err| log.warn("failed to write cache manifest: {t}", .{err}); |
| 1375 | break :cp .{ final_path, man.toOwnedLock() }; |
| 1367 | 1376 | } |
| 1368 | 1377 | }; |
| 1369 | 1378 | // Hang on to the configuration file lock until we finish loading the configuration file. |