Skip to content

Commit 22a97cd

Browse files
committed
std.Build: revert --host-target, --host-cpu, --host-dynamic-linker
This is a partial revert of 105db13. As we learned from Void Linux packaging, these options are not actually helpful since the distribution package manager may very well want to cross-compile the packages that it is building. So, let's not overcomplicate things. There are already the standard options: -Dtarget, -Dcpu, and -Ddynamic-linker. These options are generally provided when the project generates machine code artifacts, however, there may be a project that does no such thing, in which case it makes sense for these options to be missing. The Zig Build System is a general-purpose build system, after all.
1 parent 21a6a1b commit 22a97cd

File tree

6 files changed

+22
-68
lines changed

6 files changed

+22
-68
lines changed

lib/compiler/build_runner.zig

+4-18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ pub fn main() !void {
7070
.zig_exe = zig_exe,
7171
.env_map = try process.getEnvMap(arena),
7272
.global_cache_root = global_cache_directory,
73+
.host = .{
74+
.query = .{},
75+
.result = try std.zig.system.resolveTargetQuery(.{}),
76+
},
7377
};
7478

7579
graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() });
@@ -142,12 +146,6 @@ pub fn main() !void {
142146
arg, text,
143147
});
144148
};
145-
} else if (mem.eql(u8, arg, "--host-target")) {
146-
graph.host_query_options.arch_os_abi = nextArgOrFatal(args, &arg_idx);
147-
} else if (mem.eql(u8, arg, "--host-cpu")) {
148-
graph.host_query_options.cpu_features = nextArgOrFatal(args, &arg_idx);
149-
} else if (mem.eql(u8, arg, "--host-dynamic-linker")) {
150-
graph.host_query_options.dynamic_linker = nextArgOrFatal(args, &arg_idx);
151149
} else if (mem.eql(u8, arg, "--prefix-lib-dir")) {
152150
dir_list.lib_dir = nextArgOrFatal(args, &arg_idx);
153151
} else if (mem.eql(u8, arg, "--prefix-exe-dir")) {
@@ -283,14 +281,6 @@ pub fn main() !void {
283281
}
284282
}
285283

