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 {...@@ -149,7 +149,7 @@ const ErrorStyle = enum {
149};149};
150const MultilineErrors = enum { indent, newline, none };150const MultilineErrors = enum { indent, newline, none };
151const Summary = enum { all, new, failures, line, none };151const Summary = enum { all, new, failures, line, none };
152const PrintConfiguration = enum { none, zon, path, tree };152const PrintConfiguration = enum { none, zon, path, tree, stop };
153153
154const GeneratedFile = struct {154const GeneratedFile = struct {
155 data: ?[]const u8,155 data: ?[]const u8,
...@@ -300,7 +300,6 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -300,7 +300,6 @@ pub fn main(init: process.Init.Minimal) !void {
300 var cached_passthru_configure: std.ArrayList(u32) = .empty;300 var cached_passthru_configure: std.ArrayList(u32) = .empty;
301 var forks: std.ArrayList(Fork) = .empty;301 var forks: std.ArrayList(Fork) = .empty;
302 var system_pkg_dir_path: ?[]const u8 = null;302 var system_pkg_dir_path: ?[]const u8 = null;
303 var fetch_only = false;
304 var fetch_mode: Fetch.JobQueue.Mode = .needed;303 var fetch_mode: Fetch.JobQueue.Mode = .needed;
305 var debug_target: ?[]const u8 = null;304 var debug_target: ?[]const u8 = null;
306 var cache_poison: std.Build.Graph.CachePoison = .pure;305 var cache_poison: std.Build.Graph.CachePoison = .pure;
...@@ -387,12 +386,10 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -387,12 +386,10 @@ pub fn main(init: process.Init.Minimal) !void {
387 override_pkg_dir = nextArgOrFatal(args, &arg_i);386 override_pkg_dir = nextArgOrFatal(args, &arg_i);
388 } else if (mem.eql(u8, arg, "--print-tree")) {387 } else if (mem.eql(u8, arg, "--print-tree")) {
389 print_configuration = .tree;388 print_configuration = .tree;
389 } else if (mem.eql(u8, arg, "--configure")) {
390 print_configuration = .stop;
390 } else if (mem.eql(u8, arg, "--fetch")) {391 } else if (mem.eql(u8, arg, "--fetch")) {
391 fetch_only = true;392 fetch_mode = .all;
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});
396 } else if (mem.cutPrefix(u8, arg, "--fork=")) |rest| {393 } else if (mem.cutPrefix(u8, arg, "--fork=")) |rest| {
397 try forks.append(arena, .init(rest));394 try forks.append(arena, .init(rest));
398 } else if (mem.eql(u8, arg, "--fork")) {395 } else if (mem.eql(u8, arg, "--fork")) {
...@@ -619,7 +616,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -619,7 +616,7 @@ pub fn main(init: process.Init.Minimal) !void {
619 }616 }
620 }617 }
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;
623 const server_mode = !early_exit_mode and (watch_flag or webui_listen != null or fuzz != null or listen);620 const server_mode = !early_exit_mode and (watch_flag or webui_listen != null or fuzz != null or listen);
624621
625 process.raiseFileDescriptorLimit();622 process.raiseFileDescriptorLimit();
...@@ -793,7 +790,6 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -793,7 +790,6 @@ pub fn main(init: process.Init.Minimal) !void {
793 .parent_progress_node = main_progress_node,790 .parent_progress_node = main_progress_node,
794 .fetch_mode = fetch_mode,791 .fetch_mode = fetch_mode,
795 .system_pkg_dir_path = system_pkg_dir_path,792 .system_pkg_dir_path = system_pkg_dir_path,
796 .fetch_only = fetch_only,
797 .print_configuration = print_configuration,793 .print_configuration = print_configuration,
798 .forks = forks.items,794 .forks = forks.items,
799 .src_files = &configure_source_files,795 .src_files = &configure_source_files,
...@@ -822,6 +818,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -822,6 +818,7 @@ pub fn main(init: process.Init.Minimal) !void {
822 },818 },
823 .path => unreachable,819 .path => unreachable,
824 .tree => unreachable,820 .tree => unreachable,
821 .stop => return cleanExit(io, &scanned_config),
825 }822 }
826823
827 var maker: Maker = .{824 var maker: Maker = .{
...@@ -1134,7 +1131,6 @@ const ConfigureOptions = struct {...@@ -1134,7 +1131,6 @@ const ConfigureOptions = struct {
1134 parent_progress_node: std.Progress.Node,1131 parent_progress_node: std.Progress.Node,
1135 fetch_mode: Fetch.JobQueue.Mode,1132 fetch_mode: Fetch.JobQueue.Mode,
1136 system_pkg_dir_path: ?[]const u8,1133 system_pkg_dir_path: ?[]const u8,
1137 fetch_only: bool,
1138 print_configuration: PrintConfiguration,1134 print_configuration: PrintConfiguration,
1139 forks: []Fork,1135 forks: []Fork,
1140 src_files: *Cache.Manifest.SelfContainedFiles,1136 src_files: *Cache.Manifest.SelfContainedFiles,
...@@ -1382,20 +1378,22 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1382,20 +1378,22 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1382 return error.FailedButCacheIntact;1378 return error.FailedButCacheIntact;
1383 }1379 }
13841380
1385 if (options.fetch_only or options.print_configuration == .tree) {1381 if (options.fetch_mode == .all) {
1386 _ = io.lockStderr(&.{}, .no_color) catch {};1382 _ = io.lockStderr(&.{}, .no_color) catch {};
1387 if (options.print_configuration == .tree) {1383 process.exit(0);
1388 const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map);1384 }
1389 const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map);1385
1390 printPkgTree(.{1386 if (options.print_configuration == .tree) {
1391 .writer = initStdoutWriter(io),1387 const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map);
1392 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),1388 const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map);
1393 }, arena, &job_queue, &fetch) catch |err| switch (err) {1389 printPkgTree(.{
1394 error.WriteFailed => return stdout_writer_allocation.err.?,1390 .writer = initStdoutWriter(io),
1395 else => |e| return e,1391 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
1396 };1392 }, arena, &job_queue, &fetch) catch |err| switch (err) {
1397 try stdout_writer_allocation.flush();1393 error.WriteFailed => return stdout_writer_allocation.err.?,
1398 }1394 else => |e| return e,
1395 };
1396 try stdout_writer_allocation.flush();
1399 process.exit(0);1397 process.exit(0);
1400 }1398 }
14011399
...@@ -1677,7 +1675,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1677,7 +1675,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1677 _ = io.lockStderr(&.{}, .no_color) catch {};1675 _ = io.lockStderr(&.{}, .no_color) catch {};
1678 process.exit(0);1676 process.exit(0);
1679 },1677 },
1680 .none, .zon => {},1678 .none, .zon, .stop => {},
1681 .tree => unreachable,1679 .tree => unreachable,
1682 }1680 }
16831681
lib/compiler/Maker/ScannedConfig.zig+10-11
...@@ -353,8 +353,8 @@ const general_usage =...@@ -353,8 +353,8 @@ const general_usage =
353 \\ --error-style [style] Control how build errors are printed353 \\ --error-style [style] Control how build errors are printed
354 \\ verbose (Default) Report errors with full context354 \\ verbose (Default) Report errors with full context
355 \\ minimal Report errors after summary, excluding context like command lines355 \\ minimal Report errors after summary, excluding context like command lines
356 \\ verbose_clear Like 'verbose', but clear the terminal at the start of each update356 \\ 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 update357 \\ minimal_clear Like "minimal", but clear the terminal at the start of each update
358 \\ --multiline-errors [style] Control how multi-line error messages are printed358 \\ --multiline-errors [style] Control how multi-line error messages are printed
359 \\ indent (Default) Indent non-initial lines to align with initial line359 \\ indent (Default) Indent non-initial lines to align with initial line
360 \\ newline Include a leading newline so that the error message is on its own lines360 \\ newline Include a leading newline so that the error message is on its own lines
...@@ -375,22 +375,21 @@ const general_usage =...@@ -375,22 +375,21 @@ const general_usage =
375 \\ --webui[=ip] Enable the web interface on the given IP address375 \\ --webui[=ip] Enable the web interface on the given IP address
376 \\ --fuzz[=limit] Continuously search for unit test failures with an optional 376 \\ --fuzz[=limit] Continuously search for unit test failures with an optional
377 \\ limit to the max number of iterations. The argument supports377 \\ limit to the max number of iterations. The argument supports
378 \\ an optional 'K', 'M', or 'G' suffix (e.g. '10K'). Implies378 \\ an optional 'K', 'M', or 'G' suffix (e.g. "10K"). Implies
379 \\ '--webui' when no limit is specified.379 \\ "--webui" when no limit is specified.
380 \\ --listen=- Enable the build server protocol on stdio
381 \\ --time-report Force full rebuild and provide detailed information on380 \\ --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")
383 \\ -fincremental Enable incremental compilation382 \\ -fincremental Enable incremental compilation
384 \\ -fno-incremental Disable incremental compilation383 \\ -fno-incremental Disable incremental compilation
384 \\ --configure Exit after the configuration phase
385 \\385 \\
386 \\Package Management Options:386 \\Package Management Options:
387 \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit387 \\ --fetch Fetch all dependencies including lazy ones; exit without configuration
388 \\ needed (Default) Lazy dependencies are fetched as needed
389 \\ all Lazy dependencies are always fetched
390 \\ --fork=[path], --fork [path] Override one or more projects from dependency tree388 \\ --fork=[path], --fork [path] Override one or more projects from dependency tree
391 \\ --print-tree Write current state of package dependencies to stdout389 \\ --print-tree Write current state of package dependencies to stdout
392 \\390 \\
393 \\Advanced Options:391 \\Advanced Options:
392 \\ --listen=- Enable the build server protocol on stdio
394 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error393 \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
395 \\ -fno-reference-trace Disable reference trace394 \\ -fno-reference-trace Disable reference trace
396 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts395 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts
...@@ -405,8 +404,8 @@ const general_usage =...@@ -405,8 +404,8 @@ const general_usage =
405 \\ poisoned Don't cache the configuration404 \\ poisoned Don't cache the configuration
406 \\ disallowed Panics when cache would be poisoned405 \\ disallowed Panics when cache would be poisoned
407 \\ ignored A little poison never hurt anybody406 \\ ignored A little poison never hurt anybody
408 \\ --print-configuration Render configuration as .zon to stdout and exit407 \\ --print-configuration Render configuration as .zon to stdout. Implies "--configure"
409 \\ --print-configuration-path Print the path to the binary configuration file to stdout408 \\ --print-configuration-path Print the path to the binary configuration file to stdout.
410 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries409 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
411 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)410 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
412 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)411 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)