authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 00:33:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 15:09:35-07:00
log5129fae4e8fdb68db1efdff20679b13487501691
tree94d4a545091873df4236372608db368d2d79cf91
parent60c4befad39a1e1689872bc78dd1b8f8d5c34887

std.Build: accept host Target in create()

And only detect native target in LibExeObjStep once, in create().

4 files changed, 19 insertions(+), 6 deletions(-)

lib/build_runner.zig+3
...@@ -41,12 +41,15 @@ pub fn main() !void {...@@ -41,12 +41,15 @@ pub fn main() !void {
41 return error.InvalidArgs;41 return error.InvalidArgs;
42 };42 };
4343
44 const host = try std.zig.system.NativeTargetInfo.detect(.{});
45
44 const builder = try std.Build.create(46 const builder = try std.Build.create(
45 allocator,47 allocator,
46 zig_exe,48 zig_exe,
47 build_root,49 build_root,
48 cache_root,50 cache_root,
49 global_cache_root,51 global_cache_root,
52 host,
50 );53 );
51 defer builder.destroy();54 defer builder.destroy();
5255
lib/std/Build.zig+8-2
...@@ -179,12 +179,11 @@ pub fn create(...@@ -179,12 +179,11 @@ pub fn create(
179 build_root: []const u8,179 build_root: []const u8,
180 cache_root: []const u8,180 cache_root: []const u8,
181 global_cache_root: []const u8,181 global_cache_root: []const u8,
182 host: NativeTargetInfo,
182) !*Build {183) !*Build {
183 const env_map = try allocator.create(EnvMap);184 const env_map = try allocator.create(EnvMap);
184 env_map.* = try process.getEnvMap(allocator);185 env_map.* = try process.getEnvMap(allocator);
185186
186 const host = try NativeTargetInfo.detect(.{});
187
188 const self = try allocator.create(Build);187 const self = try allocator.create(Build);
189 self.* = Build{188 self.* = Build{
190 .zig_exe = zig_exe,189 .zig_exe = zig_exe,
...@@ -1529,12 +1528,15 @@ test "builder.findProgram compiles" {...@@ -1529,12 +1528,15 @@ test "builder.findProgram compiles" {
1529 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);1528 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
1530 defer arena.deinit();1529 defer arena.deinit();
15311530
1531 const host = try NativeTargetInfo.detect(.{});
1532
1532 const builder = try Build.create(1533 const builder = try Build.create(
1533 arena.allocator(),1534 arena.allocator(),
1534 "zig",1535 "zig",
1535 "zig-cache",1536 "zig-cache",
1536 "zig-cache",1537 "zig-cache",
1537 "zig-cache",1538 "zig-cache",
1539 host,
1538 );1540 );
1539 defer builder.destroy();1541 defer builder.destroy();
1540 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;1542 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
...@@ -1713,12 +1715,16 @@ test "dupePkg()" {...@@ -1713,12 +1715,16 @@ test "dupePkg()" {
17131715
1714 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);1716 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
1715 defer arena.deinit();1717 defer arena.deinit();
1718
1719 const host = try NativeTargetInfo.detect(.{});
1720
1716 var builder = try Build.create(1721 var builder = try Build.create(
1717 arena.allocator(),1722 arena.allocator(),
1718 "test",1723 "test",
1719 "test",1724 "test",
1720 "test",1725 "test",
1721 "test",1726 "test",
1727 host,
1722 );1728 );
1723 defer builder.destroy();1729 defer builder.destroy();
17241730
lib/std/Build/LibExeObjStep.zig+4-4
...@@ -364,7 +364,7 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {...@@ -364,7 +364,7 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {
364 .output_h_path_source = GeneratedFile{ .step = &self.step },364 .output_h_path_source = GeneratedFile{ .step = &self.step },
365 .output_pdb_path_source = GeneratedFile{ .step = &self.step },365 .output_pdb_path_source = GeneratedFile{ .step = &self.step },
366366
367 .target_info = undefined, // populated in computeOutFileNames367 .target_info = NativeTargetInfo.detect(self.target) catch unreachable,
368 };368 };
369 self.computeOutFileNames();369 self.computeOutFileNames();
370 if (root_src) |rs| rs.addStepDependencies(&self.step);370 if (root_src) |rs| rs.addStepDependencies(&self.step);
...@@ -372,9 +372,6 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {...@@ -372,9 +372,6 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {
372}372}
373373
374fn computeOutFileNames(self: *LibExeObjStep) void {374fn computeOutFileNames(self: *LibExeObjStep) void {
375 self.target_info = NativeTargetInfo.detect(self.target) catch
376 unreachable;
377
378 const target = self.target_info.target;375 const target = self.target_info.target;
379376
380 self.out_filename = std.zig.binNameAlloc(self.builder.allocator, .{377 self.out_filename = std.zig.binNameAlloc(self.builder.allocator, .{
...@@ -1946,12 +1943,15 @@ test "addPackage" {...@@ -1946,12 +1943,15 @@ test "addPackage" {
1946 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);1943 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
1947 defer arena.deinit();1944 defer arena.deinit();
19481945
1946 const host = try NativeTargetInfo.detect(.{});
1947
1949 var builder = try std.Build.create(1948 var builder = try std.Build.create(
1950 arena.allocator(),1949 arena.allocator(),
1951 "test",1950 "test",
1952 "test",1951 "test",
1953 "test",1952 "test",
1954 "test",1953 "test",
1954 host,
1955 );1955 );
1956 defer builder.destroy();1956 defer builder.destroy();
19571957
lib/std/Build/OptionsStep.zig+4
...@@ -279,12 +279,16 @@ test "OptionsStep" {...@@ -279,12 +279,16 @@ test "OptionsStep" {
279279
280 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);280 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
281 defer arena.deinit();281 defer arena.deinit();
282
283 const host = try std.zig.system.NativeTargetInfo.detect(.{});
284
282 var builder = try std.Build.create(285 var builder = try std.Build.create(
283 arena.allocator(),286 arena.allocator(),
284 "test",287 "test",
285 "test",288 "test",
286 "test",289 "test",
287 "test",290 "test",
291 host,
288 );292 );
289 defer builder.destroy();293 defer builder.destroy();
290294