diff --git a/BRANCH_TODO b/BRANCH_TODO index 8f95fb7ec6a5b6cd97a3478d534188e8d8216944..762157b6c35e9f86d01e1865a1a2e8e40023ea58 100644 --- 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 index 96d1072c392550b21109cf6d93f969490bd1749b..b5e874af0c869c88af49f7fa9aac30152611e68f 100644 --- 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 index be9d9940fa255e795401cd6de22490a5b87ffb7d..69212eee8694156edec6ce0fe5281598a7bf0eb6 100644 --- 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 index e348e02921c1e345f1a2451072e9c25eea96cc05..4ca16f21258418d602ebf2c67b8a6396f664b728 100644 --- 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 index 9f4c8507459f7ba2592422689714ea84ef748cb9..cd2ec3c28e53923c20f0297aed6b72cd14284ba0 100644 --- 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 index 5ee5c3f3e2b4b7b2a37363d551385ceba8a12ff0..8591de270ed2773be1ae6c907eccfdc2ec7097d1 100644 --- 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);