aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Step/Options.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-02-01 15:44:44 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-02-02 20:43:01 -0700
commit105db13536b4dc2affe130cb8d2eee6c97c89bcd (patch)
tree07d5a285d7ff1ea5262118e94ea61a018f1d775a /lib/std/Build/Step/Options.zig
parentbd1d2b0ae25ead6cd27c0bfeb65490ee92f06bad (diff)
downloadzig-105db13536b4dc2affe130cb8d2eee6c97c89bcd.tar.gz
zig-105db13536b4dc2affe130cb8d2eee6c97c89bcd.zip
std.Build: implement --host-target, --host-cpu, --host-dynamic-linker
This also makes a long-overdue change of extracting common state from Build into a shared Graph object. Getting the semantics right for these flags turned out to be quite tricky. In the end it works like this: * The override only happens when the target is fully native, with no additional query parameters, such as versions or CPU features added. * The override affects the resolved Target but leaves the original Query unmodified. * The "is native?" detection logic operates on the original, unmodified query. This makes it possible to provide invalid host target information, causing confusing errors to occur. Don't do that. There are some minor breaking changes to std.Build API such as the fact that `b.zig_exe` is now moved to `b.graph.zig_exe`, as well as a handful of other similar flags.
Diffstat (limited to 'lib/std/Build/Step/Options.zig')
-rw-r--r--lib/std/Build/Step/Options.zig31
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig
index beaaf4e3a0..8dfe735703 100644
--- a/lib/std/Build/Step/Options.zig
+++ b/lib/std/Build/Step/Options.zig
@@ -222,7 +222,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
const basename = "options.zig";
// Hash contents to file name.
- var hash = b.cache.hash;
+ var hash = b.graph.cache.hash;
// Random bytes to make unique. Refresh this with new random bytes when
// implementation is modified in a non-backwards-compatible way.
hash.add(@as(u32, 0xad95e922));
@@ -301,27 +301,28 @@ test Options {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
- const host: std.Build.ResolvedTarget = .{
- .query = .{},
- .result = try std.zig.system.resolveTargetQuery(.{}),
- };
-
- var cache: std.Build.Cache = .{
- .gpa = arena.allocator(),
- .manifest_dir = std.fs.cwd(),
+ var graph: std.Build.Graph = .{
+ .arena = arena.allocator(),
+ .cache = .{
+ .gpa = arena.allocator(),
+ .manifest_dir = std.fs.cwd(),
+ },
+ .zig_exe = "test",
+ .env_map = std.process.EnvMap.init(arena.allocator()),
+ .global_cache_root = .{ .path = "test", .handle = std.fs.cwd() },
};
var builder = try std.Build.create(
- arena.allocator(),
- "test",
+ &graph,
.{ .path = "test", .handle = std.fs.cwd() },
.{ .path = "test", .handle = std.fs.cwd() },
- .{ .path = "test", .handle = std.fs.cwd() },
- host,
- &cache,
&.{},
);
- defer builder.destroy();
+
+ builder.host = .{
+ .query = .{},
+ .result = try std.zig.system.resolveTargetQuery(.{}),
+ };
const options = builder.addOptions();