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(
12911291
12921292 if (m.resolved_target.get(conf)) |resolved_target| {
12931293 // 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| {
12951295 try zig_args.ensureUnusedCapacity(gpa, 6);
12961296
1297 const query = compact_query.unwrap(conf);
1298
12991297 zig_args.appendAssumeCapacity("-target");
13001298 zig_args.appendAssumeCapacity(try query.zigTriple(arena));
13011299
lib/compiler/Maker/Step/Run.zig+1-2
......@@ -1823,8 +1823,7 @@ fn runCommand(
18231823 }
18241824 const root_module = producer.root_module.get(conf);
18251825 const root_module_target = root_module.resolved_target.get(conf).?.result.get(conf);
1826 const other_target_query = root_module_target.unwrap(conf);
1827 const root_target = std.zig.system.resolveTargetQuery(io, other_target_query) catch unreachable;
1826 const root_target = root_module_target.unwrapTarget(conf);
18281827 const link_libc = maker.stepByIndex(producer_index).extended.compile.is_linking_libc;
18291828
18301829 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(
4040 argv.appendAssumeCapacity("--global-cache-dir");
4141 argv.appendAssumeCapacity(graph.global_cache_root.path orelse ".");
4242
43 if (conf_tc.target.get(conf).?.query.unwrap()) |compact_query| {
44 const query = compact_query.get(conf).unwrap(conf);
45 argv.appendAssumeCapacity("-target");
46 argv.appendAssumeCapacity(try query.zigTriple(arena));
43 if (conf_tc.target.get(conf)) |resolved_target| {
44 if (resolved_target.unwrapQuery(conf)) |query| {
45 argv.appendAssumeCapacity("-target");
46 argv.appendAssumeCapacity(try query.zigTriple(arena));
47 }
4748 }
4849
4950 switch (conf_tc.flags.optimize) {
lib/std/Build/Configuration.zig+69-21
......@@ -2144,6 +2144,33 @@ pub const ResolvedTarget = struct {
21442144 return (unwrap(this) orelse return null).get(c);
21452145 }
21462146 };
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 }
21472174};
21482175
21492176pub const TargetQuery = struct {
......@@ -2731,29 +2758,50 @@ pub const TargetQuery = struct {
27312758 dynamic_linker: bool,
27322759 };
27332760
2734 pub fn unwrap(tq: *const TargetQuery, c: *const Configuration) std.Target.Query {
2735 const cpu_arch = tq.flags.cpu_arch.unwrap();
2761 pub fn unwrapTarget(tq: *const TargetQuery, c: *const Configuration) std.Target {
2762 const cpu_arch = tq.flags.cpu_arch.unwrap().?;
2763 const os_tag = tq.flags.os_tag.unwrap().?;
27362764 return .{
2737 .cpu_arch = cpu_arch,
2738 .cpu_model = switch (tq.flags.cpu_model) {
2739 .native => .native,
2740 .baseline => .baseline,
2741 .determined_by_arch_os => .determined_by_arch_os,
2742 .explicit => .{ .explicit = cpu_arch.?.parseCpuModel(tq.cpu_name.value.?.slice(c)).? },
2765 .cpu = .{
2766 .arch = cpu_arch,
2767 .model = cpu_arch.parseCpuModel(tq.cpu_name.value.?.slice(c)).?,
2768 .features = tq.cpu_features_add.value.?,
27432769 },
2744 .cpu_features_add = tq.cpu_features_add.value orelse .empty,
2745 .cpu_features_sub = tq.cpu_features_sub.value orelse .empty,
2746 .os_tag = tq.flags.os_tag.unwrap(),
2747 .os_version_min = tq.os_version_min.u.unwrap(c),
2748 .os_version_max = tq.os_version_max.u.unwrap(c),
2749 .glibc_version = if (tq.glibc_version.value) |s|
2750 std.SemanticVersion.parse(s.slice(c)) catch unreachable
2751 else
2752 null,
2753 .android_api_level = tq.android_api_level.value,
2754 .abi = tq.flags.abi.unwrap(),
2755 .dynamic_linker = if (tq.dynamic_linker.value) |s| .init(s.slice(c)) else null,
2756 .ofmt = tq.flags.object_format.unwrap(),
2770 .os = .{
2771 .tag = os_tag,
2772 .version_range = switch (os_tag) {
2773 .linux => .{ .linux = .{
2774 .range = .{
2775 .min = tq.os_version_min.u.unwrap(c).?.semver,
2776 .max = tq.os_version_max.u.unwrap(c).?.semver,
2777 },
2778 .glibc = std.SemanticVersion.parse(tq.glibc_version.value.?.slice(c)) catch unreachable,
2779 .android = tq.android_api_level.value.?,
2780 } },
2781 .hurd => .{ .hurd = .{
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),
27572805 };
27582806 }
27592807};