authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-26 15:53:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-27 03:04:31+02:00
logd0c6ed189b334fa4ad60485724d59ad9a78b0046
tree0c2d2acefc49bf5b7c131367c3d52a681fd82ede
parent9c565509313cc497739d518e7bf2de69b1f195bb

Maker: fix Target deserialization

more disciplined Target / Query separation even though they're both serialized in the same struct

4 files changed, 76 insertions(+), 30 deletions(-)

lib/compiler/Maker/Step/Compile.zig+1-3
...@@ -1291,11 +1291,9 @@ fn appendModuleFlags(...@@ -1291,11 +1291,9 @@ fn appendModuleFlags(
12911291
1292 if (m.resolved_target.get(conf)) |resolved_target| {1292 if (m.resolved_target.get(conf)) |resolved_target| {
1293 // Communicate the query via CLI since it's more compact.1293 // Communicate the query via CLI since it's more compact.
1294 if (resolved_target.query.get(conf)) |compact_query| {1294 if (resolved_target.unwrapQuery(conf)) |query| {
1295 try zig_args.ensureUnusedCapacity(gpa, 6);1295 try zig_args.ensureUnusedCapacity(gpa, 6);
12961296
1297 const query = compact_query.unwrap(conf);
1298
1299 zig_args.appendAssumeCapacity("-target");1297 zig_args.appendAssumeCapacity("-target");
1300 zig_args.appendAssumeCapacity(try query.zigTriple(arena));1298 zig_args.appendAssumeCapacity(try query.zigTriple(arena));
13011299
lib/compiler/Maker/Step/Run.zig+1-2
...@@ -1823,8 +1823,7 @@ fn runCommand(...@@ -1823,8 +1823,7 @@ fn runCommand(
1823 }1823 }
1824 const root_module = producer.root_module.get(conf);1824 const root_module = producer.root_module.get(conf);
1825 const root_module_target = root_module.resolved_target.get(conf).?.result.get(conf);1825 const root_module_target = root_module.resolved_target.get(conf).?.result.get(conf);
1826 const other_target_query = root_module_target.unwrap(conf);1826 const root_target = root_module_target.unwrapTarget(conf);
1827 const root_target = std.zig.system.resolveTargetQuery(io, other_target_query) catch unreachable;
1828 const link_libc = maker.stepByIndex(producer_index).extended.compile.is_linking_libc;1827 const link_libc = maker.stepByIndex(producer_index).extended.compile.is_linking_libc;
18291828
1830 const host: std.Target = std.zig.system.resolveTargetQuery(io, .{}) catch |he| switch (he) {1829 const host: std.Target = std.zig.system.resolveTargetQuery(io, .{}) catch |he| switch (he) {
lib/compiler/Maker/Step/TranslateC.zig+5-4
...@@ -40,10 +40,11 @@ pub fn make(...@@ -40,10 +40,11 @@ pub fn make(
40 argv.appendAssumeCapacity("--global-cache-dir");40 argv.appendAssumeCapacity("--global-cache-dir");
41 argv.appendAssumeCapacity(graph.global_cache_root.path orelse ".");41 argv.appendAssumeCapacity(graph.global_cache_root.path orelse ".");
4242
43 if (conf_tc.target.get(conf).?.query.unwrap()) |compact_query| {43 if (conf_tc.target.get(conf)) |resolved_target| {
44 const query = compact_query.get(conf).unwrap(conf);44 if (resolved_target.unwrapQuery(conf)) |query| {
45 argv.appendAssumeCapacity("-target");45 argv.appendAssumeCapacity("-target");
46 argv.appendAssumeCapacity(try query.zigTriple(arena));46 argv.appendAssumeCapacity(try query.zigTriple(arena));
47 }
47 }48 }
4849
49 switch (conf_tc.flags.optimize) {50 switch (conf_tc.flags.optimize) {
lib/std/Build/Configuration.zig+69-21
...@@ -2144,6 +2144,33 @@ pub const ResolvedTarget = struct {...@@ -2144,6 +2144,33 @@ pub const ResolvedTarget = struct {
2144 return (unwrap(this) orelse return null).get(c);2144 return (unwrap(this) orelse return null).get(c);
2145 }2145 }
2146 };2146 };
2147
2148 pub fn unwrapQuery(rt: *const ResolvedTarget, c: *const Configuration) ?std.Target.Query {
2149 const tq = rt.query.get(c) orelse return null;
2150 const cpu_arch = tq.flags.cpu_arch.unwrap() orelse rt.result.get(c).flags.cpu_arch.unwrap().?;
2151 return .{
2152 .cpu_arch = cpu_arch,
2153 .cpu_model = switch (tq.flags.cpu_model) {
2154 .native => .native,
2155 .baseline => .baseline,
2156 .determined_by_arch_os => .determined_by_arch_os,
2157 .explicit => .{ .explicit = cpu_arch.parseCpuModel(tq.cpu_name.value.?.slice(c)).? },
2158 },
2159 .cpu_features_add = tq.cpu_features_add.value orelse .empty,
2160 .cpu_features_sub = tq.cpu_features_sub.value orelse .empty,
2161 .os_tag = tq.flags.os_tag.unwrap(),
2162 .os_version_min = tq.os_version_min.u.unwrap(c),
2163 .os_version_max = tq.os_version_max.u.unwrap(c),
2164 .glibc_version = if (tq.glibc_version.value) |s|
2165 std.SemanticVersion.parse(s.slice(c)) catch unreachable
2166 else
2167 null,
2168 .android_api_level = tq.android_api_level.value,
2169 .abi = tq.flags.abi.unwrap(),
2170 .dynamic_linker = if (tq.dynamic_linker.value) |s| .init(s.slice(c)) else null,
2171 .ofmt = tq.flags.object_format.unwrap(),
2172 };
2173 }
2147};2174};
21482175
2149pub const TargetQuery = struct {2176pub const TargetQuery = struct {
...@@ -2731,29 +2758,50 @@ pub const TargetQuery = struct {...@@ -2731,29 +2758,50 @@ pub const TargetQuery = struct {
2731 dynamic_linker: bool,2758 dynamic_linker: bool,
2732 };2759 };
27332760
2734 pub fn unwrap(tq: *const TargetQuery, c: *const Configuration) std.Target.Query {2761 pub fn unwrapTarget(tq: *const TargetQuery, c: *const Configuration) std.Target {
2735 const cpu_arch = tq.flags.cpu_arch.unwrap();2762 const cpu_arch = tq.flags.cpu_arch.unwrap().?;
2763 const os_tag = tq.flags.os_tag.unwrap().?;
2736 return .{2764 return .{
2737 .cpu_arch = cpu_arch,2765 .cpu = .{
2738 .cpu_model = switch (tq.flags.cpu_model) {2766 .arch = cpu_arch,
2739 .native => .native,2767 .model = cpu_arch.parseCpuModel(tq.cpu_name.value.?.slice(c)).?,
2740 .baseline => .baseline,2768 .features = tq.cpu_features_add.value.?,
2741 .determined_by_arch_os => .determined_by_arch_os,
2742 .explicit => .{ .explicit = cpu_arch.?.parseCpuModel(tq.cpu_name.value.?.slice(c)).? },
2743 },2769 },
2744 .cpu_features_add = tq.cpu_features_add.value orelse .empty,2770 .os = .{
2745 .cpu_features_sub = tq.cpu_features_sub.value orelse .empty,2771 .tag = os_tag,
2746 .os_tag = tq.flags.os_tag.unwrap(),2772 .version_range = switch (os_tag) {
2747 .os_version_min = tq.os_version_min.u.unwrap(c),2773 .linux => .{ .linux = .{
2748 .os_version_max = tq.os_version_max.u.unwrap(c),2774 .range = .{
2749 .glibc_version = if (tq.glibc_version.value) |s|2775 .min = tq.os_version_min.u.unwrap(c).?.semver,
2750 std.SemanticVersion.parse(s.slice(c)) catch unreachable2776 .max = tq.os_version_max.u.unwrap(c).?.semver,
2751 else2777 },
2752 null,2778 .glibc = std.SemanticVersion.parse(tq.glibc_version.value.?.slice(c)) catch unreachable,
2753 .android_api_level = tq.android_api_level.value,2779 .android = tq.android_api_level.value.?,
2754 .abi = tq.flags.abi.unwrap(),2780 } },
2755 .dynamic_linker = if (tq.dynamic_linker.value) |s| .init(s.slice(c)) else null,2781 .hurd => .{ .hurd = .{
2756 .ofmt = tq.flags.object_format.unwrap(),2782 .range = .{
2783 .min = tq.os_version_min.u.unwrap(c).?.semver,
2784 .max = tq.os_version_max.u.unwrap(c).?.semver,
2785 },
2786 .glibc = std.SemanticVersion.parse(tq.glibc_version.value.?.slice(c)) catch unreachable,
2787 } },
2788 .windows => .{ .windows = .{
2789 .min = tq.os_version_min.u.unwrap(c).?.windows,
2790 .max = tq.os_version_max.u.unwrap(c).?.windows,
2791 } },
2792 else => switch (tq.os_version_min.u.unwrap(c).?) {
2793 .none => .{ .none = {} },
2794 .semver => |min| .{ .semver = .{
2795 .min = min,
2796 .max = tq.os_version_max.u.unwrap(c).?.semver,
2797 } },
2798 .windows => unreachable,
2799 },
2800 },
2801 },
2802 .abi = tq.flags.abi.unwrap().?,
2803 .ofmt = tq.flags.object_format.unwrap().?,
2804 .dynamic_linker = .init(if (tq.dynamic_linker.value) |s| s.slice(c) else null),
2757 };2805 };
2758 }2806 }
2759};2807};