authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-30 05:45:57+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-30 05:45:57+02:00
log09ad5c029a24f77e3de3586fa10164374c4c9ac5
tree42b5806dae6c56eb21450d954298264390aaeea2
parentb8cb780230197ce7e7e3059c7e37e1a40d9dcfc2
parent9ad29fbc6c594f4474919020a3c796d64ab38455

Merge pull request 'make `-Dskip-non-native` smarter' (#35502) from skip_non_native into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35502

10 files changed, 158 insertions(+), 53 deletions(-)

build.zig-1
......@@ -233,7 +233,6 @@ pub fn build(b: *std.Build) !void {
233233 exe.root_module.addOptions("build_options", exe_options);
234234
235235 exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames);
236 exe_options.addOption(bool, "skip_non_native", skip_non_native);
237236 exe_options.addOption(bool, "have_llvm", enable_llvm);
238237 exe_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
239238 exe_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
lib/std/math.zig+5
......@@ -461,6 +461,11 @@ pub fn wrap(x: anytype, r: anytype) @TypeOf(x) {
461461 }
462462}
463463test wrap {
464 if (builtin.os.tag == .windows and builtin.cpu.arch == .x86) {
465 // https://codeberg.org/ziglang/zig/issues/35520
466 return error.SkipZigTest;
467 }
468
464469 // Within range
465470 try testing.expect(wrap(@as(i32, -75), @as(i32, 180)) == -75);
466471 try testing.expect(wrap(@as(i32, -75), @as(i32, -180)) == -75);
lib/std/math/isnan.zig+5
......@@ -29,6 +29,11 @@ test isNan {
2929test isSignalNan {
3030 if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff and builtin.abi != .gnu) return error.SkipZigTest;
3131
32 if (builtin.os.tag == .windows) {
33 // https://codeberg.org/ziglang/zig/issues/35519
34 return error.SkipZigTest;
35 }
36
3237 inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| {
3338 // TODO: Signalling NaN values get converted to quiet NaN values in
3439 // some cases where they shouldn't such that this can fail.
src/link/Elf.zig-12
......@@ -1691,9 +1691,6 @@ pub fn updateFunc(
16911691 func_index: InternPool.Index,
16921692 mir: *const codegen.AnyMir,
16931693) link.File.UpdateNavError!void {
1694 if (build_options.skip_non_native and builtin.object_format != .elf) {
1695 @panic("Attempted to compile for object format that was disabled by build configuration");
1696 }
16971694 return self.zigObjectPtr().?.updateFunc(self, pt, func_index, mir);
16981695}
16991696
......@@ -1702,9 +1699,6 @@ pub fn updateNav(
17021699 pt: Zcu.PerThread,
17031700 nav: InternPool.Nav.Index,
17041701) link.File.UpdateNavError!void {
1705 if (build_options.skip_non_native and builtin.object_format != .elf) {
1706 @panic("Attempted to compile for object format that was disabled by build configuration");
1707 }
17081702 return self.zigObjectPtr().?.updateNav(self, pt, nav);
17091703}
17101704
......@@ -1714,9 +1708,6 @@ pub fn updateContainerType(
17141708 ty: InternPool.Index,
17151709 success: bool,
17161710) link.File.UpdateContainerTypeError!void {
1717 if (build_options.skip_non_native and builtin.object_format != .elf) {
1718 @panic("Attempted to compile for object format that was disabled by build configuration");
1719 }
17201711 return self.zigObjectPtr().?.updateContainerType(pt, ty, success) catch |err| switch (err) {
17211712 error.OutOfMemory => |e| return e,
17221713 };
......@@ -1728,9 +1719,6 @@ pub fn updateExports(
17281719 exported: Zcu.Exported,
17291720 export_indices: []const Zcu.Export.Index,
17301721) link.File.UpdateExportsError!void {
1731 if (build_options.skip_non_native and builtin.object_format != .elf) {
1732 @panic("Attempted to compile for object format that was disabled by build configuration");
1733 }
17341722 return self.zigObjectPtr().?.updateExports(self, pt, exported, export_indices);
17351723}
17361724
src/link/MachO.zig-9
......@@ -3075,16 +3075,10 @@ pub fn updateFunc(
30753075 func_index: InternPool.Index,
30763076 mir: *const codegen.AnyMir,
30773077) link.File.UpdateNavError!void {
3078 if (build_options.skip_non_native and builtin.object_format != .macho) {
3079 @panic("Attempted to compile for object format that was disabled by build configuration");
3080 }
30813078 return self.getZigObject().?.updateFunc(self, pt, func_index, mir);
30823079}
30833080
30843081pub fn updateNav(self: *MachO, pt: Zcu.PerThread, nav: InternPool.Nav.Index) link.File.UpdateNavError!void {
3085 if (build_options.skip_non_native and builtin.object_format != .macho) {
3086 @panic("Attempted to compile for object format that was disabled by build configuration");
3087 }
30883082 return self.getZigObject().?.updateNav(self, pt, nav);
30893083}
30903084
......@@ -3098,9 +3092,6 @@ pub fn updateExports(
30983092 exported: Zcu.Exported,
30993093 export_indices: []const Zcu.Export.Index,
31003094) link.File.UpdateExportsError!void {
3101 if (build_options.skip_non_native and builtin.object_format != .macho) {
3102 @panic("Attempted to compile for object format that was disabled by build configuration");
3103 }
31043095 return self.getZigObject().?.updateExports(self, pt, exported, export_indices);
31053096}
31063097
src/link/Wasm.zig-11
......@@ -3192,10 +3192,6 @@ pub fn updateFunc(
31923192 func_index: InternPool.Index,
31933193 any_mir: *const codegen.AnyMir,
31943194) !void {
3195 if (build_options.skip_non_native and builtin.object_format != .wasm) {
3196 @panic("Attempted to compile for object format that was disabled by build configuration");
3197 }
3198
31993195 dev.check(.wasm_backend);
32003196
32013197 // This linker implementation only works with codegen backend `.stage2_wasm`.
......@@ -3279,9 +3275,6 @@ pub fn updateFunc(
32793275// Generate code for the "Nav", storing it in memory to be later written to
32803276// the file on flush().
32813277pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void {
3282 if (build_options.skip_non_native and builtin.object_format != .wasm) {
3283 @panic("Attempted to compile for object format that was disabled by build configuration");
3284 }
32853278 const zcu = pt.zcu;
32863279 const ip = &zcu.intern_pool;
32873280 const nav = ip.getNav(nav_index);
......@@ -3378,10 +3371,6 @@ pub fn updateExports(
33783371 exported: Zcu.Exported,
33793372 export_indices: []const Zcu.Export.Index,
33803373) !void {
3381 if (build_options.skip_non_native and builtin.object_format != .wasm) {
3382 @panic("Attempted to compile for object format that was disabled by build configuration");
3383 }
3384
33853374 const zcu = pt.zcu;
33863375 const gpa = zcu.gpa;
33873376 const ip = &zcu.intern_pool;
test/behavior/align.zig+5
......@@ -29,6 +29,11 @@ test "large alignment of local constant" {
2929 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; // flaky
3030 if (builtin.zig_backend == .stage2_c and builtin.target.abi == .msvc) return error.SkipZigTest;
3131
32 if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) {
33 // https://codeberg.org/ziglang/zig/issues/35537
34 return error.SkipZigTest;
35 }
36
3237 const x: f32 align(128) = 12.34;
3338 try std.testing.expect(@intFromPtr(&x) % 128 == 0);
3439}
test/behavior/floatop.zig+5
......@@ -948,6 +948,11 @@ test "@log2 with vectors" {
948948 builtin.cpu.arch == .aarch64 and
949949 builtin.os.tag == .windows) return error.SkipZigTest;
950950
951 if (builtin.os.tag == .windows and builtin.cpu.arch == .x86) {
952 // https://codeberg.org/ziglang/zig/issues/35518
953 return error.SkipZigTest;
954 }
955
951956 try testLog2WithVectors();
952957 try comptime testLog2WithVectors();
953958}
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+137-19
......@@ -200,6 +200,7 @@ const module_test_targets = blk: {
200200 // .use_lld = false,
201201 // .optimize_mode = .ReleaseFast,
202202 // .strip = true,
203 // .skip_modules = &.{"std"}, // TODO get these passing
203204 //},
204205 //.{
205206 // .target = .{
......@@ -212,6 +213,7 @@ const module_test_targets = blk: {
212213 // .use_lld = false,
213214 // .optimize_mode = .ReleaseFast,
214215 // .strip = true,
216 // .skip_modules = &.{"std"}, // TODO get these passing
215217 //},
216218
217219 .{
......@@ -1609,6 +1611,8 @@ const module_test_targets = blk: {
16091611 .abi = .msvc,
16101612 },
16111613 .link_libc = true,
1614 // https://codeberg.org/ziglang/zig/issues/35517
1615 .skip_modules = &.{"libc"},
16121616 },
16131617 .{
16141618 .target = .{
......@@ -1624,6 +1628,8 @@ const module_test_targets = blk: {
16241628 .abi = .gnu,
16251629 },
16261630 .link_libc = true,
1631 // https://codeberg.org/ziglang/zig/issues/35517
1632 .skip_modules = &.{"libc"},
16271633 },
16281634
16291635 .{
......@@ -1634,6 +1640,8 @@ const module_test_targets = blk: {
16341640 },
16351641 .use_llvm = false,
16361642 .use_lld = false,
1643 // https://codeberg.org/ziglang/zig/issues/35537
1644 .skip_modules = &.{"behavior"},
16371645 },
16381646 .{
16391647 .target = .{
......@@ -1649,6 +1657,8 @@ const module_test_targets = blk: {
16491657 .abi = .msvc,
16501658 },
16511659 .link_libc = true,
1660 // https://codeberg.org/ziglang/zig/issues/35517
1661 .skip_modules = &.{"libc"},
16521662 },
16531663 .{
16541664 .target = .{
......@@ -1989,13 +1999,14 @@ const c_abi_targets = blk: {
19891999
19902000 // Windows Targets
19912001
1992 .{
1993 .target = .{
1994 .cpu_arch = .x86,
1995 .os_tag = .windows,
1996 .abi = .gnu,
1997 },
1998 },
2002 // https://codeberg.org/ziglang/zig/issues/35521
2003 //.{
2004 // .target = .{
2005 // .cpu_arch = .x86,
2006 // .os_tag = .windows,
2007 // .abi = .gnu,
2008 // },
2009 //},
19992010 .{
20002011 .target = .{
20012012 .cpu_arch = .x86_64,
......@@ -2026,8 +2037,7 @@ const incremental_targets: []const []const u8 = &.{
20262037 //"wasm32-wasi-selfhosted",
20272038};
20282039
2029fn compatible32bitArch(b: *std.Build) ?std.Target.Cpu.Arch {
2030 const host = b.graph.host.result;
2040fn compatible32bitArch(host: *const std.Target) ?std.Target.Cpu.Arch {
20312041 return switch (host.os.tag) {
20322042 .windows => switch (host.cpu.arch) {
20332043 .x86_64 => .x86,
......@@ -2050,6 +2060,108 @@ fn compatible32bitArch(b: *std.Build) ?std.Target.Cpu.Arch {
20502060 };
20512061}
20522062
2063pub fn isNative(actual_target: *const std.Build.ResolvedTarget, host: *const std.Target) bool {
2064 if (actual_target.query.isNative()) return true;
2065 const actual = &actual_target.result;
2066
2067 if (actual.cpu.arch != host.cpu.arch and
2068 actual.cpu.arch != compatible32bitArch(host))
2069 {
2070 return false;
2071 }
2072
2073 if (actual.os.tag != host.os.tag)
2074 return false;
2075
2076 // Remove features that don't actually affect compatibility.
2077 const irrelevant: std.Target.Cpu.Feature.Set = switch (host.cpu.arch) {
2078 .x86_64 => std.Target.x86.featureSet(&.{
2079 .@"16bit_mode",
2080 .@"32bit_mode",
2081 .@"64bit",
2082 .false_deps_getmant,
2083 .false_deps_lzcnt_tzcnt,
2084 .false_deps_mulc,
2085 .false_deps_mullq,
2086 .false_deps_perm,
2087 .false_deps_popcnt,
2088 .false_deps_range,
2089 .fast_11bytenop,
2090 .fast_15bytenop,
2091 .fast_7bytenop,
2092 .fast_bextr,
2093 .fast_dpwssd,
2094 .fast_gather,
2095 .fast_hops,
2096 .fast_imm16,
2097 .fast_lzcnt,
2098 .fast_movbe,
2099 .fast_scalar_fsqrt,
2100 .fast_scalar_shift_masks,
2101 .fast_shld_rotate,
2102 .fast_variable_crosslane_shuffle,
2103 .fast_variable_perlane_shuffle,
2104 .fast_vector_fsqrt,
2105 .fast_vector_shift_masks,
2106 .faster_shift_than_shuffle,
2107 .no_bypass_delay,
2108 .no_bypass_delay_blend,
2109 .no_bypass_delay_mov,
2110 .no_bypass_delay_shuffle,
2111 .prefer_128_bit,
2112 .prefer_256_bit,
2113 .prefer_legacy_setcc,
2114 .prefer_mask_registers,
2115 .prefer_movmsk_over_vtest,
2116 .prefer_no_gather,
2117 .prefer_no_scatter,
2118 .slow_3ops_lea,
2119 .slow_incdec,
2120 .slow_lea,
2121 .slow_pmaddwd,
2122 .slow_pmulld,
2123 .slow_pmullq,
2124 .slow_shld,
2125 .slow_two_mem_ops,
2126 .slow_unaligned_mem_16,
2127 .slow_unaligned_mem_32,
2128 }),
2129 .aarch64, .aarch64_be => std.Target.aarch64.featureSet(&.{
2130 .addr_lsl_slow_14,
2131 .alu_lsl_fast,
2132 .avoid_ldapur,
2133 .disable_fast_inc_vl,
2134 .exynos_cheap_as_move,
2135 .fuse_address,
2136 .fuse_addsub_2reg_const1,
2137 .fuse_adrp_add,
2138 .fuse_aes,
2139 .fuse_arith_logic,
2140 .fuse_crypto_eor,
2141 .fuse_csel,
2142 .fuse_cset,
2143 .fuse_literals,
2144 .predictable_select_expensive,
2145 .slow_misaligned_128store,
2146 .slow_paired_128,
2147 .slow_strqro_store,
2148 .use_experimental_zeroing_pseudos,
2149 .use_fixed_over_scalable_if_equal_cost,
2150 .use_postra_scheduler,
2151 .use_reciprocal_square_root,
2152 .use_wzr_to_vec_move,
2153 }),
2154 else => .empty,
2155 };
2156 var set = actual.cpu.features;
2157 set.removeFeatureSet(irrelevant);
2158
2159 if (!host.cpu.features.isSuperSetOf(set))
2160 return false;
2161
2162 return true;
2163}
2164
20532165/// For stack trace tests, we only test native by default, because external executors are pretty
20542166/// unreliable at stack tracing. However, if there's a 32-bit equivalent target which the host can
20552167/// trivially run, we may as well at least test that!
......@@ -2057,7 +2169,7 @@ fn nativeAndCompatible32bit(b: *std.Build, skip_non_native: bool) []const std.Bu
20572169 const host = b.graph.host.result;
20582170 const only_native = (&b.graph.host)[0..1];
20592171 if (skip_non_native) return only_native;
2060 const arch32 = compatible32bitArch(b) orelse return only_native;
2172 const arch32 = compatible32bitArch(&b.graph.host.result) orelse return only_native;
20612173 return b.graph.arena.dupe(std.Build.ResolvedTarget, &.{
20622174 b.graph.host,
20632175 b.resolveTargetQuery(.{ .cpu_arch = arch32, .os_tag = host.os.tag }),
......@@ -2074,7 +2186,7 @@ fn wineAndCompatible32bit(b: *std.Build, skip_non_native: bool) []const std.Buil
20742186 .os_tag = .windows,
20752187 })) catch @panic("OOM");
20762188 if (!skip_non_native) {
2077 if (compatible32bitArch(b)) |arch| {
2189 if (compatible32bitArch(&b.graph.host.result)) |arch| {
20782190 targets.append(b.graph.arena, b.resolveTargetQuery(.{
20792191 .cpu_arch = arch,
20802192 .os_tag = .windows,
......@@ -2519,11 +2631,21 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
25192631
25202632 if (!options.test_extra_targets and test_target.extra_target) continue;
25212633
2522 if (options.skip_non_native and !test_target.target.isNative())
2634 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
25232635 continue;
25242636
25252637 const target = &resolved_target.result;
25262638
2639 if (target.cpu.arch == .powerpc64le and target.ofmt == .c) {
2640 // https://codeberg.org/ziglang/zig/issues/35522
2641 continue;
2642 }
2643
2644 if (target.cpu.arch == .s390x and target.ofmt == .c) {
2645 // https://codeberg.org/ziglang/zig/issues/35523
2646 continue;
2647 }
2648
25272649 if (std.mem.eql(u8, options.name, "libc")) {
25282650 // The libc API tests obviously need to link libc. So for test
25292651 // target entries where we wouldn't link libc by default, skip the
......@@ -2562,11 +2684,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
25622684 if (options.skip_single_threaded and test_target.single_threaded == true)
25632685 continue;
25642686
2565 if (!would_use_llvm and target.cpu.arch == .aarch64) {
2566 // TODO get std tests passing for the aarch64 self-hosted backend.
2567 if (mem.eql(u8, options.name, "std")) continue;
2568 }
2569
25702687 const want_this_mode = for (options.optimize_modes) |m| {
25712688 if (m == test_target.optimize_mode) break true;
25722689 } else false;
......@@ -2812,8 +2929,6 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
28122929 const step = b.step("test-c-abi", "Run the C ABI tests");
28132930
28142931 for (c_abi_targets) |c_abi_target| {
2815 if (options.skip_non_native and !c_abi_target.target.isNative()) continue;
2816
28172932 if (options.skip_wasm and c_abi_target.target.cpu_arch != null and c_abi_target.target.cpu_arch.?.isWasm()) continue;
28182933
28192934 if (options.skip_freebsd and c_abi_target.target.os_tag == .freebsd) continue;
......@@ -2827,6 +2942,9 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
28272942 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
28282943 const target = &resolved_target.result;
28292944
2945 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
2946 continue;
2947
28302948 if (options.test_target_filters.len > 0) {
28312949 for (options.test_target_filters) |filter| {
28322950 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;