authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-12 18:28:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-12 18:28:07-07:00
log2551cf283f28e2cae27e461b51ea6df92d849fbb
tree8d6807f7cbb5dee468c2ef7f8efbd56d6ff44c5f
parent2f60a88308cf6358c06a6eaaff5ea61491873a0b

zig build: add --configure flag, change --fetch flag

--fetch is changed to mean: > Fetch all dependencies including lazy ones; exit without configuration --configure is introduced (replaces old `--fetch` semantics): > Exit after the configuration phase

2 files changed, 32 insertions(+), 35 deletions(-)

lib/compiler/Maker.zig+22-24
......@@ -149,7 +149,7 @@ const ErrorStyle = enum {
149149};
150150const MultilineErrors = enum { indent, newline, none };
151151const Summary = enum { all, new, failures, line, none };
152const PrintConfiguration = enum { none, zon, path, tree };
152const PrintConfiguration = enum { none, zon, path, tree, stop };
153153
154154const GeneratedFile = struct {
155155 data: ?[]const u8,
......@@ -300,7 +300,6 @@ pub fn main(init: process.Init.Minimal) !void {
300300 var cached_passthru_configure: std.ArrayList(u32) = .empty;
301301 var forks: std.ArrayList(Fork) = .empty;
302302 var system_pkg_dir_path: ?[]const u8 = null;
303 var fetch_only = false;
304303 var fetch_mode: Fetch.JobQueue.Mode = .needed;
305304 var debug_target: ?[]const u8 = null;
306305 var cache_poison: std.Build.Graph.CachePoison = .pure;
......@@ -387,12 +386,10 @@ pub fn main(init: process.Init.Minimal) !void {
387386 override_pkg_dir = nextArgOrFatal(args, &arg_i);
388387 } else if (mem.eql(u8, arg, "--print-tree")) {
389388 print_configuration = .tree;
389 } else if (mem.eql(u8, arg, "--configure")) {
390 print_configuration = .stop;
390391 } else if (mem.eql(u8, arg, "--fetch")) {
391 fetch_only = true;
392 } else if (mem.cutPrefix(u8, arg, "--fetch=")) |rest| {
393 fetch_only = true;
394 fetch_mode = stringToEnum(Fetch.JobQueue.Mode, rest) orelse
395 fatal("expected [needed|all] after \"--fetch=\", found {q}", .{rest});
392 fetch_mode = .all;
396393 } else if (mem.cutPrefix(u8, arg, "--fork=")) |rest| {
397394 try forks.append(arena, .init(rest));
398395 } else if (mem.eql(u8, arg, "--fork")) {
......@@ -619,7 +616,7 @@ pub fn main(init: process.Init.Minimal) !void {
619616 }
620617 }
621618
622 const early_exit_mode = fetch_only or help_menu or steps_menu or print_configuration != .none;
619 const early_exit_mode = fetch_mode == .all or help_menu or steps_menu or print_configuration != .none;
623620 const server_mode = !early_exit_mode and (watch_flag or webui_listen != null or fuzz != null or listen);
624621
625622 process.raiseFileDescriptorLimit();
......@@ -793,7 +790,6 @@ pub fn main(init: process.Init.Minimal) !void {
793790 .parent_progress_node = main_progress_node,
794791 .fetch_mode = fetch_mode,
795792 .system_pkg_dir_path = system_pkg_dir_path,
796 .fetch_only = fetch_only,
797793 .print_configuration = print_configuration,
798794 .forks = forks.items,
799795 .src_files = &configure_source_files,
......@@ -822,6 +818,7 @@ pub fn main(init: process.Init.Minimal) !void {
822818 },
823819 .path => unreachable,
824820 .tree => unreachable,
821 .stop => return cleanExit(io, &scanned_config),
825822 }
826823
827824 var maker: Maker = .{
......@@ -1134,7 +1131,6 @@ const ConfigureOptions = struct {
11341131 parent_progress_node: std.Progress.Node,
11351132 fetch_mode: Fetch.JobQueue.Mode,
11361133 system_pkg_dir_path: ?[]const u8,
1137 fetch_only: bool,
11381134 print_configuration: PrintConfiguration,
11391135 forks: []Fork,
11401136 src_files: *Cache.Manifest.SelfContainedFiles,
......@@ -1382,20 +1378,22 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
13821378 return error.FailedButCacheIntact;
13831379 }
13841380
1385 if (options.fetch_only or options.print_configuration == .tree) {
1381 if (options.fetch_mode == .all) {
13861382 _ = io.lockStderr(&.{}, .no_color) catch {};
1387 if (options.print_configuration == .tree) {
1388 const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map);
1389 const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map);
1390 printPkgTree(.{
1391 .writer = initStdoutWriter(io),
1392 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
1393 }, arena, &job_queue, &fetch) catch |err| switch (err) {
1394 error.WriteFailed => return stdout_writer_allocation.err.?,
1395 else => |e| return e,
1396 };
1397 try stdout_writer_allocation.flush();
1398 }
1383 process.exit(0);
1384 }
1385
1386 if (options.print_configuration == .tree) {
1387 const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map);
1388 const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map);
1389 printPkgTree(.{
1390 .writer = initStdoutWriter(io),
1391 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
1392 }, arena, &job_queue, &fetch) catch |err| switch (err) {
1393 error.WriteFailed => return stdout_writer_allocation.err.?,
1394 else => |e| return e,
1395 };
1396 try stdout_writer_allocation.flush();
13991397 process.exit(0);
14001398 }
14011399
......@@ -1677,7 +1675,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
16771675 _ = io.lockStderr(&.{}, .no_color) catch {};
16781676 process.exit(0);
16791677 },
1680 .none, .zon => {},
1678 .none, .zon, .stop => {},
16811679 .tree => unreachable,
16821680 }
16831681
lib/compiler/Maker/ScannedConfig.zig+10-11
......@@ -353,8 +353,8 @@ const general_usage =
353353 \\ --error-style [style] Control how build errors are printed
354354 \\ verbose (Default) Report errors with full context
355355 \\ minimal Report errors after summary, excluding context like command lines
356 \\ verbose_clear Like 'verbose', but clear the terminal at the start of each update
357 \\ minimal_clear Like 'minimal', but clear the terminal at the start of each update
356 \\ verbose_clear Like "verbose", but clear the terminal at the start of each update
357 \\ minimal_clear Like "minimal", but clear the terminal at the start of each update
358358 \\ --multiline-errors [style] Control how multi-line error messages are printed
359359 \\ indent (Default) Indent non-initial lines to align with initial line
360360 \\ newline Include a leading newline so that the error message is on its own lines
......@@ -375,22 +375,21 @@ const general_usage =
375375 \\ --webui[=ip] Enable the web interface on the given IP address
376376 \\ --fuzz[=limit] Continuously search for unit test failures with an optional
377377 \\ limit to the max number of iterations. The argument supports
378 \\ an optional 'K', 'M', or 'G' suffix (e.g. '10K'). Implies
379 \\ '--webui' when no limit is specified.
380 \\ --listen=- Enable the build server protocol on stdio
378 \\ an optional 'K', 'M', or 'G' suffix (e.g. "10K"). Implies
379 \\ "--webui" when no limit is specified.
381380 \\ --time-report Force full rebuild and provide detailed information on
382 \\ compilation time of Zig source code (implies '--webui')
381 \\ compilation time of Zig source code (implies "--webui")
383382 \\ -fincremental Enable incremental compilation
384383 \\ -fno-incremental Disable incremental compilation
384 \\ --configure Exit after the configuration phase
385385 \\
386386 \\Package Management Options:
387 \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit
388 \\ needed (Default) Lazy dependencies are fetched as needed
389 \\ all Lazy dependencies are always fetched
387 \\ --fetch Fetch all dependencies including lazy ones; exit without configuration
390388 \\ --fork=[path], --fork [path] Override one or more projects from dependency tree
391389 \\ --print-tree Write current state of package dependencies to stdout
392390 \\
393391 \\Advanced Options:
392 \\ --listen=- Enable the build server protocol on stdio
394393 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
395394 \\ -fno-reference-trace Disable reference trace
396395 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts
......@@ -405,8 +404,8 @@ const general_usage =
405404 \\ poisoned Don't cache the configuration
406405 \\ disallowed Panics when cache would be poisoned
407406 \\ ignored A little poison never hurt anybody
408 \\ --print-configuration Render configuration as .zon to stdout and exit
409 \\ --print-configuration-path Print the path to the binary configuration file to stdout
407 \\ --print-configuration Render configuration as .zon to stdout. Implies "--configure"
408 \\ --print-configuration-path Print the path to the binary configuration file to stdout.
410409 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
411410 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
412411 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)