authorgravatar for me@falsepattern.comFalsePattern <me@falsepattern.com> 2026-05-28 18:58:57+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-29 19:12:32+02:00
logfee88b30d2ea1d9b8caa17c56869d598951e0c80
treef16fc5a5aaf39044cf3ebdef70dd4771f2013208
parentf3ad12b5f1e2d76d157928d9bd4b5926b1bd015f

zig build: add CLI argument for printing the configuration cache file path


2 files changed, 12 insertions(+), 2 deletions(-)

lib/compiler/Maker/ScannedConfig.zig+1
...@@ -350,6 +350,7 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {...@@ -350,6 +350,7 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
350 \\ disallowed Panics when cache would be poisoned350 \\ disallowed Panics when cache would be poisoned
351 \\ ignored A little poison never hurt anybody351 \\ ignored A little poison never hurt anybody
352 \\ --print-configuration Render configuration as .zon to stdout352 \\ --print-configuration Render configuration as .zon to stdout
353 \\ --print-configuration-path Print the path to the binary configuration file to stdout
353 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries354 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
354 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)355 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
355 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)356 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
src/main.zig+11-2
...@@ -4951,6 +4951,7 @@ fn cmdBuild(...@@ -4951,6 +4951,7 @@ fn cmdBuild(
4951 var debug_target: ?[]const u8 = null;4951 var debug_target: ?[]const u8 = null;
4952 var debug_libc_paths_file: ?[]const u8 = null;4952 var debug_libc_paths_file: ?[]const u8 = null;
4953 var cache_poison: std.Build.Graph.CachePoison = .pure;4953 var cache_poison: std.Build.Graph.CachePoison = .pure;
4954 var print_configuration_path: bool = false;
49544955
4955 const self_exe_path = try process.executablePathAlloc(io, arena);4956 const self_exe_path = try process.executablePathAlloc(io, arena);
4956 const default_seed = try std.fmt.allocPrint(arena, "0x{x}", .{randInt(io, u32)});4957 const default_seed = try std.fmt.allocPrint(arena, "0x{x}", .{randInt(io, u32)});
...@@ -5069,6 +5070,9 @@ fn cmdBuild(...@@ -5069,6 +5070,9 @@ fn cmdBuild(
5069 i += 1;5070 i += 1;
5070 override_global_cache_dir = args[i];5071 override_global_cache_dir = args[i];
5071 continue;5072 continue;
5073 } else if (mem.eql(u8, arg, "--print-configuration-path")) {
5074 print_configuration_path = true;
5075 continue;
5072 } else if (mem.eql(u8, arg, "-freference-trace")) {5076 } else if (mem.eql(u8, arg, "-freference-trace")) {
5073 reference_trace = 256;5077 reference_trace = 256;
5074 } else if (mem.eql(u8, arg, "--fetch")) {5078 } else if (mem.eql(u8, arg, "--fetch")) {
...@@ -5266,7 +5270,7 @@ fn cmdBuild(...@@ -5266,7 +5270,7 @@ fn cmdBuild(
5266 };5270 };
52675271
5268 // Kick off an optimized compilation of the make runner.5272 // Kick off an optimized compilation of the make runner.
5269 var make_runner_task = io.async(compileMakeRunner, .{ gpa, arena, io, .{5273 var make_runner_task = if (print_configuration_path) undefined else io.async(compileMakeRunner, .{ gpa, arena, io, .{
5270 .dirs = .{5274 .dirs = .{
5271 .cwd = dirs.cwd,5275 .cwd = dirs.cwd,
5272 .zig_lib = dirs.zig_lib,5276 .zig_lib = dirs.zig_lib,
...@@ -5283,7 +5287,7 @@ fn cmdBuild(...@@ -5283,7 +5287,7 @@ fn cmdBuild(
5283 .reference_trace = reference_trace,5287 .reference_trace = reference_trace,
5284 .optimize_mode = maker_optimize_mode,5288 .optimize_mode = maker_optimize_mode,
5285 } });5289 } });
5286 defer _ = make_runner_task.cancel(io) catch {};5290 defer _ = if (!print_configuration_path) make_runner_task.cancel(io) catch {};
52875291
5288 const pkg_root: Path = if (override_pkg_dir) |p|5292 const pkg_root: Path = if (override_pkg_dir) |p|
5289 .initCwd(p)5293 .initCwd(p)
...@@ -5744,6 +5748,11 @@ fn cmdBuild(...@@ -5744,6 +5748,11 @@ fn cmdBuild(
5744 var configuration_lock = if (!poisoned) config_man.toOwnedLock() else null;5748 var configuration_lock = if (!poisoned) config_man.toOwnedLock() else null;
5745 defer if (configuration_lock) |*l| l.release(io);5749 defer if (configuration_lock) |*l| l.release(io);
57465750
5751 if (print_configuration_path) {
5752 var stdout_writer = Io.File.stdout().writerStreaming(io, &.{});
5753 configuration_path.format(&stdout_writer.interface) catch fatal("failed printing cache file path: {t}", .{stdout_writer.err.?});
5754 return cleanExit(io);
5755 }
5747 const make_runner = make_runner_task.await(io) catch |err| fatal("failed compiling maker: {t}", .{err});5756 const make_runner = make_runner_task.await(io) catch |err| fatal("failed compiling maker: {t}", .{err});
57485757
5749 make_argv.items[0] = try make_runner.exe_path.toString(arena);5758 make_argv.items[0] = try make_runner.exe_path.toString(arena);