| author | |
| committer | |
| log | 22a97cd235b5a2ffa9882c267b365c463b38e5ba |
| tree | 82f9feca1f1f9b276953d0d0a8a45c3130e475f9 |
| parent | 21a6a1b0f2d7241594a9aa123e48cf2e3ebaccb9 |
This is a partial revert of 105db13536b4dc2affe130cb8d2eee6c97c89bcd.
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.6 files changed, 22 insertions(+), 68 deletions(-)
lib/compiler/build_runner.zig+4-18| ... | ... | @@ -70,6 +70,10 @@ pub fn main() !void { |
| 70 | 70 | .zig_exe = zig_exe, |
| 71 | 71 | .env_map = try process.getEnvMap(arena), |
| 72 | 72 | .global_cache_root = global_cache_directory, |
| 73 | .host = .{ | |
| 74 | .query = .{}, | |
| 75 | .result = try std.zig.system.resolveTargetQuery(.{}), | |
| 76 | }, | |
| 73 | 77 | }; |
| 74 | 78 | |
| 75 | 79 | graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); |
| ... | ... | @@ -142,12 +146,6 @@ pub fn main() !void { |
| 142 | 146 | arg, text, |
| 143 | 147 | }); |
| 144 | 148 | }; |
| 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); | |
| 151 | 149 | } else if (mem.eql(u8, arg, "--prefix-lib-dir")) { |
| 152 | 150 | dir_list.lib_dir = nextArgOrFatal(args, &arg_idx); |
| 153 | 151 | } else if (mem.eql(u8, arg, "--prefix-exe-dir")) { |
| ... | ... | @@ -283,14 +281,6 @@ pub fn main() !void { |
| 283 | 281 | } |
| 284 | 282 | } |
| 285 | 283 | |
| 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 | ||
| 294 | 284 | const stderr = std.io.getStdErr(); |
| 295 | 285 | const ttyconf = get_tty_conf(color, stderr); |
| 296 | 286 | switch (ttyconf) { |
| ... | ... | @@ -1171,10 +1161,6 @@ fn usage(b: *std.Build, out_stream: anytype) !void { |
| 1171 | 1161 | \\ --sysroot [path] Set the system root directory (usually /) |
| 1172 | 1162 | \\ --libc [file] Provide a file which specifies libc paths |
| 1173 | 1163 | \\ |
| 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 | \\ | |
| 1178 | 1164 | \\ --system [pkgdir] Disable package fetching; enable all integrations |
| 1179 | 1165 | \\ -fsys=[name] Enable a system integration |
| 1180 | 1166 | \\ -fno-sys=[name] Disable a system integration |
lib/std/Build.zig+6-10| ... | ... | @@ -82,7 +82,7 @@ enable_wine: bool = false, |
| 82 | 82 | /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`. |
| 83 | 83 | glibc_runtimes_dir: ?[]const u8 = null, |
| 84 | 84 | |
| 85 | /// Information about the native target. Computed before build() is invoked. | |
| 85 | /// Deprecated. Use `b.graph.host`. | |
| 86 | 86 | host: ResolvedTarget, |
| 87 | 87 | |
| 88 | 88 | dep_prefix: []const u8 = "", |
| ... | ... | @@ -118,8 +118,9 @@ pub const Graph = struct { |
| 118 | 118 | zig_exe: [:0]const u8, |
| 119 | 119 | env_map: EnvMap, |
| 120 | 120 | global_cache_root: Cache.Directory, |
| 121 | host_query_options: std.Target.Query.ParseOptions = .{}, | |
| 122 | 121 | needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .{}, |
| 122 | /// Information about the native target. Computed before build() is invoked. | |
| 123 | host: ResolvedTarget, | |
| 123 | 124 | }; |
| 124 | 125 | |
| 125 | 126 | const AvailableDeps = []const struct { []const u8, []const u8 }; |
| ... | ... | @@ -297,7 +298,7 @@ pub fn create( |
| 297 | 298 | .zig_lib_dir = null, |
| 298 | 299 | .install_path = undefined, |
| 299 | 300 | .args = null, |
| 300 | .host = undefined, | |
| 301 | .host = graph.host, | |
| 301 | 302 | .modules = std.StringArrayHashMap(*Module).init(arena), |
| 302 | 303 | .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(arena), |
| 303 | 304 | .initialized_deps = initialized_deps, |
| ... | ... | @@ -2489,14 +2490,9 @@ pub const ResolvedTarget = struct { |
| 2489 | 2490 | /// various parts of the API. |
| 2490 | 2491 | pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget { |
| 2491 | 2492 | 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; | |
| 2498 | 2495 | } |
| 2499 | ||
| 2500 | 2496 | return .{ |
| 2501 | 2497 | .query = query, |
| 2502 | 2498 | .result = std.zig.system.resolveTargetQuery(query) catch |
lib/std/Build/Step/Compile.zig-10| ... | ... | @@ -1011,16 +1011,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1011 | 1011 | }; |
| 1012 | 1012 | try zig_args.append(cmd); |
| 1013 | 1013 | |
| 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 | ||
| 1024 | 1014 | if (b.reference_trace) |some| { |
| 1025 | 1015 | try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some})); |
| 1026 | 1016 | } |
lib/std/Build/Step/Options.zig+4-5| ... | ... | @@ -516,6 +516,10 @@ test Options { |
| 516 | 516 | .zig_exe = "test", |
| 517 | 517 | .env_map = std.process.EnvMap.init(arena.allocator()), |
| 518 | 518 | .global_cache_root = .{ .path = "test", .handle = std.fs.cwd() }, |
| 519 | .host = .{ | |
| 520 | .query = .{}, | |
| 521 | .result = try std.zig.system.resolveTargetQuery(.{}), | |
| 522 | }, | |
| 519 | 523 | }; |
| 520 | 524 | |
| 521 | 525 | var builder = try std.Build.create( |
| ... | ... | @@ -525,11 +529,6 @@ test Options { |
| 525 | 529 | &.{}, |
| 526 | 530 | ); |
| 527 | 531 | |
| 528 | builder.host = .{ | |
| 529 | .query = .{}, | |
| 530 | .result = try std.zig.system.resolveTargetQuery(.{}), | |
| 531 | }; | |
| 532 | ||
| 533 | 532 | const options = builder.addOptions(); |
| 534 | 533 | |
| 535 | 534 | const KeywordEnum = enum { |
lib/std/Target/Query.zig+7-4| ... | ... | @@ -362,12 +362,16 @@ pub fn isNativeAbi(self: Query) bool { |
| 362 | 362 | return self.os_tag == null and self.abi == null; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | pub fn isNative(self: Query) bool { | |
| 365 | pub fn isNativeTriple(self: Query) bool { | |
| 366 | 366 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | pub fn isNative(self: Query) bool { | |
| 370 | return self.isNativeTriple() and self.ofmt == null; | |
| 371 | } | |
| 372 | ||
| 369 | 373 | pub fn canDetectLibC(self: Query) bool { |
| 370 | if (self.isNative()) return true; | |
| 374 | if (self.isNativeOs()) return true; | |
| 371 | 375 | if (self.os_tag) |os| { |
| 372 | 376 | if (builtin.os.tag == .macos and os.isDarwin()) return true; |
| 373 | 377 | if (os == .linux and self.abi == .android) return true; |
| ... | ... | @@ -386,9 +390,8 @@ fn formatVersion(version: SemanticVersion, writer: anytype) !void { |
| 386 | 390 | } |
| 387 | 391 | |
| 388 | 392 | pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 { |
| 389 | if (self.isNative()) { | |
| 393 | if (self.isNativeTriple()) | |
| 390 | 394 | return allocator.dupe(u8, "native"); |
| 391 | } | |
| 392 | 395 | |
| 393 | 396 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; |
| 394 | 397 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; |
src/main.zig+1-21| ... | ... | @@ -985,9 +985,6 @@ fn buildOutputType( |
| 985 | 985 | .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena), |
| 986 | 986 | .link_objects = .{}, |
| 987 | 987 | .native_system_include_paths = &.{}, |
| 988 | .host_triple = null, | |
| 989 | .host_cpu = null, | |
| 990 | .host_dynamic_linker = null, | |
| 991 | 988 | }; |
| 992 | 989 | |
| 993 | 990 | // before arg parsing, check for the NO_COLOR environment variable |
| ... | ... | @@ -1285,12 +1282,6 @@ fn buildOutputType( |
| 1285 | 1282 | mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]); |
| 1286 | 1283 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { |
| 1287 | 1284 | 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(); | |
| 1294 | 1285 | } else if (mem.eql(u8, arg, "--sysroot")) { |
| 1295 | 1286 | const next_arg = args_iter.nextOrFatal(); |
| 1296 | 1287 | create_module.sysroot = next_arg; |
| ... | ... | @@ -3521,9 +3512,6 @@ const CreateModule = struct { |
| 3521 | 3512 | each_lib_rpath: ?bool, |
| 3522 | 3513 | libc_paths_file: ?[]const u8, |
| 3523 | 3514 | link_objects: std.ArrayListUnmanaged(Compilation.LinkObject), |
| 3524 | host_triple: ?[]const u8, | |
| 3525 | host_cpu: ?[]const u8, | |
| 3526 | host_dynamic_linker: ?[]const u8, | |
| 3527 | 3515 | }; |
| 3528 | 3516 | |
| 3529 | 3517 | fn createModule( |
| ... | ... | @@ -3605,15 +3593,7 @@ fn createModule( |
| 3605 | 3593 | } |
| 3606 | 3594 | |
| 3607 | 3595 | 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); | |
| 3617 | 3597 | break :t .{ |
| 3618 | 3598 | .result = target, |
| 3619 | 3599 | .is_native_os = target_query.isNativeOs(), |