| author | |
| committer | |
| log | b92e30ff0bd2b77a486451b21d17666a311407f3 |
| tree | cd2504c6815b27486e554c2541d4496d7e8f91ab |
| parent | f5613a0e3589fcca51411ce379f3c90eace99fa6 |
This change is seemingly insignificant but I actually agonized over this
for three days. Some other things I considered:
* (status quo in master branch) make Compile step creation functions
accept a Target.Query and delete the ResolvedTarget struct.
- downside: redundantly resolve target queries many times
* same as before but additionally add a hash map to cache target query
resolutions.
- downside: now there is a hash map that doesn't actually need to
exist, just to make the API more ergonomic.
* add is_native_os and is_native_abi fields to std.Target and use it
directly as the result of resolving a target query.
- downside: they really don't belong there. They would be available
as comptime booleans via `@import("builtin")` but they should not
be exposed that way.
With this change the downsides are:
* the option name of addExecutable and friends is `target` instead of
`resolved_target` matching the type name.
- upside: this does not break compatibility with existing build
scripts
* you likely end up seeing `target.result.cpu.arch` rather than
`target.cpu.arch`.
- upside: this is an improvement over `target.target.cpu.arch` which
it was before this commit.
- downside: `b.host.target` is now `b.host.result`.16 files changed, 43 insertions(+), 41 deletions(-)
build.zig+4-4| ... | ... | @@ -221,7 +221,7 @@ pub fn build(b: *std.Build) !void { |
| 221 | 221 | |
| 222 | 222 | test_step.dependOn(&exe.step); |
| 223 | 223 | |
| 224 | if (target.target.os.tag == .windows and target.target.abi == .gnu) { | |
| 224 | if (target.result.os.tag == .windows and target.result.abi == .gnu) { | |
| 225 | 225 | // LTO is currently broken on mingw, this can be removed when it's fixed. |
| 226 | 226 | exe.want_lto = false; |
| 227 | 227 | check_case_exe.want_lto = false; |
| ... | ... | @@ -347,7 +347,7 @@ pub fn build(b: *std.Build) !void { |
| 347 | 347 | try addStaticLlvmOptionsToExe(exe); |
| 348 | 348 | try addStaticLlvmOptionsToExe(check_case_exe); |
| 349 | 349 | } |
| 350 | if (target.target.os.tag == .windows) { | |
| 350 | if (target.result.os.tag == .windows) { | |
| 351 | 351 | inline for (.{ exe, check_case_exe }) |artifact| { |
| 352 | 352 | artifact.linkSystemLibrary("version"); |
| 353 | 353 | artifact.linkSystemLibrary("uuid"); |
| ... | ... | @@ -371,7 +371,7 @@ pub fn build(b: *std.Build) !void { |
| 371 | 371 | ); |
| 372 | 372 | |
| 373 | 373 | // On mingw, we need to opt into windows 7+ to get some features required by tracy. |
| 374 | const tracy_c_flags: []const []const u8 = if (target.target.os.tag == .windows and target.target.abi == .gnu) | |
| 374 | const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu) | |
| 375 | 375 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } |
| 376 | 376 | else |
| 377 | 377 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; |
| ... | ... | @@ -383,7 +383,7 @@ pub fn build(b: *std.Build) !void { |
| 383 | 383 | } |
| 384 | 384 | exe.linkLibC(); |
| 385 | 385 | |
| 386 | if (target.target.os.tag == .windows) { | |
| 386 | if (target.result.os.tag == .windows) { | |
| 387 | 387 | exe.linkSystemLibrary("dbghelp"); |
| 388 | 388 | exe.linkSystemLibrary("ws2_32"); |
| 389 | 389 | } |
lib/build_runner.zig+1-1| ... | ... | @@ -48,7 +48,7 @@ pub fn main() !void { |
| 48 | 48 | |
| 49 | 49 | const host: std.Build.ResolvedTarget = .{ |
| 50 | 50 | .query = .{}, |
| 51 | .target = try std.zig.system.resolveTargetQuery(.{}), | |
| 51 | .result = try std.zig.system.resolveTargetQuery(.{}), | |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | 54 | const build_root_directory: std.Build.Cache.Directory = .{ |
lib/std/Build.zig+2-2| ... | ... | @@ -2044,7 +2044,7 @@ pub fn hex64(x: u64) [16]u8 { |
| 2044 | 2044 | /// of the target are "native". This can apply to the CPU, the OS, or even the ABI. |
| 2045 | 2045 | pub const ResolvedTarget = struct { |
| 2046 | 2046 | query: Target.Query, |
| 2047 | target: Target, | |
| 2047 | result: Target, | |
| 2048 | 2048 | }; |
| 2049 | 2049 | |
| 2050 | 2050 | /// Converts a target query into a fully resolved target that can be passed to |
| ... | ... | @@ -2056,7 +2056,7 @@ pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget { |
| 2056 | 2056 | |
| 2057 | 2057 | return .{ |
| 2058 | 2058 | .query = query, |
| 2059 | .target = std.zig.system.resolveTargetQuery(query) catch | |
| 2059 | .result = std.zig.system.resolveTargetQuery(query) catch | |
| 2060 | 2060 | @panic("unable to resolve target query"), |
| 2061 | 2061 | }; |
| 2062 | 2062 | } |
lib/std/Build/Module.zig+5-5| ... | ... | @@ -10,7 +10,7 @@ root_source_file: ?LazyPath, |
| 10 | 10 | /// maintain step dependency edges. |
| 11 | 11 | import_table: std.StringArrayHashMapUnmanaged(*Module), |
| 12 | 12 | |
| 13 | target: ?std.Build.ResolvedTarget = null, | |
| 13 | resolved_target: ?std.Build.ResolvedTarget = null, | |
| 14 | 14 | optimize: ?std.builtin.OptimizeMode = null, |
| 15 | 15 | dwarf_format: ?std.dwarf.Format, |
| 16 | 16 | |
| ... | ... | @@ -192,7 +192,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St |
| 192 | 192 | .depending_steps = .{}, |
| 193 | 193 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, |
| 194 | 194 | .import_table = .{}, |
| 195 | .target = options.target, | |
| 195 | .resolved_target = options.target, | |
| 196 | 196 | .optimize = options.optimize, |
| 197 | 197 | .link_libc = options.link_libc, |
| 198 | 198 | .link_libcpp = options.link_libcpp, |
| ... | ... | @@ -627,7 +627,7 @@ pub fn appendZigProcessFlags( |
| 627 | 627 | try zig_args.append(@tagName(m.code_model)); |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | if (m.target) |*target| { | |
| 630 | if (m.resolved_target) |*target| { | |
| 631 | 631 | // Communicate the query via CLI since it's more compact. |
| 632 | 632 | if (!target.query.isNative()) { |
| 633 | 633 | try zig_args.appendSlice(&.{ |
| ... | ... | @@ -737,9 +737,9 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | fn requireKnownTarget(m: *Module) std.Target { |
| 740 | const resolved_target = m.target orelse | |
| 740 | const resolved_target = m.resolved_target orelse | |
| 741 | 741 | @panic("this API requires the Module to be created with a known 'target' field"); |
| 742 | return resolved_target.target; | |
| 742 | return resolved_target.result; | |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | const Module = @This(); |
lib/std/Build/Step/Compile.zig+3-3| ... | ... | @@ -251,7 +251,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 251 | 251 | else |
| 252 | 252 | owner.fmt("{s} ", .{name}); |
| 253 | 253 | |
| 254 | const target = options.root_module.target.?.target; | |
| 254 | const target = options.root_module.target.?.result; | |
| 255 | 255 | |
| 256 | 256 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ |
| 257 | 257 | switch (options.kind) { |
| ... | ... | @@ -954,7 +954,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 954 | 954 | try addFlag(&zig_args, "llvm", self.use_llvm); |
| 955 | 955 | try addFlag(&zig_args, "lld", self.use_lld); |
| 956 | 956 | |
| 957 | if (self.root_module.target.?.query.ofmt) |ofmt| { | |
| 957 | if (self.root_module.resolved_target.?.query.ofmt) |ofmt| { | |
| 958 | 958 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "-ofmt={s}", .{@tagName(ofmt)})); |
| 959 | 959 | } |
| 960 | 960 | |
| ... | ... | @@ -1845,5 +1845,5 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool { |
| 1845 | 1845 | |
| 1846 | 1846 | pub fn rootModuleTarget(c: *Compile) std.Target { |
| 1847 | 1847 | // The root module is always given a target, so we know this to be non-null. |
| 1848 | return c.root_module.target.?.target; | |
| 1848 | return c.root_module.resolved_target.?.result; | |
| 1849 | 1849 | } |
lib/std/Build/Step/Run.zig+8-6| ... | ... | @@ -678,8 +678,8 @@ fn runCommand( |
| 678 | 678 | |
| 679 | 679 | const need_cross_glibc = exe.rootModuleTarget().isGnuLibC() and |
| 680 | 680 | exe.is_linking_libc; |
| 681 | const other_target = exe.root_module.target.?.target; | |
| 682 | switch (std.zig.system.getExternalExecutor(b.host.target, &other_target, .{ | |
| 681 | const other_target = exe.root_module.resolved_target.?.result; | |
| 682 | switch (std.zig.system.getExternalExecutor(b.host.result, &other_target, .{ | |
| 683 | 683 | .qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null, |
| 684 | 684 | .link_libc = exe.is_linking_libc, |
| 685 | 685 | })) { |
| ... | ... | @@ -752,7 +752,7 @@ fn runCommand( |
| 752 | 752 | .bad_dl => |foreign_dl| { |
| 753 | 753 | if (allow_skip) return error.MakeSkipped; |
| 754 | 754 | |
| 755 | const host_dl = b.host.target.dynamic_linker.get() orelse "(none)"; | |
| 755 | const host_dl = b.host.result.dynamic_linker.get() orelse "(none)"; | |
| 756 | 756 | |
| 757 | 757 | return step.fail( |
| 758 | 758 | \\the host system is unable to execute binaries from the target |
| ... | ... | @@ -764,7 +764,7 @@ fn runCommand( |
| 764 | 764 | .bad_os_or_cpu => { |
| 765 | 765 | if (allow_skip) return error.MakeSkipped; |
| 766 | 766 | |
| 767 | const host_name = try b.host.target.zigTriple(b.allocator); | |
| 767 | const host_name = try b.host.result.zigTriple(b.allocator); | |
| 768 | 768 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); |
| 769 | 769 | |
| 770 | 770 | return step.fail("the host system ({s}) is unable to execute binaries from the target ({s})", .{ |
| ... | ... | @@ -1295,7 +1295,9 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { |
| 1295 | 1295 | while (it.next()) |item| { |
| 1296 | 1296 | const other = item.compile.?; |
| 1297 | 1297 | if (item.module == &other.root_module) { |
| 1298 | if (item.module.target.?.target.os.tag == .windows and other.isDynamicLibrary()) { | |
| 1298 | if (item.module.resolved_target.?.result.os.tag == .windows and | |
| 1299 | other.isDynamicLibrary()) | |
| 1300 | { | |
| 1299 | 1301 | addPathDir(self, fs.path.dirname(other.getEmittedBin().getPath(b)).?); |
| 1300 | 1302 | } |
| 1301 | 1303 | } |
| ... | ... | @@ -1314,7 +1316,7 @@ fn failForeign( |
| 1314 | 1316 | return error.MakeSkipped; |
| 1315 | 1317 | |
| 1316 | 1318 | const b = self.step.owner; |
| 1317 | const host_name = try b.host.target.zigTriple(b.allocator); | |
| 1319 | const host_name = try b.host.result.zigTriple(b.allocator); | |
| 1318 | 1320 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); |
| 1319 | 1321 | |
| 1320 | 1322 | return self.step.fail( |
test/link/elf.zig+1-1| ... | ... | @@ -1763,7 +1763,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1763 | 1763 | exe.addObject(g_o); |
| 1764 | 1764 | exe.addObject(h_o); |
| 1765 | 1765 | |
| 1766 | if (opts.target.target.isGnuLibC()) { | |
| 1766 | if (opts.target.result.isGnuLibC()) { | |
| 1767 | 1767 | // TODO I think we need to clarify our use of `-fPIC -fPIE` flags for different targets |
| 1768 | 1768 | exe.pie = true; |
| 1769 | 1769 | } |
test/link/link.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ pub const Options = struct { |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | 16 | pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step { |
| 17 | const target = opts.target.target.zigTriple(b.allocator) catch @panic("OOM"); | |
| 17 | const target = opts.target.result.zigTriple(b.allocator) catch @panic("OOM"); | |
| 18 | 18 | const optimize = @tagName(opts.optimize); |
| 19 | 19 | const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; |
| 20 | 20 | const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}", .{ |
test/link/macho/bugs/13056/build.zig+1-1| ... | ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | |
| 16 | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 18 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.target) orelse | |
| 18 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse | |
| 19 | 19 | @panic("macOS SDK is required to run the test"); |
| 20 | 20 | |
| 21 | 21 | const exe = b.addExecutable(.{ |
test/src/Cases.zig+5-5| ... | ... | @@ -467,7 +467,7 @@ fn addFromDirInner( |
| 467 | 467 | // Cross-product to get all possible test combinations |
| 468 | 468 | for (targets) |target_query| { |
| 469 | 469 | const resolved_target = b.resolveTargetQuery(target_query); |
| 470 | const target = resolved_target.target; | |
| 470 | const target = resolved_target.result; | |
| 471 | 471 | for (backends) |backend| { |
| 472 | 472 | if (backend == .stage2 and |
| 473 | 473 | target.cpu.arch != .wasm32 and target.cpu.arch != .x86_64) |
| ... | ... | @@ -647,8 +647,8 @@ pub fn lowerToBuildSteps( |
| 647 | 647 | parent_step.dependOn(&artifact.step); |
| 648 | 648 | }, |
| 649 | 649 | .Execution => |expected_stdout| no_exec: { |
| 650 | const run = if (case.target.target.ofmt == .c) run_step: { | |
| 651 | if (getExternalExecutor(host, &case.target.target, .{ .link_libc = true }) != .native) { | |
| 650 | const run = if (case.target.result.ofmt == .c) run_step: { | |
| 651 | if (getExternalExecutor(host, &case.target.result, .{ .link_libc = true }) != .native) { | |
| 652 | 652 | // We wouldn't be able to run the compiled C code. |
| 653 | 653 | break :no_exec; |
| 654 | 654 | } |
| ... | ... | @@ -667,7 +667,7 @@ pub fn lowerToBuildSteps( |
| 667 | 667 | "--", |
| 668 | 668 | "-lc", |
| 669 | 669 | "-target", |
| 670 | case.target.target.zigTriple(b.allocator) catch @panic("OOM"), | |
| 670 | case.target.result.zigTriple(b.allocator) catch @panic("OOM"), | |
| 671 | 671 | }); |
| 672 | 672 | run_c.addArtifactArg(artifact); |
| 673 | 673 | break :run_step run_c; |
| ... | ... | @@ -693,7 +693,7 @@ pub fn lowerToBuildSteps( |
| 693 | 693 | continue; // Pass test. |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | if (getExternalExecutor(host, &case.target.target, .{ .link_libc = true }) != .native) { | |
| 696 | if (getExternalExecutor(host, &case.target.result, .{ .link_libc = true }) != .native) { | |
| 697 | 697 | // We wouldn't be able to run the compiled C code. |
| 698 | 698 | continue; // Pass test. |
| 699 | 699 | } |
test/standalone/c_compiler/build.zig+1-1| ... | ... | @@ -42,7 +42,7 @@ fn add( |
| 42 | 42 | exe_cpp.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &[0][]const u8{} }); |
| 43 | 43 | exe_cpp.linkLibCpp(); |
| 44 | 44 | |
| 45 | switch (target.target.os.tag) { | |
| 45 | switch (target.result.os.tag) { | |
| 46 | 46 | .windows => { |
| 47 | 47 | // https://github.com/ziglang/zig/issues/8531 |
| 48 | 48 | exe_cpp.want_lto = false; |
test/standalone/compiler_rt_panic/build.zig+4-4| ... | ... | @@ -4,16 +4,16 @@ pub fn build(b: *std.Build) void { |
| 4 | 4 | const test_step = b.step("test", "Test it"); |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | const resolved_target = b.standardTargetOptions(.{}); | |
| 8 | const target = resolved_target.target; | |
| 7 | const target = b.standardTargetOptions(.{}); | |
| 9 | 8 | const optimize = b.standardOptimizeOption(.{}); |
| 10 | 9 | |
| 11 | if (target.ofmt != .elf or !(target.abi.isMusl() or target.abi.isGnu())) return; | |
| 10 | if (target.result.ofmt != .elf or !(target.result.abi.isMusl() or target.result.abi.isGnu())) | |
| 11 | return; | |
| 12 | 12 | |
| 13 | 13 | const exe = b.addExecutable(.{ |
| 14 | 14 | .name = "main", |
| 15 | 15 | .optimize = optimize, |
| 16 | .target = resolved_target, | |
| 16 | .target = target, | |
| 17 | 17 | }); |
| 18 | 18 | exe.linkLibC(); |
| 19 | 19 | exe.addCSourceFile(.{ |
test/standalone/ios/build.zig+1-1| ... | ... | @@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | .cpu_arch = .aarch64, |
| 13 | 13 | .os_tag = .ios, |
| 14 | 14 | }); |
| 15 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.target) orelse | |
| 15 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse | |
| 16 | 16 | @panic("no iOS SDK found"); |
| 17 | 17 | b.sysroot = sdk; |
| 18 | 18 |
test/standalone/self_exe_symlink/build.zig+1-1| ... | ... | @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { |
| 11 | 11 | |
| 12 | 12 | // The test requires getFdPath in order to to get the path of the |
| 13 | 13 | // File returned by openSelfExe |
| 14 | if (!std.os.isGetFdPathSupportedOnTarget(target.target.os)) return; | |
| 14 | if (!std.os.isGetFdPathSupportedOnTarget(target.result.os)) return; | |
| 15 | 15 | |
| 16 | 16 | const main = b.addExecutable(.{ |
| 17 | 17 | .name = "main", |
test/standalone/stack_iterator/build.zig+3-3| ... | ... | @@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void { |
| 22 | 22 | .root_source_file = .{ .path = "unwind.zig" }, |
| 23 | 23 | .target = target, |
| 24 | 24 | .optimize = optimize, |
| 25 | .unwind_tables = target.target.isDarwin(), | |
| 25 | .unwind_tables = target.result.isDarwin(), | |
| 26 | 26 | .omit_frame_pointer = false, |
| 27 | 27 | }); |
| 28 | 28 | |
| ... | ... | @@ -70,7 +70,7 @@ pub fn build(b: *std.Build) void { |
| 70 | 70 | .strip = false, |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | if (target.target.os.tag == .windows) | |
| 73 | if (target.result.os.tag == .windows) | |
| 74 | 74 | c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); |
| 75 | 75 | |
| 76 | 76 | c_shared_lib.addCSourceFile(.{ |
| ... | ... | @@ -84,7 +84,7 @@ pub fn build(b: *std.Build) void { |
| 84 | 84 | .root_source_file = .{ .path = "shared_lib_unwind.zig" }, |
| 85 | 85 | .target = target, |
| 86 | 86 | .optimize = optimize, |
| 87 | .unwind_tables = target.target.isDarwin(), | |
| 87 | .unwind_tables = target.result.isDarwin(), | |
| 88 | 88 | .omit_frame_pointer = true, |
| 89 | 89 | }); |
| 90 | 90 |
test/tests.zig+2-2| ... | ... | @@ -1043,7 +1043,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1043 | 1043 | continue; |
| 1044 | 1044 | |
| 1045 | 1045 | const resolved_target = b.resolveTargetQuery(test_target.target); |
| 1046 | const target = resolved_target.target; | |
| 1046 | const target = resolved_target.result; | |
| 1047 | 1047 | |
| 1048 | 1048 | if (options.skip_cross_glibc and !test_target.target.isNative() and |
| 1049 | 1049 | target.isGnuLibC() and test_target.link_libc == true) |
| ... | ... | @@ -1229,7 +1229,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S |
| 1229 | 1229 | if (skip_non_native and !c_abi_target.target.isNative()) continue; |
| 1230 | 1230 | |
| 1231 | 1231 | const resolved_target = b.resolveTargetQuery(c_abi_target.target); |
| 1232 | const target = resolved_target.target; | |
| 1232 | const target = resolved_target.result; | |
| 1233 | 1233 | |
| 1234 | 1234 | if (target.os.tag == .windows and target.cpu.arch == .aarch64) { |
| 1235 | 1235 | // https://github.com/ziglang/zig/issues/14908 |