authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-27 17:43:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-29 15:22:48-07:00
log03f937759dd9183a5f6740434360c88ab124c29d
tree6eb52b8e2ebf047c83a4337c5e8e2a3d462eb70c
parentbf959666e8013518660b188a365cbd383d516af3

tests: make -Dskip-non-native smarter

instead of only checking the target query nativeness, it checks for CPU feature set compatibility of resolved targets

2 files changed, 110 insertions(+), 8 deletions(-)

test/src/Cases.zig+1-1
......@@ -481,7 +481,7 @@ pub fn lowerToBuildSteps(
481481
482482 if (case.case.? == .Error and options.skip_compile_errors) continue;
483483
484 if (options.skip_non_native and !case.target.query.isNative())
484 if (options.skip_non_native and !@import("../tests.zig").isNative(&case.target, &b.graph.host.result))
485485 continue;
486486
487487 if (options.skip_spirv and case.target.query.cpu_arch != null and case.target.query.cpu_arch.?.isSpirV()) continue;
test/tests.zig+109-7
......@@ -2026,8 +2026,7 @@ const incremental_targets: []const []const u8 = &.{
20262026 //"wasm32-wasi-selfhosted",
20272027};
20282028
2029fn compatible32bitArch(b: *std.Build) ?std.Target.Cpu.Arch {
2030 const host = b.graph.host.result;
2029fn compatible32bitArch(host: *const std.Target) ?std.Target.Cpu.Arch {
20312030 return switch (host.os.tag) {
20322031 .windows => switch (host.cpu.arch) {
20332032 .x86_64 => .x86,
......@@ -2050,6 +2049,108 @@ fn compatible32bitArch(b: *std.Build) ?std.Target.Cpu.Arch {
20502049 };
20512050}
20522051
2052pub fn isNative(actual_target: *const std.Build.ResolvedTarget, host: *const std.Target) bool {
2053 if (actual_target.query.isNative()) return true;
2054 const actual = &actual_target.result;
2055
2056 if (actual.cpu.arch != host.cpu.arch and
2057 actual.cpu.arch != compatible32bitArch(host))
2058 {
2059 return false;
2060 }
2061
2062 if (actual.os.tag != host.os.tag)
2063 return false;
2064
2065 // Remove features that don't actually affect compatibility.
2066 const irrelevant: std.Target.Cpu.Feature.Set = switch (host.cpu.arch) {
2067 .x86_64 => std.Target.x86.featureSet(&.{
2068 .@"16bit_mode",
2069 .@"32bit_mode",
2070 .@"64bit",
2071 .false_deps_getmant,
2072 .false_deps_lzcnt_tzcnt,
2073 .false_deps_mulc,
2074 .false_deps_mullq,
2075 .false_deps_perm,
2076 .false_deps_popcnt,
2077 .false_deps_range,
2078 .fast_11bytenop,
2079 .fast_15bytenop,
2080 .fast_7bytenop,
2081 .fast_bextr,
2082 .fast_dpwssd,
2083 .fast_gather,
2084 .fast_hops,
2085 .fast_imm16,
2086 .fast_lzcnt,
2087 .fast_movbe,
2088 .fast_scalar_fsqrt,
2089 .fast_scalar_shift_masks,
2090 .fast_shld_rotate,
2091 .fast_variable_crosslane_shuffle,
2092 .fast_variable_perlane_shuffle,
2093 .fast_vector_fsqrt,
2094 .fast_vector_shift_masks,
2095 .faster_shift_than_shuffle,
2096 .no_bypass_delay,
2097 .no_bypass_delay_blend,
2098 .no_bypass_delay_mov,
2099 .no_bypass_delay_shuffle,
2100 .prefer_128_bit,
2101 .prefer_256_bit,
2102 .prefer_legacy_setcc,
2103 .prefer_mask_registers,
2104 .prefer_movmsk_over_vtest,
2105 .prefer_no_gather,
2106 .prefer_no_scatter,
2107 .slow_3ops_lea,
2108 .slow_incdec,
2109 .slow_lea,
2110 .slow_pmaddwd,
2111 .slow_pmulld,
2112 .slow_pmullq,
2113 .slow_shld,
2114 .slow_two_mem_ops,
2115 .slow_unaligned_mem_16,
2116 .slow_unaligned_mem_32,
2117 }),
2118 .aarch64 => std.Target.aarch64.featureSet(&.{
2119 .addr_lsl_slow_14,
2120 .alu_lsl_fast,
2121 .avoid_ldapur,
2122 .disable_fast_inc_vl,
2123 .exynos_cheap_as_move,
2124 .fuse_address,
2125 .fuse_addsub_2reg_const1,
2126 .fuse_adrp_add,
2127 .fuse_aes,
2128 .fuse_arith_logic,
2129 .fuse_crypto_eor,
2130 .fuse_csel,
2131 .fuse_cset,
2132 .fuse_literals,
2133 .predictable_select_expensive,
2134 .slow_misaligned_128store,
2135 .slow_paired_128,
2136 .slow_strqro_store,
2137 .use_experimental_zeroing_pseudos,
2138 .use_fixed_over_scalable_if_equal_cost,
2139 .use_postra_scheduler,
2140 .use_reciprocal_square_root,
2141 .use_wzr_to_vec_move,
2142 }),
2143 else => .empty,
2144 };
2145 var set = actual.cpu.features;
2146 set.removeFeatureSet(irrelevant);
2147
2148 if (!host.cpu.features.isSuperSetOf(set))
2149 return false;
2150
2151 return true;
2152}
2153
20532154/// For stack trace tests, we only test native by default, because external executors are pretty
20542155/// unreliable at stack tracing. However, if there's a 32-bit equivalent target which the host can
20552156/// trivially run, we may as well at least test that!
......@@ -2057,7 +2158,7 @@ fn nativeAndCompatible32bit(b: *std.Build, skip_non_native: bool) []const std.Bu
20572158 const host = b.graph.host.result;
20582159 const only_native = (&b.graph.host)[0..1];
20592160 if (skip_non_native) return only_native;
2060 const arch32 = compatible32bitArch(b) orelse return only_native;
2161 const arch32 = compatible32bitArch(&b.graph.host.result) orelse return only_native;
20612162 return b.graph.arena.dupe(std.Build.ResolvedTarget, &.{
20622163 b.graph.host,
20632164 b.resolveTargetQuery(.{ .cpu_arch = arch32, .os_tag = host.os.tag }),
......@@ -2074,7 +2175,7 @@ fn wineAndCompatible32bit(b: *std.Build, skip_non_native: bool) []const std.Buil
20742175 .os_tag = .windows,
20752176 })) catch @panic("OOM");
20762177 if (!skip_non_native) {
2077 if (compatible32bitArch(b)) |arch| {
2178 if (compatible32bitArch(&b.graph.host.result)) |arch| {
20782179 targets.append(b.graph.arena, b.resolveTargetQuery(.{
20792180 .cpu_arch = arch,
20802181 .os_tag = .windows,
......@@ -2519,7 +2620,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
25192620
25202621 if (!options.test_extra_targets and test_target.extra_target) continue;
25212622
2522 if (options.skip_non_native and !test_target.target.isNative())
2623 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
25232624 continue;
25242625
25252626 const target = &resolved_target.result;
......@@ -2812,8 +2913,6 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
28122913 const step = b.step("test-c-abi", "Run the C ABI tests");
28132914
28142915 for (c_abi_targets) |c_abi_target| {
2815 if (options.skip_non_native and !c_abi_target.target.isNative()) continue;
2816
28172916 if (options.skip_wasm and c_abi_target.target.cpu_arch != null and c_abi_target.target.cpu_arch.?.isWasm()) continue;
28182917
28192918 if (options.skip_freebsd and c_abi_target.target.os_tag == .freebsd) continue;
......@@ -2827,6 +2926,9 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
28272926 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
28282927 const target = &resolved_target.result;
28292928
2929 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
2930 continue;
2931
28302932 if (options.test_target_filters.len > 0) {
28312933 for (options.test_target_filters) |filter| {
28322934 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;