286-
const host_query = std.Build.parseTargetQuery(graph.host_query_options) catch |err| switch (err) {
287-
error.ParseFailed => process.exit(1),
288-
};
289-
builder.host = .{
290-
.query = .{},
291-
.result = try std.zig.system.resolveTargetQuery(host_query),
292-
};
293-
294284
const stderr = std.io.getStdErr();
295285
const ttyconf = get_tty_conf(color, stderr);
296286
switch (ttyconf) {
@@ -1171,10 +1161,6 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
11711161
\\ --sysroot [path] Set the system root directory (usually /)
11721162
\\ --libc [file] Provide a file which specifies libc paths
11731163
\\
1174-
\\ --host-target [triple] Use the provided target as the host
1175-
\\ --host-cpu [cpu] Use the provided CPU as the host
1176-
\\ --host-dynamic-linker [path] Use the provided dynamic linker as the host
1177-
\\
11781164
\\ --system [pkgdir] Disable package fetching; enable all integrations
11791165
\\ -fsys=[name] Enable a system integration
11801166
\\ -fno-sys=[name] Disable a system integration

lib/std/Build.zig

+6-10
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enable_wine: bool = false,
8282
/// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
8383
glibc_runtimes_dir: ?[]const u8 = null,
8484

85-
/// Information about the native target. Computed before build() is invoked.
85+
/// Deprecated. Use `b.graph.host`.
8686
host: ResolvedTarget,
8787

8888
dep_prefix: []const u8 = "",
@@ -118,8 +118,9 @@ pub const Graph = struct {
118118
zig_exe: [:0]const u8,
119119
env_map: EnvMap,
120120
global_cache_root: Cache.Directory,
121-
host_query_options: std.Target.Query.ParseOptions = .{},
122121
needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .{},
122+
/// Information about the native target. Computed before build() is invoked.
123+
host: ResolvedTarget,
123124
};
124125

125126
const AvailableDeps = []const struct { []const u8, []const u8 };
@@ -297,7 +298,7 @@ pub fn create(
297298
.zig_lib_dir = null,
298299
.install_path = undefined,
299300
.args = null,
300-
.host = undefined,
301+
.host = graph.host,
301302
.modules = std.StringArrayHashMap(*Module).init(arena),
302303
.named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(arena),
303304
.initialized_deps = initialized_deps,
@@ -2489,14 +2490,9 @@ pub const ResolvedTarget = struct {
24892490
/// various parts of the API.
24902491
pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget {
24912492
if (query.isNative()) {
2492-
var adjusted = b.host;
2493-
if (query.ofmt) |ofmt| {
2494-
adjusted.query.ofmt = ofmt;
2495-
adjusted.result.ofmt = ofmt;
2496-
}
2497-
return adjusted;
2493+
// Hot path. This is faster than querying the native CPU and OS again.
2494+
return b.graph.host;
24982495
}
2499-
25002496
return .{
25012497
.query = query,
25022498
.result = std.zig.system.resolveTargetQuery(query) catch

lib/std/Build/Step/Compile.zig

-10
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
10111011
};
10121012
try zig_args.append(cmd);
10131013

1014-
if (!mem.eql(u8, b.graph.host_query_options.arch_os_abi, "native")) {
1015-
try zig_args.appendSlice(&.{ "--host-target", b.graph.host_query_options.arch_os_abi });
1016-
}
1017-
if (b.graph.host_query_options.cpu_features) |cpu| {
1018-
try zig_args.appendSlice(&.{ "--host-cpu", cpu });
1019-
}
1020-
if (b.graph.host_query_options.dynamic_linker) |dl| {
1021-
try zig_args.appendSlice(&.{ "--host-dynamic-linker", dl });
1022-
}
1023-
10241014
if (b.reference_trace) |some| {
10251015
try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some}));
10261016
}

lib/std/Build/Step/Options.zig

+4-5
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ test Options {
516516
.zig_exe = "test",
517517
.env_map = std.process.EnvMap.init(arena.allocator()),
518518
.global_cache_root = .{ .path = "test", .handle = std.fs.cwd() },
519+
.host = .{
520+
.query = .{},
521+
.result = try std.zig.system.resolveTargetQuery(.{}),
522+
},
519523
};
520524

521525
var builder = try std.Build.create(
@@ -525,11 +529,6 @@ test Options {
525529
&.{},
526530
);
527531

528-
builder.host = .{
529-
.query = .{},
530-
.result = try std.zig.system.resolveTargetQuery(.{}),
531-
};
532-
533532
const options = builder.addOptions();
534533

535534
const KeywordEnum = enum {

lib/std/Target/Query.zig

+7-4
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,16 @@ pub fn isNativeAbi(self: Query) bool {
362362
return self.os_tag == null and self.abi == null;
363363
}
364364

365-
pub fn isNative(self: Query) bool {
365+
pub fn isNativeTriple(self: Query) bool {
366366
return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
367367
}
368368

369+
pub fn isNative(self: Query) bool {
370+
return self.isNativeTriple() and self.ofmt == null;
371+
}
372+
369373
pub fn canDetectLibC(self: Query) bool {
370-
if (self.isNative()) return true;
374+
if (self.isNativeOs()) return true;
371375
if (self.os_tag) |os| {
372376
if (builtin.os.tag == .macos and os.isDarwin()) return true;
373377
if (os == .linux and self.abi == .android) return true;
@@ -386,9 +390,8 @@ fn formatVersion(version: SemanticVersion, writer: anytype) !void {
386390
}
387391

388392
pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 {
389-
if (self.isNative()) {
393+
if (self.isNativeTriple())
390394
return allocator.dupe(u8, "native");
391-
}
392395

393396
const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
394397
const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";

src/main.zig

+1-21
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,6 @@ fn buildOutputType(
985985
.libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
986986
.link_objects = .{},
987987
.native_system_include_paths = &.{},
988-
.host_triple = null,
989-
.host_cpu = null,
990-
.host_dynamic_linker = null,
991988
};
992989

993990
// before arg parsing, check for the NO_COLOR environment variable
@@ -1285,12 +1282,6 @@ fn buildOutputType(
12851282
mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]);
12861283
} else if (mem.eql(u8, arg, "--dynamic-linker")) {
12871284
create_module.dynamic_linker = args_iter.nextOrFatal();
1288-
} else if (mem.eql(u8, arg, "--host-target")) {
1289-
create_module.host_triple = args_iter.nextOrFatal();
1290-
} else if (mem.eql(u8, arg, "--host-cpu")) {
1291-
create_module.host_cpu = args_iter.nextOrFatal();
1292-
} else if (mem.eql(u8, arg, "--host-dynamic-linker")) {
1293-
create_module.host_dynamic_linker = args_iter.nextOrFatal();
12941285
} else if (mem.eql(u8, arg, "--sysroot")) {
12951286
const next_arg = args_iter.nextOrFatal();
12961287
create_module.sysroot = next_arg;
@@ -3521,9 +3512,6 @@ const CreateModule = struct {
35213512
each_lib_rpath: ?bool,
35223513
libc_paths_file: ?[]const u8,
35233514
link_objects: std.ArrayListUnmanaged(Compilation.LinkObject),
3524-
host_triple: ?[]const u8,
3525-
host_cpu: ?[]const u8,
3526-
host_dynamic_linker: ?[]const u8,
35273515
};
35283516

35293517
fn createModule(
@@ -3605,15 +3593,7 @@ fn createModule(
36053593
}
36063594

36073595
const target_query = std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options);
3608-
const adjusted_target_query = a: {
3609-
if (!target_query.isNative()) break :a target_query;
3610-
if (create_module.host_triple) |triple| target_parse_options.arch_os_abi = triple;
3611-
if (create_module.host_cpu) |cpu| target_parse_options.cpu_features = cpu;
3612-
if (create_module.host_dynamic_linker) |dl| target_parse_options.dynamic_linker = dl;
3613-
break :a std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options);
3614-
};
3615-
3616-
const target = std.zig.resolveTargetQueryOrFatal(adjusted_target_query);
3596+
const target = std.zig.resolveTargetQueryOrFatal(target_query);
36173597
break :t .{
36183598
.result = target,
36193599
.is_native_os = target_query.isNativeOs(),

0 commit comments

Comments
 (0)