authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-30 15:35:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
logaec708ce25409f7e5aa9f39568cdf6281e857742
tree105348ef6edb7cbea239fdcee31a121d3b42c60f
parent1dc82c13280ae327faf9448dcaf69960f5f5cad4

build system: remove unneeded args from configurer

not needed: * zig exe path * zig lib dir * build root * local cache root * global cache root

5 files changed, 40 insertions(+), 135 deletions(-)

lib/compiler/Maker/Step/Run.zig+4-1
...@@ -189,7 +189,10 @@ pub fn make(...@@ -189,7 +189,10 @@ pub fn make(
189189
190 man.hash.add(conf_run.flags.test_runner_mode);190 man.hash.add(conf_run.flags.test_runner_mode);
191 if (conf_run.flags.test_runner_mode) {191 if (conf_run.flags.test_runner_mode) {
192 try argv_list.ensureUnusedCapacity(gpa, 2);192 const cache_dir_string = try convertPathArg(run_index, maker, .{ .root_dir = cache_root });
193
194 try argv_list.ensureUnusedCapacity(gpa, 3);
195 argv_list.appendAssumeCapacity(try allocPrint(arena, "--cache-dir={s}", .{cache_dir_string}));
193 argv_list.appendAssumeCapacity(try allocPrint(arena, "--seed=0x{x}", .{graph.random_seed}));196 argv_list.appendAssumeCapacity(try allocPrint(arena, "--seed=0x{x}", .{graph.random_seed}));
194 argv_list.appendAssumeCapacity("--listen=-");197 argv_list.appendAssumeCapacity("--listen=-");
195 }198 }
lib/compiler/configurer.zig+7-59
...@@ -39,44 +39,10 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -39,44 +39,10 @@ pub fn main(init: process.Init.Minimal) !void {
3939
40 const args = try init.args.toSlice(arena);40 const args = try init.args.toSlice(arena);
4141
42 // Skip own executable name.
43 var arg_idx: usize = 1;
44
45 const zig_exe = expectArgOrFatal(args, &arg_idx, "--zig");
46 const zig_lib_dir = expectArgOrFatal(args, &arg_idx, "--zig-lib-dir");
47 const build_root = expectArgOrFatal(args, &arg_idx, "--build-root");
48 const local_cache_root = expectArgOrFatal(args, &arg_idx, "--local-cache");
49 const global_cache_root = expectArgOrFatal(args, &arg_idx, "--global-cache");
50
51 const cwd: Io.Dir = .cwd();
52
53 const zig_lib_directory: std.Build.Cache.Directory = .{
54 .path = zig_lib_dir,
55 .handle = try cwd.openDir(io, zig_lib_dir, .{}),
56 };
57
58 const build_root_directory: std.Build.Cache.Directory = .{
59 .path = build_root,
60 .handle = try cwd.openDir(io, build_root, .{}),
61 };
62
63 const local_cache_directory: std.Build.Cache.Directory = .{
64 .path = local_cache_root,
65 .handle = try cwd.createDirPathOpen(io, local_cache_root, .{}),
66 };
67
68 const global_cache_directory: std.Build.Cache.Directory = .{
69 .path = global_cache_root,
70 .handle = try cwd.createDirPathOpen(io, global_cache_root, .{}),
71 };
72
73 var graph: std.Build.Graph = .{42 var graph: std.Build.Graph = .{
74 .io = io,43 .io = io,
75 .arena = arena,44 .arena = arena,
76 .zig_exe = zig_exe,
77 .environ_map = try init.environ.createMap(arena),45 .environ_map = try init.environ.createMap(arena),
78 .global_cache_root = global_cache_directory,
79 .zig_lib_directory = zig_lib_directory,
80 // TODO get this from parent process instead46 // TODO get this from parent process instead
81 .host = .{47 .host = .{
82 .query = .{},48 .query = .{},
...@@ -96,12 +62,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -96,12 +62,7 @@ pub fn main(init: process.Init.Minimal) !void {
96 assert(try graph.wip_configuration.addString("") == .empty);62 assert(try graph.wip_configuration.addString("") == .empty);
97 assert(try graph.wip_configuration.addString("root") == .root);63 assert(try graph.wip_configuration.addString("root") == .root);
9864
99 const builder = try std.Build.create(65 const builder = try std.Build.create(&graph, dependencies.root_deps);
100 &graph,
101 build_root_directory,
102 local_cache_directory,
103 dependencies.root_deps,
104 );
10566
106 var error_style: ErrorStyle = .verbose;67 var error_style: ErrorStyle = .verbose;
107 var multiline_errors: MultilineErrors = .indent;68 var multiline_errors: MultilineErrors = .indent;
...@@ -119,7 +80,9 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -119,7 +80,9 @@ pub fn main(init: process.Init.Minimal) !void {
119 }80 }
120 }81 }
12182
122 while (nextArg(args, &arg_idx)) |arg| {83 var arg_i: usize = 1; // Skip own executable name.
84
85 while (nextArg(args, &arg_i)) |arg| {
123 if (mem.cutPrefix(u8, arg, "-D")) |option_contents| {86 if (mem.cutPrefix(u8, arg, "-D")) |option_contents| {
124 if (option_contents.len == 0)87 if (option_contents.len == 0)
125 fatalWithHint("expected option name after '-D'", .{});88 fatalWithHint("expected option name after '-D'", .{});
...@@ -145,7 +108,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -145,7 +108,7 @@ pub fn main(init: process.Init.Minimal) !void {
145 });108 });
146 };109 };
147 } else if (mem.eql(u8, arg, "--color")) {110 } else if (mem.eql(u8, arg, "--color")) {
148 const next_arg = nextArg(args, &arg_idx) orelse111 const next_arg = nextArg(args, &arg_i) orelse
149 fatalWithHint("expected [auto|on|off] after {q}", .{arg});112 fatalWithHint("expected [auto|on|off] after {q}", .{arg});
150 color = std.meta.stringToEnum(Color, next_arg) orelse {113 color = std.meta.stringToEnum(Color, next_arg) orelse {
151 fatalWithHint("expected [auto|on|off] after {q}, found {q}", .{114 fatalWithHint("expected [auto|on|off] after {q}, found {q}", .{
...@@ -153,13 +116,13 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -153,13 +116,13 @@ pub fn main(init: process.Init.Minimal) !void {
153 });116 });
154 };117 };
155 } else if (mem.eql(u8, arg, "--error-style")) {118 } else if (mem.eql(u8, arg, "--error-style")) {
156 const next_arg = nextArg(args, &arg_idx) orelse119 const next_arg = nextArg(args, &arg_i) orelse
157 fatalWithHint("expected style after {q}", .{arg});120 fatalWithHint("expected style after {q}", .{arg});
158 error_style = std.meta.stringToEnum(ErrorStyle, next_arg) orelse {121 error_style = std.meta.stringToEnum(ErrorStyle, next_arg) orelse {
159 fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg });122 fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg });
160 };123 };
161 } else if (mem.eql(u8, arg, "--multiline-errors")) {124 } else if (mem.eql(u8, arg, "--multiline-errors")) {
162 const next_arg = nextArg(args, &arg_idx) orelse125 const next_arg = nextArg(args, &arg_i) orelse
163 fatalWithHint("expected style after {q}", .{arg});126 fatalWithHint("expected style after {q}", .{arg});
164 multiline_errors = std.meta.stringToEnum(MultilineErrors, next_arg) orelse {127 multiline_errors = std.meta.stringToEnum(MultilineErrors, next_arg) orelse {
165 fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg });128 fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg });
...@@ -169,8 +132,6 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -169,8 +132,6 @@ pub fn main(init: process.Init.Minimal) !void {
169 // but it is handled by the parent process. The build runner132 // but it is handled by the parent process. The build runner
170 // only sees this flag.133 // only sees this flag.
171 graph.system_package_mode = true;134 graph.system_package_mode = true;
172 } else if (mem.eql(u8, arg, "--have-run-args")) {
173 graph.have_run_args = true;
174 } else {135 } else {
175 fatalWithHint("unrecognized argument: {q}", .{arg});136 fatalWithHint("unrecognized argument: {q}", .{arg});
176 }137 }
...@@ -1112,19 +1073,6 @@ fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {...@@ -1112,19 +1073,6 @@ fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {
1112 return args[idx.*];1073 return args[idx.*];
1113}1074}
11141075
1115fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 {
1116 return nextArg(args, idx) orelse {
1117 fatalWithHint("expected argument after: {s}", .{args[idx.* - 1]});
1118 };
1119}
1120
1121fn expectArgOrFatal(args: []const [:0]const u8, index_ptr: *usize, first: []const u8) []const u8 {
1122 const next_arg = nextArg(args, index_ptr) orelse fatal("missing {q} argument", .{first});
1123 if (!mem.eql(u8, first, next_arg)) fatal("expected {q} instead of {q}", .{ first, next_arg });
1124 const arg = nextArg(args, index_ptr) orelse fatal("expected argument after {q}", .{first});
1125 return arg;
1126}
1127
1128const ErrorStyle = enum {1076const ErrorStyle = enum {
1129 verbose,1077 verbose,
1130 minimal,1078 minimal,
lib/std/Build.zig+7-27
...@@ -36,9 +36,6 @@ invalid_user_input: bool,...@@ -36,9 +36,6 @@ invalid_user_input: bool,
36default_step: *Step,36default_step: *Step,
37top_level_steps: std.StringArrayHashMapUnmanaged(*Step.TopLevel),37top_level_steps: std.StringArrayHashMapUnmanaged(*Step.TopLevel),
38install_prefix: []const u8,38install_prefix: []const u8,
39/// Path to the directory containing build.zig.
40build_root: Cache.Directory,
41cache_root: Cache.Directory,
42debug_log_scopes: []const []const u8 = &.{},39debug_log_scopes: []const []const u8 = &.{},
43/// Number of stack frames captured when a `StackTrace` is recorded for debug purposes,40/// Number of stack frames captured when a `StackTrace` is recorded for debug purposes,
44/// in particular at `Step` creation.41/// in particular at `Step` creation.
...@@ -83,10 +80,7 @@ pub const Graph = struct {...@@ -83,10 +80,7 @@ pub const Graph = struct {
83 arena: Allocator,80 arena: Allocator,
84 system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,81 system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,
85 system_package_mode: bool = false,82 system_package_mode: bool = false,
86 zig_exe: []const u8,
87 environ_map: process.Environ.Map,83 environ_map: process.Environ.Map,
88 global_cache_root: Cache.Directory,
89 zig_lib_directory: Cache.Directory,
90 needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty,84 needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty,
91 /// Information about the native target. Computed before build() is invoked.85 /// Information about the native target. Computed before build() is invoked.
92 host: ResolvedTarget,86 host: ResolvedTarget,
...@@ -97,10 +91,6 @@ pub const Graph = struct {...@@ -97,10 +91,6 @@ pub const Graph = struct {
97 /// respects the '--color' flag.91 /// respects the '--color' flag.
98 stderr_mode: ?Io.Terminal.Mode = null,92 stderr_mode: ?Io.Terminal.Mode = null,
99 release_mode: ReleaseMode = .off,93 release_mode: ReleaseMode = .off,
100 /// Whether the user passed in "--" arguments. They can be added to a child
101 /// process via `Step.Run` API but cannot be observed in the configure
102 /// phase.
103 have_run_args: bool = false,
10494
105 /// Indexes correspond to `Configuration.GeneratedFileIndex`.95 /// Indexes correspond to `Configuration.GeneratedFileIndex`.
106 generated_files: std.ArrayList(*Step),96 generated_files: std.ArrayList(*Step),
...@@ -230,8 +220,6 @@ const TypeId = enum {...@@ -230,8 +220,6 @@ const TypeId = enum {
230220
231pub fn create(221pub fn create(
232 graph: *Graph,222 graph: *Graph,
233 build_root: Cache.Directory,
234 cache_root: Cache.Directory,
235 available_deps: AvailableDeps,223 available_deps: AvailableDeps,
236) error{OutOfMemory}!*Build {224) error{OutOfMemory}!*Build {
237 const arena = graph.arena;225 const arena = graph.arena;
...@@ -239,8 +227,6 @@ pub fn create(...@@ -239,8 +227,6 @@ pub fn create(
239 const b = try arena.create(Build);227 const b = try arena.create(Build);
240 b.* = .{228 b.* = .{
241 .graph = graph,229 .graph = graph,
242 .build_root = build_root,
243 .cache_root = cache_root,
244 .invalid_user_input = false,230 .invalid_user_input = false,
245 .allocator = arena,231 .allocator = arena,
246 .user_input_options = UserInputOptionsMap.init(arena),232 .user_input_options = UserInputOptionsMap.init(arena),
...@@ -280,7 +266,6 @@ pub fn create(...@@ -280,7 +266,6 @@ pub fn create(
280fn createChild(266fn createChild(
281 parent: *Build,267 parent: *Build,
282 dep_name: []const u8,268 dep_name: []const u8,
283 build_root: Cache.Directory,
284 pkg_hash: []const u8,269 pkg_hash: []const u8,
285 pkg_deps: AvailableDeps,270 pkg_deps: AvailableDeps,
286 user_input_options: UserInputOptionsMap,271 user_input_options: UserInputOptionsMap,
...@@ -312,8 +297,6 @@ fn createChild(...@@ -312,8 +297,6 @@ fn createChild(
312 .invalid_user_input = false,297 .invalid_user_input = false,
313 .default_step = undefined,298 .default_step = undefined,
314 .top_level_steps = .{},299 .top_level_steps = .{},
315 .build_root = build_root,
316 .cache_root = parent.cache_root,
317 .debug_log_scopes = parent.debug_log_scopes,300 .debug_log_scopes = parent.debug_log_scopes,
318 .enable_darling = parent.enable_darling,301 .enable_darling = parent.enable_darling,
319 .enable_qemu = parent.enable_qemu,302 .enable_qemu = parent.enable_qemu,
...@@ -2036,15 +2019,12 @@ fn dependencyInner(...@@ -2036,15 +2019,12 @@ fn dependencyInner(
20362019
2037 const build_root: std.Build.Cache.Directory = .{2020 const build_root: std.Build.Cache.Directory = .{
2038 .path = build_root_string,2021 .path = build_root_string,
2039 .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err| {2022 .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err|
2040 std.debug.print("unable to open '{s}': {s}\n", .{2023 process.fatal("unable to open {s}: {t}", .{ build_root_string, err }),
2041 build_root_string, @errorName(err),
2042 });
2043 process.exit(1);
2044 },
2045 };2024 };
20462025
2047 const sub_builder = b.createChild(name, build_root, pkg_hash, pkg_deps, user_input_options) catch @panic("unhandled error");2026 const sub_builder = b.createChild(name, build_root, pkg_hash, pkg_deps, user_input_options) catch
2027 @panic("unhandled error");
2048 if (build_zig) |bz| {2028 if (build_zig) |bz| {
2049 sub_builder.runBuild(bz) catch @panic("unhandled error");2029 sub_builder.runBuild(bz) catch @panic("unhandled error");
20502030
...@@ -2330,9 +2310,9 @@ pub const InstallDir = union(enum) {...@@ -2330,9 +2310,9 @@ pub const InstallDir = union(enum) {
2330 }2310 }
2331};2311};
23322312
2333/// Creates a path leading to a directory inside "tmp" subdirectory of2313/// Creates a path leading to a directory inside "tmp" subdirectory of local
2334/// `cache_root` which is created on demand and cleaned up by the build runner2314/// cache which is created on demand and cleaned up by the build runner upon
2335/// upon success.2315/// success.
2336pub fn tmpPath(b: *Build) LazyPath {2316pub fn tmpPath(b: *Build) LazyPath {
2337 const wf = b.addTempFiles();2317 const wf = b.addTempFiles();
2338 return wf.getDirectory();2318 return wf.getDirectory();
lib/std/Build/Step/Run.zig-2
...@@ -215,9 +215,7 @@ pub fn setName(run: *Run, name: []const u8) void {...@@ -215,9 +215,7 @@ pub fn setName(run: *Run, name: []const u8) void {
215215
216pub fn enableTestRunnerMode(run: *Run) void {216pub fn enableTestRunnerMode(run: *Run) void {
217 if (run.test_runner_mode) return;217 if (run.test_runner_mode) return;
218 const b = run.step.owner;
219 run.stdio = .zig_test;218 run.stdio = .zig_test;
220 run.addPrefixedDirectoryArg("--cache-dir=", .{ .cwd_relative = b.cache_root.path orelse "." });
221 run.test_runner_mode = true;219 run.test_runner_mode = true;
222}220}
223221
src/main.zig+22-46
...@@ -4976,43 +4976,27 @@ fn cmdBuild(...@@ -4976,43 +4976,27 @@ fn cmdBuild(
4976 try configure_argv.ensureUnusedCapacity(arena, 16);4976 try configure_argv.ensureUnusedCapacity(arena, 16);
4977 try make_argv.ensureUnusedCapacity(arena, 16);4977 try make_argv.ensureUnusedCapacity(arena, 16);
49784978
4979 _ = configure_argv.addOneAssumeCapacity();4979 _ = configure_argv.addOneAssumeCapacity(); // configurer executable
4980 _ = make_argv.addOneAssumeCapacity();4980 _ = make_argv.addOneAssumeCapacity(); // maker executable
49814981
4982 configure_argv.appendAssumeCapacity("--zig");4982 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };
4983 configure_argv.appendAssumeCapacity(self_exe_path);4983
49844984 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined };
4985 make_argv.appendAssumeCapacity("--zig");4985 const argv_index_zig_lib_dir = make_argv.items.len - 1;
4986 make_argv.appendAssumeCapacity(self_exe_path);4986
49874987 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--build-root", undefined };
4988 configure_argv.appendAssumeCapacity("--zig-lib-dir");4988 const argv_index_build_file = make_argv.items.len - 1;
4989 make_argv.appendAssumeCapacity("--zig-lib-dir");4989
4990 const argv_index_zig_lib_dir = configure_argv.items.len;4990 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--local-cache", undefined };
4991 _ = configure_argv.addOneAssumeCapacity();4991 const argv_index_cache_dir = make_argv.items.len - 1;
4992 _ = make_argv.addOneAssumeCapacity();4992
49934993 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--global-cache", undefined };
4994 configure_argv.appendAssumeCapacity("--build-root");4994 const argv_index_global_cache_dir = make_argv.items.len - 1;
4995 make_argv.appendAssumeCapacity("--build-root");4995
4996 const argv_index_build_file = configure_argv.items.len;4996 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--configuration", undefined };
4997 _ = configure_argv.addOneAssumeCapacity();
4998 _ = make_argv.addOneAssumeCapacity();
4999
5000 configure_argv.appendAssumeCapacity("--local-cache");
5001 make_argv.appendAssumeCapacity("--local-cache");
5002 const argv_index_cache_dir = configure_argv.items.len;
5003 _ = configure_argv.addOneAssumeCapacity();
5004 _ = make_argv.addOneAssumeCapacity();
5005
5006 configure_argv.appendAssumeCapacity("--global-cache");
5007 make_argv.appendAssumeCapacity("--global-cache");
5008 const argv_index_global_cache_dir = configure_argv.items.len;
5009 _ = configure_argv.addOneAssumeCapacity();
5010 _ = make_argv.addOneAssumeCapacity();
5011
5012 make_argv.appendSliceAssumeCapacity(&.{ "--configuration", undefined });
5013 const argv_index_configuration_file = make_argv.items.len - 1;4997 const argv_index_configuration_file = make_argv.items.len - 1;
50144998
5015 make_argv.appendSliceAssumeCapacity(&.{ "--seed", default_seed });4999 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--seed", default_seed };
5016 const argv_index_seed = make_argv.items.len - 1;5000 const argv_index_seed = make_argv.items.len - 1;
50175001
5018 var color: Color = .auto;5002 var color: Color = .auto;
...@@ -5147,13 +5131,10 @@ fn cmdBuild(...@@ -5147,13 +5131,10 @@ fn cmdBuild(
5147 try configure_argv.appendSlice(arena, &.{ arg, args[i] });5131 try configure_argv.appendSlice(arena, &.{ arg, args[i] });
5148 continue;5132 continue;
5149 } else if (mem.cutPrefix(u8, arg, "-j")) |str| {5133 } else if (mem.cutPrefix(u8, arg, "-j")) |str| {
5150 const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| {5134 const num = std.fmt.parseUnsigned(u32, str, 10) catch |err|
5151 fatal("unable to parse jobs count '{s}': {s}", .{5135 fatal("unable to parse jobs count {s}: {t}", .{ str, err });
5152 str, @errorName(err),
5153 });
5154 };
5155 if (num < 1) {5136 if (num < 1) {
5156 fatal("number of jobs must be at least 1\n", .{});5137 fatal("number of jobs must be at least 1", .{});
5157 }5138 }
5158 n_jobs = num;5139 n_jobs = num;
5159 } else if (mem.eql(u8, arg, "--seed")) {5140 } else if (mem.eql(u8, arg, "--seed")) {
...@@ -5287,11 +5268,6 @@ fn cmdBuild(...@@ -5287,11 +5268,6 @@ fn cmdBuild(
5287 } });5268 } });
5288 defer _ = make_runner_task.cancel(io) catch {};5269 defer _ = make_runner_task.cancel(io) catch {};
52895270
5290 configure_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
5291 configure_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;
5292 configure_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path;
5293 configure_argv.items[argv_index_cache_dir] = dirs.local_cache.path orelse cwd_path;
5294
5295 make_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;5271 make_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path;
5296 make_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;5272 make_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path;
5297 make_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path;5273 make_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path;