aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-02-01 15:41:41 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-02-02 20:43:01 -0700
commitb3596d72b07880a49228a5756d509ad51100a53a (patch)
tree6799a453d3fa6e01e59c8f9b01ba08a62786f3da /src/main.zig
parent8f867eaf84a2c270a2d1eb7208730519036eb364 (diff)
downloadzig-b3596d72b07880a49228a5756d509ad51100a53a.tar.gz
zig-b3596d72b07880a49228a5756d509ad51100a53a.zip
CLI: add --host-target, --host-cpu, and --host-dynamic-linker
These are advanced options that make it possible to simultaneously target the "host" computer, while overriding assumptions about the host computer such as what CPU features are available, or what OS version range to target. This is useful only for the case of integrating with system package manager builds which want to pretend the host is also the target.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig
index e795666941..a13e7b1fab 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -969,6 +969,9 @@ fn buildOutputType(
.libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
.link_objects = .{},
.native_system_include_paths = &.{},
+ .host_triple = null,
+ .host_cpu = null,
+ .host_dynamic_linker = null,
};
// before arg parsing, check for the NO_COLOR environment variable
@@ -1262,6 +1265,12 @@ fn buildOutputType(
mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]);
} else if (mem.eql(u8, arg, "--dynamic-linker")) {
create_module.dynamic_linker = args_iter.nextOrFatal();
+ } else if (mem.eql(u8, arg, "--host-target")) {
+ create_module.host_triple = args_iter.nextOrFatal();
+ } else if (mem.eql(u8, arg, "--host-cpu")) {
+ create_module.host_cpu = args_iter.nextOrFatal();
+ } else if (mem.eql(u8, arg, "--host-dynamic-linker")) {
+ create_module.host_dynamic_linker = args_iter.nextOrFatal();
} else if (mem.eql(u8, arg, "--sysroot")) {
const next_arg = args_iter.nextOrFatal();
create_module.sysroot = next_arg;
@@ -3455,6 +3464,9 @@ const CreateModule = struct {
each_lib_rpath: ?bool,
libc_paths_file: ?[]const u8,
link_objects: std.ArrayListUnmanaged(Compilation.LinkObject),
+ host_triple: ?[]const u8,
+ host_cpu: ?[]const u8,
+ host_dynamic_linker: ?[]const u8,
};
fn createModule(
@@ -3539,7 +3551,15 @@ fn createModule(
}
const target_query = parseTargetQueryOrReportFatalError(arena, target_parse_options);
- const target = resolveTargetQueryOrFatal(target_query);
+ const adjusted_target_query = a: {
+ if (!target_query.isNative()) break :a target_query;
+ if (create_module.host_triple) |triple| target_parse_options.arch_os_abi = triple;
+ if (create_module.host_cpu) |cpu| target_parse_options.cpu_features = cpu;
+ if (create_module.host_dynamic_linker) |dl| target_parse_options.dynamic_linker = dl;
+ break :a parseTargetQueryOrReportFatalError(arena, target_parse_options);
+ };
+
+ const target = resolveTargetQueryOrFatal(adjusted_target_query);
break :t .{
.result = target,
.is_native_os = target_query.isNativeOs(),