zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fee88b30d2ea1d9b8caa17c56869d598951e0c80 (tree)
parent f3ad12b5f1e2d76d157928d9bd4b5926b1bd015f
Author: FalsePattern <me@falsepattern.com>
Date:   Thu, 28 May 2026 18:58:57 +0200

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

Diffstat:
Mlib/compiler/Maker/ScannedConfig.zig | 1+
Msrc/main.zig | 13+++++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/compiler/Maker/ScannedConfig.zig b/lib/compiler/Maker/ScannedConfig.zig @@ -350,6 +350,7 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void { \\ disallowed Panics when cache would be poisoned \\ ignored A little poison never hurt anybody \\ --print-configuration Render configuration as .zon to stdout + \\ --print-configuration-path Print the path to the binary configuration file to stdout \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM) \\ sha1, tree 20-byte cryptographic hash (ELF, WASM) diff --git a/src/main.zig b/src/main.zig @@ -4951,6 +4951,7 @@ fn cmdBuild( var debug_target: ?[]const u8 = null; var debug_libc_paths_file: ?[]const u8 = null; var cache_poison: std.Build.Graph.CachePoison = .pure; + var print_configuration_path: bool = false; const self_exe_path = try process.executablePathAlloc(io, arena); const default_seed = try std.fmt.allocPrint(arena, "0x{x}", .{randInt(io, u32)}); @@ -5069,6 +5070,9 @@ fn cmdBuild( i += 1; override_global_cache_dir = args[i]; continue; + } else if (mem.eql(u8, arg, "--print-configuration-path")) { + print_configuration_path = true; + continue; } else if (mem.eql(u8, arg, "-freference-trace")) { reference_trace = 256; } else if (mem.eql(u8, arg, "--fetch")) { @@ -5266,7 +5270,7 @@ fn cmdBuild( }; // Kick off an optimized compilation of the make runner. - var make_runner_task = io.async(compileMakeRunner, .{ gpa, arena, io, .{ + var make_runner_task = if (print_configuration_path) undefined else io.async(compileMakeRunner, .{ gpa, arena, io, .{ .dirs = .{ .cwd = dirs.cwd, .zig_lib = dirs.zig_lib, @@ -5283,7 +5287,7 @@ fn cmdBuild( .reference_trace = reference_trace, .optimize_mode = maker_optimize_mode, } }); - defer _ = make_runner_task.cancel(io) catch {}; + defer _ = if (!print_configuration_path) make_runner_task.cancel(io) catch {}; const pkg_root: Path = if (override_pkg_dir) |p| .initCwd(p) @@ -5744,6 +5748,11 @@ fn cmdBuild( var configuration_lock = if (!poisoned) config_man.toOwnedLock() else null; defer if (configuration_lock) |*l| l.release(io); + if (print_configuration_path) { + var stdout_writer = Io.File.stdout().writerStreaming(io, &.{}); + configuration_path.format(&stdout_writer.interface) catch fatal("failed printing cache file path: {t}", .{stdout_writer.err.?}); + return cleanExit(io); + } const make_runner = make_runner_task.await(io) catch |err| fatal("failed compiling maker: {t}", .{err}); make_argv.items[0] = try make_runner.exe_path.toString(arena);