| 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,6 +70,10 @@ pub fn main() !void { |
| 70 | .zig_exe = zig_exe, | 70 | .zig_exe = zig_exe, |
| 71 | .env_map = try process.getEnvMap(arena), | 71 | .env_map = try process.getEnvMap(arena), |
| 72 | .global_cache_root = global_cache_directory, | 72 | .global_cache_root = global_cache_directory, |
| 73 | .host = .{ | ||
| 74 | .query = .{}, | ||
| 75 | .result = try std.zig.system.resolveTargetQuery(.{}), | ||
| 76 | }, | ||
| 73 | }; | 77 | }; |
| 74 | 78 | ||
| 75 | graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); | 79 | graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); |
| ... | @@ -142,12 +146,6 @@ pub fn main() !void { | ... | @@ -142,12 +146,6 @@ pub fn main() !void { |
| 142 | arg, text, | 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 | } else if (mem.eql(u8, arg, "--prefix-lib-dir")) { | 149 | } else if (mem.eql(u8, arg, "--prefix-lib-dir")) { |
| 152 | dir_list.lib_dir = nextArgOrFatal(args, &arg_idx); | 150 | dir_list.lib_dir = nextArgOrFatal(args, &arg_idx); |
| 153 | } else if (mem.eql(u8, arg, "--prefix-exe-dir")) { | 151 | } else if (mem.eql(u8, arg, "--prefix-exe-dir")) { |
| ... | @@ -283,14 +281,6 @@ pub fn main() !void { | ... | @@ -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 | const stderr = std.io.getStdErr(); | 284 | const stderr = std.io.getStdErr(); |
| 295 | const ttyconf = get_tty_conf(color, stderr); | 285 | const ttyconf = get_tty_conf(color, stderr); |
| 296 | switch (ttyconf) { | 286 | switch (ttyconf) { |
| ... | @@ -1171,10 +1161,6 @@ fn usage(b: *std.Build, out_stream: anytype) !void { | ... | @@ -1171,10 +1161,6 @@ fn usage(b: *std.Build, out_stream: anytype) !void { |
| 1171 | \\ --sysroot [path] Set the system root directory (usually /) | 1161 | \\ --sysroot [path] Set the system root directory (usually /) |
| 1172 | \\ --libc [file] Provide a file which specifies libc paths | 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 | \\ --system [pkgdir] Disable package fetching; enable all integrations | 1164 | \\ --system [pkgdir] Disable package fetching; enable all integrations |
| 1179 | \\ -fsys=[name] Enable a system integration | 1165 | \\ -fsys=[name] Enable a system integration |
| 1180 | \\ -fno-sys=[name] Disable a system integration | 1166 | \\ -fno-sys=[name] Disable a system integration |
lib/std/Build.zig+6-10| ... | @@ -82,7 +82,7 @@ enable_wine: bool = false, | ... | @@ -82,7 +82,7 @@ enable_wine: bool = false, |
| 82 | /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`. | 82 | /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`. |
| 83 | glibc_runtimes_dir: ?[]const u8 = null, | 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 | host: ResolvedTarget, | 86 | host: ResolvedTarget, |
| 87 | 87 | ||
| 88 | dep_prefix: []const u8 = "", | 88 | dep_prefix: []const u8 = "", |
| ... | @@ -118,8 +118,9 @@ pub const Graph = struct { | ... | @@ -118,8 +118,9 @@ pub const Graph = struct { |
| 118 | zig_exe: [:0]const u8, | 118 | zig_exe: [:0]const u8, |
| 119 | env_map: EnvMap, | 119 | env_map: EnvMap, |
| 120 | global_cache_root: Cache.Directory, | 120 | global_cache_root: Cache.Directory, |
| 121 | host_query_options: std.Target.Query.ParseOptions = .{}, | ||
| 122 | needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .{}, | 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 | const AvailableDeps = []const struct { []const u8, []const u8 }; | 126 | const AvailableDeps = []const struct { []const u8, []const u8 }; |
| ... | @@ -297,7 +298,7 @@ pub fn create( | ... | @@ -297,7 +298,7 @@ pub fn create( |
| 297 | .zig_lib_dir = null, | 298 | .zig_lib_dir = null, |
| 298 | .install_path = undefined, | 299 | .install_path = undefined, |
| 299 | .args = null, | 300 | .args = null, |
| 300 | .host = undefined, | 301 | .host = graph.host, |
| 301 | .modules = std.StringArrayHashMap(*Module).init(arena), | 302 | .modules = std.StringArrayHashMap(*Module).init(arena), |
| 302 | .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(arena), | 303 | .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(arena), |
| 303 | .initialized_deps = initialized_deps, | 304 | .initialized_deps = initialized_deps, |
| ... | @@ -2489,14 +2490,9 @@ pub const ResolvedTarget = struct { | ... | @@ -2489,14 +2490,9 @@ pub const ResolvedTarget = struct { |
| 2489 | /// various parts of the API. | 2490 | /// various parts of the API. |
| 2490 | pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget { | 2491 | pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget { |
| 2491 | if (query.isNative()) { | 2492 | if (query.isNative()) { |
| 2492 | var adjusted = b.host; | 2493 | // Hot path. This is faster than querying the native CPU and OS again. |
| 2493 | if (query.ofmt) |ofmt| { | 2494 | return b.graph.host; |
| 2494 | adjusted.query.ofmt = ofmt; | ||
| 2495 | adjusted.result.ofmt = ofmt; | ||
| 2496 | } | ||
| 2497 | return adjusted; | ||
| 2498 | } | 2495 | } |
| 2499 | |||
| 2500 | return .{ | 2496 | return .{ |
| 2501 | .query = query, | 2497 | .query = query, |
| 2502 | .result = std.zig.system.resolveTargetQuery(query) catch | 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,16 +1011,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1011 | }; | 1011 | }; |
| 1012 | try zig_args.append(cmd); | 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 | if (b.reference_trace) |some| { | 1014 | if (b.reference_trace) |some| { |
| 1025 | try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some})); | 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,6 +516,10 @@ test Options { |
| 516 | .zig_exe = "test", | 516 | .zig_exe = "test", |
| 517 | .env_map = std.process.EnvMap.init(arena.allocator()), | 517 | .env_map = std.process.EnvMap.init(arena.allocator()), |
| 518 | .global_cache_root = .{ .path = "test", .handle = std.fs.cwd() }, | 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 | var builder = try std.Build.create( | 525 | var builder = try std.Build.create( |
| ... | @@ -525,11 +529,6 @@ test Options { | ... | @@ -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 | const options = builder.addOptions(); | 532 | const options = builder.addOptions(); |
| 534 | 533 | ||
| 535 | const KeywordEnum = enum { | 534 | const KeywordEnum = enum { |
lib/std/Target/Query.zig+7-4| ... | @@ -362,12 +362,16 @@ pub fn isNativeAbi(self: Query) bool { | ... | @@ -362,12 +362,16 @@ pub fn isNativeAbi(self: Query) bool { |
| 362 | return self.os_tag == null and self.abi == null; | 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 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); | 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 | pub fn canDetectLibC(self: Query) bool { | 373 | pub fn canDetectLibC(self: Query) bool { |
| 370 | if (self.isNative()) return true; | 374 | if (self.isNativeOs()) return true; |
| 371 | if (self.os_tag) |os| { | 375 | if (self.os_tag) |os| { |
| 372 | if (builtin.os.tag == .macos and os.isDarwin()) return true; | 376 | if (builtin.os.tag == .macos and os.isDarwin()) return true; |
| 373 | if (os == .linux and self.abi == .android) return true; | 377 | if (os == .linux and self.abi == .android) return true; |
| ... | @@ -386,9 +390,8 @@ fn formatVersion(version: SemanticVersion, writer: anytype) !void { | ... | @@ -386,9 +390,8 @@ fn formatVersion(version: SemanticVersion, writer: anytype) !void { |
| 386 | } | 390 | } |
| 387 | 391 | ||
| 388 | pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 { | 392 | pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 { |
| 389 | if (self.isNative()) { | 393 | if (self.isNativeTriple()) |
| 390 | return allocator.dupe(u8, "native"); | 394 | return allocator.dupe(u8, "native"); |
| 391 | } | ||
| 392 | 395 | ||
| 393 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; | 396 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; |
| 394 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; | 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,9 +985,6 @@ fn buildOutputType( |
| 985 | .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena), | 985 | .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena), |
| 986 | .link_objects = .{}, | 986 | .link_objects = .{}, |
| 987 | .native_system_include_paths = &.{}, | 987 | .native_system_include_paths = &.{}, |
| 988 | .host_triple = null, | ||
| 989 | .host_cpu = null, | ||
| 990 | .host_dynamic_linker = null, | ||
| 991 | }; | 988 | }; |
| 992 | 989 | ||
| 993 | // before arg parsing, check for the NO_COLOR environment variable | 990 | // before arg parsing, check for the NO_COLOR environment variable |
| ... | @@ -1285,12 +1282,6 @@ fn buildOutputType( | ... | @@ -1285,12 +1282,6 @@ fn buildOutputType( |
| 1285 | mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]); | 1282 | mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]); |
| 1286 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { | 1283 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { |
| 1287 | create_module.dynamic_linker = args_iter.nextOrFatal(); | 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 | } else if (mem.eql(u8, arg, "--sysroot")) { | 1285 | } else if (mem.eql(u8, arg, "--sysroot")) { |
| 1295 | const next_arg = args_iter.nextOrFatal(); | 1286 | const next_arg = args_iter.nextOrFatal(); |
| 1296 | create_module.sysroot = next_arg; | 1287 | create_module.sysroot = next_arg; |
| ... | @@ -3521,9 +3512,6 @@ const CreateModule = struct { | ... | @@ -3521,9 +3512,6 @@ const CreateModule = struct { |
| 3521 | each_lib_rpath: ?bool, | 3512 | each_lib_rpath: ?bool, |
| 3522 | libc_paths_file: ?[]const u8, | 3513 | libc_paths_file: ?[]const u8, |
| 3523 | link_objects: std.ArrayListUnmanaged(Compilation.LinkObject), | 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 | fn createModule( | 3517 | fn createModule( |
| ... | @@ -3605,15 +3593,7 @@ fn createModule( | ... | @@ -3605,15 +3593,7 @@ fn createModule( |
| 3605 | } | 3593 | } |
| 3606 | 3594 | ||
| 3607 | const target_query = std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options); | 3595 | const target_query = std.zig.parseTargetQueryOrReportFatalError(arena, target_parse_options); |
| 3608 | const adjusted_target_query = a: { | 3596 | const target = std.zig.resolveTargetQueryOrFatal(target_query); |
| 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); | ||
| 3617 | break :t .{ | 3597 | break :t .{ |
| 3618 | .result = target, | 3598 | .result = target, |
| 3619 | .is_native_os = target_query.isNativeOs(), | 3599 | .is_native_os = target_query.isNativeOs(), |