authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-04 15:57:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
log1a83b4d8fa4b631b6cabf06af8321a8d98eccb94
treee5fb8268d4cf4f667f27538987cc62c052d719b8
parent3d785897658fd8b61660649b24d8943bda545982

zig build: add zig_exe back to argv

trying to eliminate this can be a followup

6 files changed, 18 insertions(+), 13 deletions(-)

BRANCH_TODO+4
...@@ -65,3 +65,7 @@ closes #31397...@@ -65,3 +65,7 @@ closes #31397
65+ const fmt_include_paths = b.pathList(&.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" });65+ const fmt_include_paths = b.pathList(&.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" });
66+ const fmt_exclude_paths = b.pathList(&.{ "test/cases", "test/behavior/zon" });66+ const fmt_exclude_paths = b.pathList(&.{ "test/cases", "test/behavior/zon" });
67```67```
68
69### std.Build API
70
71* `b.build_root` (Directory) -> `b.root` (Path)
lib/compiler/configurer.zig+6-4
...@@ -39,6 +39,11 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -39,6 +39,11 @@ 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 var arg_i: usize = 1; // Skip own executable name.
43
44 const zig_exe = expectArgOrFatal(args, &arg_i, "--zig");
45 const build_root_sub_path = expectArgOrFatal(args, &arg_i, "--build-root");
46
42 var graph: std.Build.Graph = .{47 var graph: std.Build.Graph = .{
43 .io = io,48 .io = io,
44 .arena = arena,49 .arena = arena,
...@@ -49,6 +54,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -49,6 +54,7 @@ pub fn main(init: process.Init.Minimal) !void {
49 .result = try std.zig.system.resolveTargetQuery(io, .{}),54 .result = try std.zig.system.resolveTargetQuery(io, .{}),
50 },55 },
51 .generated_files = .empty,56 .generated_files = .empty,
57 .zig_exe = zig_exe,
5258
53 // Created before running the user's configure script so that some things59 // Created before running the user's configure script so that some things
54 // can be added during script execution such as strings.60 // can be added during script execution such as strings.
...@@ -62,10 +68,6 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -62,10 +68,6 @@ pub fn main(init: process.Init.Minimal) !void {
62 assert(try graph.wip_configuration.addString("") == .empty);68 assert(try graph.wip_configuration.addString("") == .empty);
63 assert(try graph.wip_configuration.addString("root") == .root);69 assert(try graph.wip_configuration.addString("root") == .root);
6470
65 var arg_i: usize = 1; // Skip own executable name.
66
67 const build_root_sub_path = expectArgOrFatal(args, &arg_i, "--build-root");
68
69 const cwd: Io.Dir = .cwd();71 const cwd: Io.Dir = .cwd();
7072
71 const build_root: std.Build.Cache.Path = .{73 const build_root: std.Build.Cache.Path = .{
lib/std/Build.zig+2-4
...@@ -80,6 +80,7 @@ pub const Graph = struct {...@@ -80,6 +80,7 @@ pub const Graph = struct {
80 arena: Allocator,80 arena: Allocator,
81 system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,81 system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,
82 system_package_mode: bool = false,82 system_package_mode: bool = false,
83 zig_exe: []const u8,
83 environ_map: process.Environ.Map,84 environ_map: process.Environ.Map,
84 needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty,85 needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty,
85 /// Information about the native target. Computed before build() is invoked.86 /// Information about the native target. Computed before build() is invoked.
...@@ -143,10 +144,7 @@ pub const Graph = struct {...@@ -143,10 +144,7 @@ pub const Graph = struct {
143 /// Allocates using the global process arena, failing the build on144 /// Allocates using the global process arena, failing the build on
144 /// allocation failure.145 /// allocation failure.
145 pub fn create(graph: *const Graph, comptime T: type) *T {146 pub fn create(graph: *const Graph, comptime T: type) *T {
146 return if (@sizeOf(T) == 0)147 return @ptrCast(graph.arena.allocBytesAligned(.of(T), @sizeOf(T), @returnAddress()) catch @panic("OOM"));
147 comptime @ptrFromInt(mem.alignBackward(usize, std.math.maxInt(usize), @alignOf(T)))
148 else
149 @ptrCast(graph.arena.allocBytesWithAlignment(.of(T), @sizeOf(T), @returnAddress()) catch @panic("OOM"));
150 }148 }
151};149};
152150
lib/std/mem/Allocator.zig+3-3
...@@ -169,7 +169,7 @@ pub fn create(a: Allocator, comptime T: type) Error!*T {...@@ -169,7 +169,7 @@ pub fn create(a: Allocator, comptime T: type) Error!*T {
169 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), @alignOf(T));169 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), @alignOf(T));
170 return @ptrFromInt(ptr);170 return @ptrFromInt(ptr);
171 }171 }
172 const ptr: *T = @ptrCast(try a.allocBytesWithAlignment(.of(T), @sizeOf(T), @returnAddress()));172 const ptr: *T = @ptrCast(try a.allocBytesAligned(.of(T), @sizeOf(T), @returnAddress()));
173 return ptr;173 return ptr;
174}174}
175175
...@@ -285,10 +285,10 @@ fn allocWithSizeAndAlignment(...@@ -285,10 +285,10 @@ fn allocWithSizeAndAlignment(
285 return_address: usize,285 return_address: usize,
286) Error![*]align(alignment.toByteUnits()) u8 {286) Error![*]align(alignment.toByteUnits()) u8 {
287 const byte_count = math.mul(usize, size, n) catch return error.OutOfMemory;287 const byte_count = math.mul(usize, size, n) catch return error.OutOfMemory;
288 return self.allocBytesWithAlignment(alignment, byte_count, return_address);288 return self.allocBytesAligned(alignment, byte_count, return_address);
289}289}
290290
291fn allocBytesWithAlignment(291pub fn allocBytesAligned(
292 self: Allocator,292 self: Allocator,
293 comptime alignment: Alignment,293 comptime alignment: Alignment,
294 byte_count: usize,294 byte_count: usize,
src/main.zig+1
...@@ -4982,6 +4982,7 @@ fn cmdBuild(...@@ -4982,6 +4982,7 @@ fn cmdBuild(
4982 _ = make_argv.addOneAssumeCapacity(); // maker executable4982 _ = make_argv.addOneAssumeCapacity(); // maker executable
49834983
4984 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };4984 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };
4985 configure_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };
49854986
4986 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined };4987 make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined };
4987 const argv_index_zig_lib_dir = make_argv.items.len - 1;4988 const argv_index_zig_lib_dir = make_argv.items.len - 1;
test/tests.zig+2-2
...@@ -2890,7 +2890,7 @@ pub fn addCases(...@@ -2890,7 +2890,7 @@ pub fn addCases(
28902890
2891 var cases = @import("src/Cases.zig").init(gpa, arena, io);2891 var cases = @import("src/Cases.zig").init(gpa, arena, io);
28922892
2893 var dir = try b.build_root.handle.openDir(io, "test/cases", .{ .iterate = true });2893 var dir = try b.root.openDir(io, "test/cases", .{ .iterate = true });
2894 defer dir.close(io);2894 defer dir.close(io);
28952895
2896 cases.addFromDir(dir, b);2896 cases.addFromDir(dir, b);
...@@ -2948,7 +2948,7 @@ pub fn addIncrementalTests(b: *std.Build, test_step: *Step, test_filters: []cons...@@ -2948,7 +2948,7 @@ pub fn addIncrementalTests(b: *std.Build, test_step: *Step, test_filters: []cons
2948 }),2948 }),
2949 });2949 });
29502950
2951 var dir = try b.build_root.handle.openDir(io, "test/incremental", .{ .iterate = true });2951 var dir = try b.root.openDir(io, "test/incremental", .{ .iterate = true });
2952 defer dir.close(io);2952 defer dir.close(io);
29532953
2954 var it = try dir.walk(b.graph.arena);2954 var it = try dir.walk(b.graph.arena);