Skip to content

Commit dbeda3e

Browse files
committed
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.
1 parent 7f85595 commit dbeda3e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main.zig

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ fn buildOutputType(
967967
.libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
968968
.link_objects = .{},
969969
.native_system_include_paths = &.{},
970+
.host_triple = null,
971+
.host_cpu = null,
972+
.host_dynamic_linker = null,
970973
};
971974

972975
// before arg parsing, check for the NO_COLOR environment variable
@@ -1258,6 +1261,12 @@ fn buildOutputType(
12581261
mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]);
12591262
} else if (mem.eql(u8, arg, "--dynamic-linker")) {
12601263
create_module.dynamic_linker = args_iter.nextOrFatal();
1264+
} else if (mem.eql(u8, arg, "--host-target")) {
1265+
create_module.host_triple = args_iter.nextOrFatal();
1266+
} else if (mem.eql(u8, arg, "--host-cpu")) {
1267+
create_module.host_cpu = args_iter.nextOrFatal();
1268+
} else if (mem.eql(u8, arg, "--host-dynamic-linker")) {
1269+
create_module.host_dynamic_linker = args_iter.nextOrFatal();
12611270
} else if (mem.eql(u8, arg, "--sysroot")) {
12621271
const next_arg = args_iter.nextOrFatal();
12631272
create_module.sysroot = next_arg;
@@ -3447,6 +3456,9 @@ const CreateModule = struct {
34473456
each_lib_rpath: ?bool,
34483457
libc_paths_file: ?[]const u8,
34493458
link_objects: std.ArrayListUnmanaged(Compilation.LinkObject),
3459+
host_triple: ?[]const u8,
3460+
host_cpu: ?[]const u8,
3461+
host_dynamic_linker: ?[]const u8,
34503462
};
34513463

34523464
fn createModule(
@@ -3531,7 +3543,15 @@ fn createModule(
35313543
}
35323544

35333545
const target_query = parseTargetQueryOrReportFatalError(arena, target_parse_options);
3534-
const target = resolveTargetQueryOrFatal(target_query);
3546+
const adjusted_target_query = a: {
3547+
if (!target_query.isNative()) break :a target_query;
3548+
if (create_module.host_triple) |triple| target_parse_options.arch_os_abi = triple;
3549+
if (create_module.host_cpu) |cpu| target_parse_options.cpu_features = cpu;
3550+
if (create_module.host_dynamic_linker) |dl| target_parse_options.dynamic_linker = dl;
3551+
break :a parseTargetQueryOrReportFatalError(arena, target_parse_options);
3552+
};
3553+
3554+
const target = resolveTargetQueryOrFatal(adjusted_target_query);
35353555
break :t .{
35363556
.result = target,
35373557
.is_native_os = target_query.isNativeOs(),

0 commit comments

Comments
 (0)