authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-09 12:50:27+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-10 08:36:08+02:00
log38c1536b96888b17626b35acf911cef56668b54f
tree0e687f443c234bd13807a4ccb6e01cf173094f28
parent93316d6e613cbcf0b1f94da42bffdf9eac3223de
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test-standalone: respect -Dskip-non-native in cross-compiling tests

closes https://github.com/ziglang/zig/issues/25471

13 files changed, 92 insertions(+), 24 deletions(-)

build.zig+1
......@@ -636,6 +636,7 @@ pub fn build(b: *std.Build) !void {
636636 test_step.dependOn(tests.addStandaloneTests(
637637 b,
638638 optimize_modes,
639 skip_non_native,
639640 enable_macos_sdk,
640641 enable_ios_sdk,
641642 enable_symlinks_windows,
test/standalone/build.zig+8-3
......@@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void {
1414 const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false;
1515 const simple_skip_release_fast = b.option(bool, "simple_skip_release_fast", "Simple tests skip release-fast builds") orelse false;
1616 const simple_skip_release_small = b.option(bool, "simple_skip_release_small", "Simple tests skip release-small builds") orelse false;
17 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
1718
1819 const simple_dep = b.dependency("simple", .{
1920 .skip_debug = simple_skip_debug,
......@@ -103,7 +104,7 @@ pub fn build(b: *std.Build) void {
103104 if (std.mem.eql(u8, dep_name, "simple")) continue;
104105
105106 const all_pkgs = @import("root").dependencies.packages;
106 inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| {
107 const forward_skip_non_native = inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| {
107108 if (std.mem.eql(u8, dep_hash, pkg_hash)) {
108109 const pkg = @field(all_pkgs, pkg_hash);
109110 if (!@hasDecl(pkg, "build_zig")) {
......@@ -121,11 +122,15 @@ pub fn build(b: *std.Build) void {
121122 {
122123 continue :add_dep_steps;
123124 }
124 break;
125 break @hasDecl(pkg.build_zig, "supports_skip_non_native") and
126 pkg.build_zig.supports_skip_non_native;
125127 }
126128 } else unreachable;
127129
128 const dep = b.dependency(dep_name, .{});
130 const dep = if (forward_skip_non_native)
131 b.dependency(dep_name, .{ .skip_non_native = skip_non_native })
132 else
133 b.dependency(dep_name, .{});
129134 const dep_step = dep.builder.default_step;
130135 dep_step.name = b.fmt("standalone_test_cases.{s}", .{dep_name});
131136 step.dependOn(dep_step);
test/standalone/coff_dwarf/build.zig+6-11
......@@ -1,19 +1,12 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35/// This tests the path where DWARF information is embedded in a COFF binary
46pub fn build(b: *std.Build) void {
5 const host = b.graph.host;
6
7 // https://github.com/ziglang/zig/issues/25471
8 if (host.result.os.tag == .freebsd) return;
7 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
98
10 switch (host.result.cpu.arch) {
11 .aarch64,
12 .x86,
13 .x86_64,
14 => {},
15 else => return,
16 }
9 const host = b.graph.host;
1710
1811 const test_step = b.step("test", "Test it");
1912 b.default_step = test_step;
......@@ -24,6 +17,8 @@ pub fn build(b: *std.Build) void {
2417 else => b.resolveTargetQuery(.{ .os_tag = .windows }),
2518 };
2619
20 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &host.result)) return;
21
2722 const exe = b.addExecutable(.{
2823 .name = "main",
2924 .root_module = b.createModule(.{
test/standalone/compile_asm/build.zig+6
......@@ -1,6 +1,10 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) !void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
48 const test_step = b.step("test", "Test it");
59 b.default_step = test_step;
610
......@@ -13,6 +17,8 @@ pub fn build(b: *std.Build) !void {
1317 },
1418 });
1519
20 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
21
1622 const kernel = b.addExecutable(.{
1723 .name = "kernel",
1824 .root_module = b.createModule(.{
test/standalone/elf2/build.zig+7
......@@ -1,4 +1,8 @@
1pub const supports_skip_non_native = true;
2
13pub fn build(b: *Build) void {
4 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
5
26 const test_step = b.step("test", "Test the new ELF linker");
37 b.default_step = test_step;
48
......@@ -15,6 +19,9 @@ pub fn build(b: *Build) void {
1519 .cpu_arch = .x86_64,
1620 .os_tag = .linux,
1721 });
22
23 if (skip_non_native and !std.zig.target.isNative(&x86_64_linux_target.query, &x86_64_linux_target.result, &b.graph.host.result)) return;
24
1825 addOne(b, test_step, x86_64_linux_target, false, .static, false, false, "elf2-hello-selfhosted-static");
1926 addOne(b, test_step, x86_64_linux_target, false, .static, true, false, "elf2-hello-selfhosted-static-pie");
2027 addOne(b, test_step, x86_64_linux_target, true, .static, false, false, "elf2-hello-llvm-static");
test/standalone/embed_generated_file/build.zig+12-4
......@@ -1,6 +1,17 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
8 const target = b.resolveTargetQuery(.{
9 .cpu_arch = .x86,
10 .os_tag = .freestanding,
11 });
12
13 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
14
415 const test_step = b.step("test", "Test it");
516 b.default_step = test_step;
617
......@@ -8,10 +19,7 @@ pub fn build(b: *std.Build) void {
819 .name = "bootloader",
920 .root_module = b.createModule(.{
1021 .root_source_file = b.path("bootloader.zig"),
11 .target = b.resolveTargetQuery(.{
12 .cpu_arch = .x86,
13 .os_tag = .freestanding,
14 }),
22 .target = target,
1523 .optimize = .small,
1624 }),
1725 });
test/standalone/entry_point/build.zig+11-3
......@@ -1,11 +1,19 @@
1pub const supports_skip_non_native = true;
2
13pub fn build(b: *std.Build) !void {
4 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
5
6 const target = b.resolveTargetQuery(try .parse(.{
7 .arch_os_abi = "x86_64-linux",
8 }));
9
10 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
11
212 const mod = b.createModule(.{
313 // Setting the entry point doesn't work properly on all targets right now. Since we're
414 // really just trying to make sure that the compiler *frontend* respects `-fentry` and
515 // includes it in the cache manifest, just test for a target where it works.
6 .target = b.resolveTargetQuery(try .parse(.{
7 .arch_os_abi = "x86_64-linux",
8 })),
16 .target = target,
917 .optimize = .fast, // non-Debug build for reproducible output
1018 .root_source_file = b.path("main.zig"),
1119 });
test/standalone/glibc_compat/build.zig+15-3
......@@ -1,6 +1,8 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4pub const supports_skip_non_native = true;
5
46// To run executables linked against a specific glibc version, the
57// run-time glibc version needs to be new enough. Check the host's glibc
68// version. Note that this does not allow for translation/vm/emulation
......@@ -8,17 +10,23 @@ const builtin = @import("builtin");
810const running_glibc_ver = builtin.os.versionRange().gnuLibCVersion();
911
1012pub fn build(b: *std.Build) void {
13 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
14
1115 const test_step = b.step("test", "Test");
1216 b.default_step = test_step;
1317
1418 for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
19 const target = b.resolveTargetQuery(std.Target.Query.parse(
20 .{ .arch_os_abi = t },
21 ) catch unreachable);
22
23 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
24
1525 const exe = b.addExecutable(.{
1626 .name = t,
1727 .root_module = b.createModule(.{
1828 .root_source_file = null,
19 .target = b.resolveTargetQuery(std.Target.Query.parse(
20 .{ .arch_os_abi = t },
21 ) catch unreachable),
29 .target = target,
2230 .link_libc = true,
2331 }),
2432 });
......@@ -49,6 +57,8 @@ pub fn build(b: *std.Build) void {
4957 .{ .arch_os_abi = t },
5058 ) catch unreachable);
5159
60 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
61
5262 const glibc_ver = target.result.os.version_range.linux.glibc;
5363
5464 // only build test if glibc version supports the architecture
......@@ -103,6 +113,8 @@ pub fn build(b: *std.Build) void {
103113 .{ .arch_os_abi = t },
104114 ) catch unreachable);
105115
116 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
117
106118 if (target.result.cpu.arch.isLoongArch()) continue; // https://github.com/Vexu/arocc/issues/1096
107119
108120 const glibc_ver = target.result.os.version_range.linux.glibc;
test/standalone/install_raw_hex/build.zig+6
......@@ -1,7 +1,11 @@
11const builtin = @import("builtin");
22const std = @import("std");
33
4pub const supports_skip_non_native = true;
5
46pub fn build(b: *std.Build) void {
7 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
8
59 const test_step = b.step("test", "Test it");
610 b.default_step = test_step;
711
......@@ -12,6 +16,8 @@ pub fn build(b: *std.Build) void {
1216 .abi = .gnueabihf,
1317 });
1418
19 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
20
1521 const optimize: std.builtin.Optimize = .debug;
1622
1723 const elf = b.addExecutable(.{
test/standalone/tsan/build.zig+6
......@@ -1,5 +1,7 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35const targets: []const std.Target.Query = &.{
46 .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none },
57 .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none },
......@@ -32,6 +34,8 @@ const targets: []const std.Target.Query = &.{
3234};
3335
3436pub fn build(b: *std.Build) !void {
37 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
38
3539 const test_step = b.step("test", "Test the program");
3640 b.default_step = test_step;
3741
......@@ -40,6 +44,8 @@ pub fn build(b: *std.Build) !void {
4044 for (targets) |query| {
4145 const target = b.resolveTargetQuery(query);
4246
47 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
48
4349 switch (target.result.os.tag) {
4450 .macos => {
4551 // compiling tsan on macos requires system headers that aren't present during cross-compilation
test/standalone/windows_entry_points/build.zig+6
......@@ -1,6 +1,10 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
48 const test_step = b.step("test", "Test it");
59 b.default_step = test_step;
610
......@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {
1014 .abi = .gnu,
1115 });
1216
17 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
18
1319 {
1420 const exe = b.addExecutable(.{
1521 .name = "main",
test/standalone/windows_resources/build.zig+6
......@@ -1,6 +1,10 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
48 const test_step = b.step("test", "Test it");
59 b.default_step = test_step;
610
......@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {
1014 .abi = .gnu,
1115 });
1216
17 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
18
1319 const generated_h_step = b.addWriteFile("generated.h", "#define GENERATED_DEFINE \"foo\"");
1420
1521 add(b, b.graph.host, .any, test_step, generated_h_step);
test/tests.zig+2
......@@ -2374,6 +2374,7 @@ pub fn addErrorTraceTests(b: *std.Build, options: ErrorTracesContext.Options) *S
23742374pub fn addStandaloneTests(
23752375 b: *std.Build,
23762376 optimize_modes: []const OptimizeMode,
2377 skip_non_native: bool,
23772378 enable_macos_sdk: bool,
23782379 enable_ios_sdk: bool,
23792380 enable_symlinks_windows: bool,
......@@ -2388,6 +2389,7 @@ pub fn addStandaloneTests(
23882389 .simple_skip_release_safe = mem.findScalar(OptimizeMode, optimize_modes, .safe) == null,
23892390 .simple_skip_release_fast = mem.findScalar(OptimizeMode, optimize_modes, .fast) == null,
23902391 .simple_skip_release_small = mem.findScalar(OptimizeMode, optimize_modes, .small) == null,
2392 .skip_non_native = skip_non_native,
23912393 });
23922394 const test_cases_dep_step = test_cases_dep.builder.default_step;
23932395 test_cases_dep_step.name = test_cases_dep_name;