From 2551cf283f28e2cae27e461b51ea6df92d849fbb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Oct 2026 18:28:07 -0700 Subject: [PATCH] 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 --- lib/compiler/Maker.zig | 46 +++++++++++++--------------- lib/compiler/Maker/ScannedConfig.zig | 21 ++++++------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 7b25111fb5b7c8607c0178ebb16c0c792cb4df2f..a27ce4d4ea998138088a17af5c26c1abfa32716c 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -149,7 +149,7 @@ const ErrorStyle = enum { }; const MultilineErrors = enum { indent, newline, none }; const Summary = enum { all, new, failures, line, none }; -const PrintConfiguration = enum { none, zon, path, tree }; +const PrintConfiguration = enum { none, zon, path, tree, stop }; const GeneratedFile = struct { data: ?[]const u8, @@ -300,7 +300,6 @@ pub fn main(init: process.Init.Minimal) !void { var cached_passthru_configure: std.ArrayList(u32) = .empty; var forks: std.ArrayList(Fork) = .empty; var system_pkg_dir_path: ?[]const u8 = null; - var fetch_only = false; var fetch_mode: Fetch.JobQueue.Mode = .needed; var debug_target: ?[]const u8 = null; var cache_poison: std.Build.Graph.CachePoison = .pure; @@ -387,12 +386,10 @@ pub fn main(init: process.Init.Minimal) !void { override_pkg_dir = nextArgOrFatal(args, &arg_i); } else if (mem.eql(u8, arg, "--print-tree")) { print_configuration = .tree; + } else if (mem.eql(u8, arg, "--configure")) { + print_configuration = .stop; } else if (mem.eql(u8, arg, "--fetch")) { - fetch_only = true; - } else if (mem.cutPrefix(u8, arg, "--fetch=")) |rest| { - fetch_only = true; - fetch_mode = stringToEnum(Fetch.JobQueue.Mode, rest) orelse - fatal("expected [needed|all] after \"--fetch=\", found {q}", .{rest}); + fetch_mode = .all; } else if (mem.cutPrefix(u8, arg, "--fork=")) |rest| { try forks.append(arena, .init(rest)); } else if (mem.eql(u8, arg, "--fork")) { @@ -619,7 +616,7 @@ pub fn main(init: process.Init.Minimal) !void { } } - const early_exit_mode = fetch_only or help_menu or steps_menu or print_configuration != .none; + const early_exit_mode = fetch_mode == .all or help_menu or steps_menu or print_configuration != .none; const server_mode = !early_exit_mode and (watch_flag or webui_listen != null or fuzz != null or listen); process.raiseFileDescriptorLimit(); @@ -793,7 +790,6 @@ pub fn main(init: process.Init.Minimal) !void { .parent_progress_node = main_progress_node, .fetch_mode = fetch_mode, .system_pkg_dir_path = system_pkg_dir_path, - .fetch_only = fetch_only, .print_configuration = print_configuration, .forks = forks.items, .src_files = &configure_source_files, @@ -822,6 +818,7 @@ pub fn main(init: process.Init.Minimal) !void { }, .path => unreachable, .tree => unreachable, + .stop => return cleanExit(io, &scanned_config), } var maker: Maker = .{ @@ -1134,7 +1131,6 @@ const ConfigureOptions = struct { parent_progress_node: std.Progress.Node, fetch_mode: Fetch.JobQueue.Mode, system_pkg_dir_path: ?[]const u8, - fetch_only: bool, print_configuration: PrintConfiguration, forks: []Fork, src_files: *Cache.Manifest.SelfContainedFiles, @@ -1382,20 +1378,22 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { return error.FailedButCacheIntact; } - if (options.fetch_only or options.print_configuration == .tree) { + if (options.fetch_mode == .all) { _ = io.lockStderr(&.{}, .no_color) catch {}; - if (options.print_configuration == .tree) { - const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map); - const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map); - printPkgTree(.{ - .writer = initStdoutWriter(io), - .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE), - }, arena, &job_queue, &fetch) catch |err| switch (err) { - error.WriteFailed => return stdout_writer_allocation.err.?, - else => |e| return e, - }; - try stdout_writer_allocation.flush(); - } + process.exit(0); + } + + if (options.print_configuration == .tree) { + const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map); + const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map); + printPkgTree(.{ + .writer = initStdoutWriter(io), + .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE), + }, arena, &job_queue, &fetch) catch |err| switch (err) { + error.WriteFailed => return stdout_writer_allocation.err.?, + else => |e| return e, + }; + try stdout_writer_allocation.flush(); process.exit(0); } @@ -1677,7 +1675,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { _ = io.lockStderr(&.{}, .no_color) catch {}; process.exit(0); }, - .none, .zon => {}, + .none, .zon, .stop => {}, .tree => unreachable, } diff --git a/lib/compiler/Maker/ScannedConfig.zig b/lib/compiler/Maker/ScannedConfig.zig index 13108dfa207aa8b9b002618d99d805b1020900de..bae416b9bb2523a6b042bfa118d8a60ae43213ed 100644 --- a/lib/compiler/Maker/ScannedConfig.zig +++ b/lib/compiler/Maker/ScannedConfig.zig @@ -353,8 +353,8 @@ const general_usage = \\ --error-style [style] Control how build errors are printed \\ verbose (Default) Report errors with full context \\ minimal Report errors after summary, excluding context like command lines - \\ verbose_clear Like 'verbose', but clear the terminal at the start of each update - \\ minimal_clear Like 'minimal', but clear the terminal at the start of each update + \\ verbose_clear Like "verbose", but clear the terminal at the start of each update + \\ minimal_clear Like "minimal", but clear the terminal at the start of each update \\ --multiline-errors [style] Control how multi-line error messages are printed \\ indent (Default) Indent non-initial lines to align with initial line \\ newline Include a leading newline so that the error message is on its own lines @@ -375,22 +375,21 @@ const general_usage = \\ --webui[=ip] Enable the web interface on the given IP address \\ --fuzz[=limit] Continuously search for unit test failures with an optional \\ limit to the max number of iterations. The argument supports - \\ an optional 'K', 'M', or 'G' suffix (e.g. '10K'). Implies - \\ '--webui' when no limit is specified. - \\ --listen=- Enable the build server protocol on stdio + \\ an optional 'K', 'M', or 'G' suffix (e.g. "10K"). Implies + \\ "--webui" when no limit is specified. \\ --time-report Force full rebuild and provide detailed information on - \\ compilation time of Zig source code (implies '--webui') + \\ compilation time of Zig source code (implies "--webui") \\ -fincremental Enable incremental compilation \\ -fno-incremental Disable incremental compilation + \\ --configure Exit after the configuration phase \\ \\Package Management Options: - \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit - \\ needed (Default) Lazy dependencies are fetched as needed - \\ all Lazy dependencies are always fetched + \\ --fetch Fetch all dependencies including lazy ones; exit without configuration \\ --fork=[path], --fork [path] Override one or more projects from dependency tree \\ --print-tree Write current state of package dependencies to stdout \\ \\Advanced Options: + \\ --listen=- Enable the build server protocol on stdio \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error \\ -fno-reference-trace Disable reference trace \\ -fallow-so-scripts Allows .so files to be GNU ld scripts @@ -405,8 +404,8 @@ const general_usage = \\ poisoned Don't cache the configuration \\ disallowed Panics when cache would be poisoned \\ ignored A little poison never hurt anybody - \\ --print-configuration Render configuration as .zon to stdout and exit - \\ --print-configuration-path Print the path to the binary configuration file to stdout + \\ --print-configuration Render configuration as .zon to stdout. Implies "--configure" + \\ --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) -- 2.54.0