aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-01-31 00:33:45 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-01-31 15:09:35 -0700
commit5129fae4e8fdb68db1efdff20679b13487501691 (patch)
tree94d4a545091873df4236372608db368d2d79cf91 /lib
parent60c4befad39a1e1689872bc78dd1b8f8d5c34887 (diff)
downloadzig-5129fae4e8fdb68db1efdff20679b13487501691.tar.gz
zig-5129fae4e8fdb68db1efdff20679b13487501691.zip
std.Build: accept host Target in create()
And only detect native target in LibExeObjStep once, in create().
Diffstat (limited to 'lib')
-rw-r--r--lib/build_runner.zig3
-rw-r--r--lib/std/Build.zig10
-rw-r--r--lib/std/Build/LibExeObjStep.zig8
-rw-r--r--lib/std/Build/OptionsStep.zig4
4 files changed, 19 insertions, 6 deletions
diff --git a/lib/build_runner.zig b/lib/build_runner.zig
index 189b118787..f2b2eba950 100644
--- a/lib/build_runner.zig
+++ b/lib/build_runner.zig
@@ -41,12 +41,15 @@ pub fn main() !void {
return error.InvalidArgs;
};
+ const host = try std.zig.system.NativeTargetInfo.detect(.{});
+
const builder = try std.Build.create(
allocator,
zig_exe,
build_root,
cache_root,
global_cache_root,
+ host,
);
defer builder.destroy();
diff --git a/lib/std/Build.zig b/lib/std/Build.zig
index a3c579c743..c0152ef6f1 100644
--- a/lib/std/Build.zig
+++ b/lib/std/Build.zig
@@ -179,12 +179,11 @@ pub fn create(
build_root: []const u8,
cache_root: []const u8,
global_cache_root: []const u8,
+ host: NativeTargetInfo,
) !*Build {
const env_map = try allocator.create(EnvMap);
env_map.* = try process.getEnvMap(allocator);
- const host = try NativeTargetInfo.detect(.{});
-
const self = try allocator.create(Build);
self.* = Build{
.zig_exe = zig_exe,
@@ -1529,12 +1528,15 @@ test "builder.findProgram compiles" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
+ const host = try NativeTargetInfo.detect(.{});
+
const builder = try Build.create(
arena.allocator(),
"zig",
"zig-cache",
"zig-cache",
"zig-cache",
+ host,
);
defer builder.destroy();
_ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
@@ -1713,12 +1715,16 @@ test "dupePkg()" {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
+
+ const host = try NativeTargetInfo.detect(.{});
+
var builder = try Build.create(
arena.allocator(),
"test",
"test",
"test",
"test",
+ host,
);
defer builder.destroy();
diff --git a/lib/std/Build/LibExeObjStep.zig b/lib/std/Build/LibExeObjStep.zig
index af9d34440d..67f42c1783 100644
--- a/lib/std/Build/LibExeObjStep.zig
+++ b/lib/std/Build/LibExeObjStep.zig
@@ -364,7 +364,7 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {
.output_h_path_source = GeneratedFile{ .step = &self.step },
.output_pdb_path_source = GeneratedFile{ .step = &self.step },
- .target_info = undefined, // populated in computeOutFileNames
+ .target_info = NativeTargetInfo.detect(self.target) catch unreachable,
};
self.computeOutFileNames();
if (root_src) |rs| rs.addStepDependencies(&self.step);
@@ -372,9 +372,6 @@ pub fn create(builder: *std.Build, options: Options) *LibExeObjStep {
}
fn computeOutFileNames(self: *LibExeObjStep) void {
- self.target_info = NativeTargetInfo.detect(self.target) catch
- unreachable;
-
const target = self.target_info.target;
self.out_filename = std.zig.binNameAlloc(self.builder.allocator, .{
@@ -1946,12 +1943,15 @@ test "addPackage" {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
+ const host = try NativeTargetInfo.detect(.{});
+
var builder = try std.Build.create(
arena.allocator(),
"test",
"test",
"test",
"test",
+ host,
);
defer builder.destroy();
diff --git a/lib/std/Build/OptionsStep.zig b/lib/std/Build/OptionsStep.zig
index 3d26807411..8e1a7ef2fc 100644
--- a/lib/std/Build/OptionsStep.zig
+++ b/lib/std/Build/OptionsStep.zig
@@ -279,12 +279,16 @@ test "OptionsStep" {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
+
+ const host = try std.zig.system.NativeTargetInfo.detect(.{});
+
var builder = try std.Build.create(
arena.allocator(),
"test",
"test",
"test",
"test",
+ host,
);
defer builder.destroy();