authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-24 16:45:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:20-07:00
log46bdb35420efc111a38bba19f9bd714ad41a759f
tree2f8893a20d4ea2e80400a2ee682abc1f036fa5ad
parent7b4f0ef133a5b03e0ec6ea73b1681ed3ac21a31e

Maker: fix CLI flag parsing

when combining two processes into one, the same flags were parsed multiple times. This caused some of the logic for --verbose, --color, and --search-prefixes to be incorrectly dead.

2 files changed, 14 insertions(+), 16 deletions(-)

lib/compiler/Maker.zig+14-14
......@@ -1,4 +1,5 @@
11const Maker = @This();
2
23const builtin = @import("builtin");
34const native_os = builtin.os.tag;
45
......@@ -263,10 +264,17 @@ pub fn main(init: process.Init.Minimal) !void {
263264 configure_argv.appendAssumeCapacity(arg); // Intentionally "--system" only; not the path.
264265 } else if (mem.cutPrefix(u8, arg, "--color=")) |rest| {
265266 color = stringToEnum(Color, rest) orelse
266 fatal("expected --color=[auto|on|off]; found {q}", .{arg});
267 fatalWithHint("expected --color=[auto|on|off]; found {q}", .{arg});
267268
268269 try cached_passthru_configure.append(arena, @intCast(configure_argv.items.len));
269270 configure_argv.appendAssumeCapacity(arg);
271 } else if (mem.eql(u8, arg, "--color")) {
272 const next_arg = nextArgOrFatal(args, &arg_i);
273 color = stringToEnum(Color, next_arg) orelse
274 fatalWithHint("expected [auto|on|off] found {q}", .{next_arg});
275
276 try cached_passthru_configure.append(arena, @intCast(configure_argv.items.len));
277 configure_argv.appendAssumeCapacity(try allocPrint(arena, "--color={t}", .{color}));
270278 } else if (mem.eql(u8, arg, "--cache-poison")) {
271279 cache_poison = .poisoned;
272280 configure_argv.appendAssumeCapacity("--cache-poison=poisoned");
......@@ -280,12 +288,16 @@ pub fn main(init: process.Init.Minimal) !void {
280288 // Intentionally is added both to make and configure but
281289 // does not go into the cache hash.
282290 configure_argv.appendAssumeCapacity(arg);
291 graph.verbose = true;
283292 } else if (mem.eql(u8, arg, "--search-prefix")) {
284293 const prefix = nextArgOrFatal(args, &arg_i);
294
285295 // This argument is cache poisonous: it does not go into
286296 // the cache and configurer must set the poison bit when
287297 // choosing to observe it.
288298 configure_argv.addManyAsArrayAssumeCapacity(2).* = .{ arg, prefix };
299
300 try graph.search_prefixes.append(arena, prefix);
289301 } else if (mem.eql(u8, arg, "--cache-dir")) {
290302 override_local_cache_dir = nextArgOrFatal(args, &arg_i);
291303 } else if (mem.eql(u8, arg, "--pkg-dir")) {
......@@ -361,18 +373,8 @@ pub fn main(init: process.Init.Minimal) !void {
361373 .{ timeout_str, num_str, err },
362374 );
363375 test_timeout_ns = std.math.lossyCast(u64, unit_factor * num_parsed);
364 } else if (mem.eql(u8, arg, "--search-prefix")) {
365 try graph.search_prefixes.append(arena, nextArgOrFatal(args, &arg_i));
366376 } else if (mem.eql(u8, arg, "--libc")) {
367377 graph.libc_file = nextArgOrFatal(args, &arg_i);
368 } else if (mem.eql(u8, arg, "--color")) {
369 const next_arg = nextArg(args, &arg_i) orelse
370 fatalWithHint("expected [auto|on|off] after {q}", .{arg});
371 color = stringToEnum(Color, next_arg) orelse {
372 fatalWithHint("expected [auto|on|off] after {q}, found {q}", .{
373 arg, next_arg,
374 });
375 };
376378 } else if (mem.eql(u8, arg, "--error-style")) {
377379 const next_arg = nextArg(args, &arg_i) orelse
378380 fatalWithHint("expected style after {q}", .{arg});
......@@ -429,15 +431,13 @@ pub fn main(init: process.Init.Minimal) !void {
429431 } else if (mem.eql(u8, arg, "--debug-rt")) {
430432 graph.debug_compiler_runtime_libs = .Debug;
431433 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {
432 graph.debug_compiler_runtime_libs = stringToEnum(std.builtin.OptimizeMode, rest) orelse
434 graph.debug_compiler_runtime_libs = stringToEnum(std.lang.OptimizeMode, rest) orelse
433435 fatal("unrecognized optimization mode: {s}", .{rest});
434436 } else if (is_debug_mode and mem.eql(u8, arg, "--debug-maker-leaks")) {
435437 debug_maker_leaks = true;
436438 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {
437439 // --glibc-runtimes was the old name of the flag; kept for compatibility for now.
438440 graph.libc_runtimes_dir = nextArgOrFatal(args, &arg_i);
439 } else if (mem.eql(u8, arg, "--verbose")) {
440 graph.verbose = true;
441441 } else if (mem.eql(u8, arg, "--verbose-air")) {
442442 graph.verbose_air = true;
443443 } else if (mem.eql(u8, arg, "--verbose-cc")) {
lib/compiler/Maker/ScannedConfig.zig-2
......@@ -342,7 +342,6 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
342342 \\ --build-file [file] Override path to build.zig
343343 \\ --cache-dir [path] Override path to local Zig cache directory
344344 \\ --global-cache-dir [path] Override path to global Zig cache directory
345 \\ --zig-lib-dir [arg] Override path to Zig lib directory
346345 \\ --seed [integer] For shuffling dependency traversal order (default: random)
347346 \\ --cache-poison[=mode] Override configuration caching behavior
348347 \\ pure (default) Avoid false positive cache hits
......@@ -360,7 +359,6 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
360359 \\ none (default) No build ID
361360 \\ --debug-log [scope] Enable debugging the compiler
362361 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
363 \\ --maker-opt=[mode] Change maker executable optimization mode (default: ReleaseSafe)
364362 \\ --verbose-link Enable compiler debug output for linking
365363 \\ --verbose-air Enable compiler debug output for Zig AIR
366364 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR