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 {
4141 return error.InvalidArgs;
4242 };
4343
44 const host = try std.zig.system.NativeTargetInfo.detect(.{});
45
4446 const builder = try std.Build.create(
4547 allocator,
4648 zig_exe,
4749 build_root,
4850 cache_root,
4951 global_cache_root,
52 host,
5053 );
5154 defer builder.destroy();
5255
lib/std/Build.zig+8-2
......@@ -179,12 +179,11 @@ pub fn create(
179179 build_root: []const u8,
180180 cache_root: []const u8,
181181 global_cache_root: []const u8,
182 host: NativeTargetInfo,
182183) !*Build {
183184 const env_map = try allocator.create(EnvMap);
184185 env_map.* = try process.getEnvMap(allocator);
185186
186 const host = try NativeTargetInfo.detect(.{});
187
188187 const self = try allocator.create(Build);
189188 self.* = Build{
190189 .zig_exe = zig_exe,
......@@ -1529,12 +1528,15 @@ test "builder.findProgram compiles" {
15291528 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
15301529 defer arena.deinit();
15311530
1531 const host = try NativeTargetInfo.detect(.{});
1532
15321533 const builder = try Build.create(
15331534 arena.allocator(),
15341535 "zig",
15351536 "zig-cache",
15361537 "zig-cache",
15371538 "zig-cache",
1539 host,
15381540 );
15391541 defer builder.destroy();
15401542 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
......@@ -1713,12 +1715,16 @@ test "dupePkg()" {
17131715
17141716 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
17151717 defer arena.deinit();
1718
1719 const host = try NativeTargetInfo.detect(.{});
1720
17161721 var builder = try Build.create(
17171722 arena.allocator(),
17181723 "test",
17191724 "test",
17201725 "test",
17211726 "test",
1727 host,
17221728 );
17231729 defer builder.destroy();
17241730
lib/std/Build/LibExeObjStep.zig+4-4
......@@ -364,7 +364,7 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {
364364 .output_h_path_source = GeneratedFile{ .step = &self.step },
365365 .output_pdb_path_source = GeneratedFile{ .step = &self.step },
366366
367 .target_info = undefined, // populated in computeOutFileNames
367 .target_info = NativeTargetInfo.detect(self.target) catch unreachable,
368368 };
369369 self.computeOutFileNames();
370370 if (root_src) |rs| rs.addStepDependencies(&self.step);
......@@ -372,9 +372,6 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {
372372}
373373
374374fn computeOutFileNames(self: *LibExeObjStep) void {
375 self.target_info = NativeTargetInfo.detect(self.target) catch
376 unreachable;
377
378375 const target = self.target_info.target;
379376
380377 self.out_filename = std.zig.binNameAlloc(self.builder.allocator, .{
......@@ -1946,12 +1943,15 @@ test "addPackage" {
19461943 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
19471944 defer arena.deinit();
19481945
1946 const host = try NativeTargetInfo.detect(.{});
1947
19491948 var builder = try std.Build.create(
19501949 arena.allocator(),
19511950 "test",
19521951 "test",
19531952 "test",
19541953 "test",
1954 host,
19551955 );
19561956 defer builder.destroy();
19571957
lib/std/Build/OptionsStep.zig+4
......@@ -279,12 +279,16 @@ test "OptionsStep" {
279279
280280 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
281281 defer arena.deinit();
282
283 const host = try std.zig.system.NativeTargetInfo.detect(.{});
284
282285 var builder = try std.Build.create(
283286 arena.allocator(),
284287 "test",
285288 "test",
286289 "test",
287290 "test",
291 host,
288292 );
289293 defer builder.destroy();
290294