commit 1a83b4d8fa4b631b6cabf06af8321a8d98eccb94 (tree)
parent 3d785897658fd8b61660649b24d8943bda545982
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 4 May 2026 15:57:18 -0700
zig build: add zig_exe back to argv
trying to eliminate this can be a followup
Diffstat:
6 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/BRANCH_TODO b/BRANCH_TODO
@@ -65,3 +65,7 @@ closes #31397
+ const fmt_include_paths = b.pathList(&.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" });
+ const fmt_exclude_paths = b.pathList(&.{ "test/cases", "test/behavior/zon" });
```
+
+### std.Build API
+
+* `b.build_root` (Directory) -> `b.root` (Path)
diff --git a/lib/compiler/configurer.zig b/lib/compiler/configurer.zig
@@ -39,6 +39,11 @@ pub fn main(init: process.Init.Minimal) !void {
const args = try init.args.toSlice(arena);
+ var arg_i: usize = 1; // Skip own executable name.
+
+ const zig_exe = expectArgOrFatal(args, &arg_i, "--zig");
+ const build_root_sub_path = expectArgOrFatal(args, &arg_i, "--build-root");
+
var graph: std.Build.Graph = .{
.io = io,
.arena = arena,
@@ -49,6 +54,7 @@ pub fn main(init: process.Init.Minimal) !void {
.result = try std.zig.system.resolveTargetQuery(io, .{}),
},
.generated_files = .empty,
+ .zig_exe = zig_exe,
// Created before running the user's configure script so that some things
// can be added during script execution such as strings.
@@ -62,10 +68,6 @@ pub fn main(init: process.Init.Minimal) !void {
assert(try graph.wip_configuration.addString("") == .empty);
assert(try graph.wip_configuration.addString("root") == .root);
- var arg_i: usize = 1; // Skip own executable name.
-
- const build_root_sub_path = expectArgOrFatal(args, &arg_i, "--build-root");
-
const cwd: Io.Dir = .cwd();
const build_root: std.Build.Cache.Path = .{
diff --git a/lib/std/Build.zig b/lib/std/Build.zig
@@ -80,6 +80,7 @@ pub const Graph = struct {
arena: Allocator,
system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,
system_package_mode: bool = false,
+ zig_exe: []const u8,
environ_map: process.Environ.Map,
needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty,
/// Information about the native target. Computed before build() is invoked.
@@ -143,10 +144,7 @@ pub const Graph = struct {
/// Allocates using the global process arena, failing the build on
/// allocation failure.
pub fn create(graph: *const Graph, comptime T: type) *T {
- return if (@sizeOf(T) == 0)
- comptime @ptrFromInt(mem.alignBackward(usize, std.math.maxInt(usize), @alignOf(T)))
- else
- @ptrCast(graph.arena.allocBytesWithAlignment(.of(T), @sizeOf(T), @returnAddress()) catch @panic("OOM"));
+ return @ptrCast(graph.arena.allocBytesAligned(.of(T), @sizeOf(T), @returnAddress()) catch @panic("OOM"));
}
};
diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig
@@ -169,7 +169,7 @@ pub fn create(a: Allocator, comptime T: type) Error!*T {
const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), @alignOf(T));
return @ptrFromInt(ptr);
}
- const ptr: *T = @ptrCast(try a.allocBytesWithAlignment(.of(T), @sizeOf(T), @returnAddress()));
+ const ptr: *T = @ptrCast(try a.allocBytesAligned(.of(T), @sizeOf(T), @returnAddress()));
return ptr;
}
@@ -285,10 +285,10 @@ fn allocWithSizeAndAlignment(
return_address: usize,
) Error![*]align(alignment.toByteUnits()) u8 {
const byte_count = math.mul(usize, size, n) catch return error.OutOfMemory;
- return self.allocBytesWithAlignment(alignment, byte_count, return_address);
+ return self.allocBytesAligned(alignment, byte_count, return_address);
}
-fn allocBytesWithAlignment(
+pub fn allocBytesAligned(
self: Allocator,
comptime alignment: Alignment,
byte_count: usize,
diff --git a/src/main.zig b/src/main.zig
@@ -4982,6 +4982,7 @@ fn cmdBuild(
_ = make_argv.addOneAssumeCapacity(); // maker executable
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };
+ configure_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path };
make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined };
const argv_index_zig_lib_dir = make_argv.items.len - 1;
diff --git a/test/tests.zig b/test/tests.zig
@@ -2890,7 +2890,7 @@ pub fn addCases(
var cases = @import("src/Cases.zig").init(gpa, arena, io);
- var dir = try b.build_root.handle.openDir(io, "test/cases", .{ .iterate = true });
+ var dir = try b.root.openDir(io, "test/cases", .{ .iterate = true });
defer dir.close(io);
cases.addFromDir(dir, b);
@@ -2948,7 +2948,7 @@ pub fn addIncrementalTests(b: *std.Build, test_step: *Step, test_filters: []cons
}),
});
- var dir = try b.build_root.handle.openDir(io, "test/incremental", .{ .iterate = true });
+ var dir = try b.root.openDir(io, "test/incremental", .{ .iterate = true });
defer dir.close(io);
var it = try dir.walk(b.graph.arena);