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 @@...@@ -1,4 +1,5 @@
1const Maker = @This();1const Maker = @This();
2
2const builtin = @import("builtin");3const builtin = @import("builtin");
3const native_os = builtin.os.tag;4const native_os = builtin.os.tag;
45
...@@ -263,10 +264,17 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -263,10 +264,17 @@ pub fn main(init: process.Init.Minimal) !void {
263 configure_argv.appendAssumeCapacity(arg); // Intentionally "--system" only; not the path.264 configure_argv.appendAssumeCapacity(arg); // Intentionally "--system" only; not the path.
264 } else if (mem.cutPrefix(u8, arg, "--color=")) |rest| {265 } else if (mem.cutPrefix(u8, arg, "--color=")) |rest| {
265 color = stringToEnum(Color, rest) orelse266 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
268 try cached_passthru_configure.append(arena, @intCast(configure_argv.items.len));269 try cached_passthru_configure.append(arena, @intCast(configure_argv.items.len));
269 configure_argv.appendAssumeCapacity(arg);270 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}));
270 } else if (mem.eql(u8, arg, "--cache-poison")) {278 } else if (mem.eql(u8, arg, "--cache-poison")) {
271 cache_poison = .poisoned;279 cache_poison = .poisoned;
272 configure_argv.appendAssumeCapacity("--cache-poison=poisoned");280 configure_argv.appendAssumeCapacity("--cache-poison=poisoned");
...@@ -280,12 +288,16 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -280,12 +288,16 @@ pub fn main(init: process.Init.Minimal) !void {
280 // Intentionally is added both to make and configure but288 // Intentionally is added both to make and configure but
281 // does not go into the cache hash.289 // does not go into the cache hash.
282 configure_argv.appendAssumeCapacity(arg);290 configure_argv.appendAssumeCapacity(arg);
291 graph.verbose = true;
283 } else if (mem.eql(u8, arg, "--search-prefix")) {292 } else if (mem.eql(u8, arg, "--search-prefix")) {
284 const prefix = nextArgOrFatal(args, &arg_i);293 const prefix = nextArgOrFatal(args, &arg_i);
294
285 // This argument is cache poisonous: it does not go into295 // This argument is cache poisonous: it does not go into
286 // the cache and configurer must set the poison bit when296 // the cache and configurer must set the poison bit when
287 // choosing to observe it.297 // choosing to observe it.
288 configure_argv.addManyAsArrayAssumeCapacity(2).* = .{ arg, prefix };298 configure_argv.addManyAsArrayAssumeCapacity(2).* = .{ arg, prefix };
299
300 try graph.search_prefixes.append(arena, prefix);
289 } else if (mem.eql(u8, arg, "--cache-dir")) {301 } else if (mem.eql(u8, arg, "--cache-dir")) {
290 override_local_cache_dir = nextArgOrFatal(args, &arg_i);302 override_local_cache_dir = nextArgOrFatal(args, &arg_i);
291 } else if (mem.eql(u8, arg, "--pkg-dir")) {303 } else if (mem.eql(u8, arg, "--pkg-dir")) {
...@@ -361,18 +373,8 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -361,18 +373,8 @@ pub fn main(init: process.Init.Minimal) !void {
361 .{ timeout_str, num_str, err },373 .{ timeout_str, num_str, err },
362 );374 );
363 test_timeout_ns = std.math.lossyCast(u64, unit_factor * num_parsed);375 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));
366 } else if (mem.eql(u8, arg, "--libc")) {376 } else if (mem.eql(u8, arg, "--libc")) {
367 graph.libc_file = nextArgOrFatal(args, &arg_i);377 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 };
376 } else if (mem.eql(u8, arg, "--error-style")) {378 } else if (mem.eql(u8, arg, "--error-style")) {
377 const next_arg = nextArg(args, &arg_i) orelse379 const next_arg = nextArg(args, &arg_i) orelse
378 fatalWithHint("expected style after {q}", .{arg});380 fatalWithHint("expected style after {q}", .{arg});
...@@ -429,15 +431,13 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -429,15 +431,13 @@ pub fn main(init: process.Init.Minimal) !void {
429 } else if (mem.eql(u8, arg, "--debug-rt")) {431 } else if (mem.eql(u8, arg, "--debug-rt")) {
430 graph.debug_compiler_runtime_libs = .Debug;432 graph.debug_compiler_runtime_libs = .Debug;
431 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {433 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {
432 graph.debug_compiler_runtime_libs = stringToEnum(std.builtin.OptimizeMode, rest) orelse434 graph.debug_compiler_runtime_libs = stringToEnum(std.lang.OptimizeMode, rest) orelse
433 fatal("unrecognized optimization mode: {s}", .{rest});435 fatal("unrecognized optimization mode: {s}", .{rest});
434 } else if (is_debug_mode and mem.eql(u8, arg, "--debug-maker-leaks")) {436 } else if (is_debug_mode and mem.eql(u8, arg, "--debug-maker-leaks")) {
435 debug_maker_leaks = true;437 debug_maker_leaks = true;
436 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {438 } else if (mem.eql(u8, arg, "--libc-runtimes") or mem.eql(u8, arg, "--glibc-runtimes")) {
437 // --glibc-runtimes was the old name of the flag; kept for compatibility for now.439 // --glibc-runtimes was the old name of the flag; kept for compatibility for now.
438 graph.libc_runtimes_dir = nextArgOrFatal(args, &arg_i);440 graph.libc_runtimes_dir = nextArgOrFatal(args, &arg_i);
439 } else if (mem.eql(u8, arg, "--verbose")) {
440 graph.verbose = true;
441 } else if (mem.eql(u8, arg, "--verbose-air")) {441 } else if (mem.eql(u8, arg, "--verbose-air")) {
442 graph.verbose_air = true;442 graph.verbose_air = true;
443 } else if (mem.eql(u8, arg, "--verbose-cc")) {443 } 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 {...@@ -342,7 +342,6 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
342 \\ --build-file [file] Override path to build.zig342 \\ --build-file [file] Override path to build.zig
343 \\ --cache-dir [path] Override path to local Zig cache directory343 \\ --cache-dir [path] Override path to local Zig cache directory
344 \\ --global-cache-dir [path] Override path to global Zig cache directory344 \\ --global-cache-dir [path] Override path to global Zig cache directory
345 \\ --zig-lib-dir [arg] Override path to Zig lib directory
346 \\ --seed [integer] For shuffling dependency traversal order (default: random)345 \\ --seed [integer] For shuffling dependency traversal order (default: random)
347 \\ --cache-poison[=mode] Override configuration caching behavior346 \\ --cache-poison[=mode] Override configuration caching behavior
348 \\ pure (default) Avoid false positive cache hits347 \\ pure (default) Avoid false positive cache hits
...@@ -360,7 +359,6 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {...@@ -360,7 +359,6 @@ pub fn printUsage(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void {
360 \\ none (default) No build ID359 \\ none (default) No build ID
361 \\ --debug-log [scope] Enable debugging the compiler360 \\ --debug-log [scope] Enable debugging the compiler
362 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered361 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
363 \\ --maker-opt=[mode] Change maker executable optimization mode (default: ReleaseSafe)
364 \\ --verbose-link Enable compiler debug output for linking362 \\ --verbose-link Enable compiler debug output for linking
365 \\ --verbose-air Enable compiler debug output for Zig AIR363 \\ --verbose-air Enable compiler debug output for Zig AIR
366 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR364 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR