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 {...@@ -636,6 +636,7 @@ pub fn build(b: *std.Build) !void {
636 test_step.dependOn(tests.addStandaloneTests(636 test_step.dependOn(tests.addStandaloneTests(
637 b,637 b,
638 optimize_modes,638 optimize_modes,
639 skip_non_native,
639 enable_macos_sdk,640 enable_macos_sdk,
640 enable_ios_sdk,641 enable_ios_sdk,
641 enable_symlinks_windows,642 enable_symlinks_windows,
test/standalone/build.zig+8-3
...@@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void {...@@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void {
14 const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false;14 const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false;
15 const simple_skip_release_fast = b.option(bool, "simple_skip_release_fast", "Simple tests skip release-fast builds") orelse false;15 const simple_skip_release_fast = b.option(bool, "simple_skip_release_fast", "Simple tests skip release-fast builds") orelse false;
16 const simple_skip_release_small = b.option(bool, "simple_skip_release_small", "Simple tests skip release-small builds") orelse false;16 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
18 const simple_dep = b.dependency("simple", .{19 const simple_dep = b.dependency("simple", .{
19 .skip_debug = simple_skip_debug,20 .skip_debug = simple_skip_debug,
...@@ -103,7 +104,7 @@ pub fn build(b: *std.Build) void {...@@ -103,7 +104,7 @@ pub fn build(b: *std.Build) void {
103 if (std.mem.eql(u8, dep_name, "simple")) continue;104 if (std.mem.eql(u8, dep_name, "simple")) continue;
104105
105 const all_pkgs = @import("root").dependencies.packages;106 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| {
107 if (std.mem.eql(u8, dep_hash, pkg_hash)) {108 if (std.mem.eql(u8, dep_hash, pkg_hash)) {
108 const pkg = @field(all_pkgs, pkg_hash);109 const pkg = @field(all_pkgs, pkg_hash);
109 if (!@hasDecl(pkg, "build_zig")) {110 if (!@hasDecl(pkg, "build_zig")) {
...@@ -121,11 +122,15 @@ pub fn build(b: *std.Build) void {...@@ -121,11 +122,15 @@ pub fn build(b: *std.Build) void {
121 {122 {
122 continue :add_dep_steps;123 continue :add_dep_steps;
123 }124 }
124 break;125 break @hasDecl(pkg.build_zig, "supports_skip_non_native") and
126 pkg.build_zig.supports_skip_non_native;
125 }127 }
126 } else unreachable;128 } 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, .{});
129 const dep_step = dep.builder.default_step;134 const dep_step = dep.builder.default_step;
130 dep_step.name = b.fmt("standalone_test_cases.{s}", .{dep_name});135 dep_step.name = b.fmt("standalone_test_cases.{s}", .{dep_name});
131 step.dependOn(dep_step);136 step.dependOn(dep_step);
test/standalone/coff_dwarf/build.zig+6-11
...@@ -1,19 +1,12 @@...@@ -1,19 +1,12 @@
1const std = @import("std");1const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
3/// This tests the path where DWARF information is embedded in a COFF binary5/// This tests the path where DWARF information is embedded in a COFF binary
4pub fn build(b: *std.Build) void {6pub fn build(b: *std.Build) void {
5 const host = b.graph.host;7 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
6
7 // https://github.com/ziglang/zig/issues/25471
8 if (host.result.os.tag == .freebsd) return;
98
10 switch (host.result.cpu.arch) {9 const host = b.graph.host;
11 .aarch64,
12 .x86,
13 .x86_64,
14 => {},
15 else => return,
16 }
1710
18 const test_step = b.step("test", "Test it");11 const test_step = b.step("test", "Test it");
19 b.default_step = test_step;12 b.default_step = test_step;
...@@ -24,6 +17,8 @@ pub fn build(b: *std.Build) void {...@@ -24,6 +17,8 @@ pub fn build(b: *std.Build) void {
24 else => b.resolveTargetQuery(.{ .os_tag = .windows }),17 else => b.resolveTargetQuery(.{ .os_tag = .windows }),
25 };18 };
2619
20 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &host.result)) return;
21
27 const exe = b.addExecutable(.{22 const exe = b.addExecutable(.{
28 .name = "main",23 .name = "main",
29 .root_module = b.createModule(.{24 .root_module = b.createModule(.{
test/standalone/compile_asm/build.zig+6
...@@ -1,6 +1,10 @@...@@ -1,6 +1,10 @@
1const std = @import("std");1const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
3pub fn build(b: *std.Build) !void {5pub fn build(b: *std.Build) !void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
4 const test_step = b.step("test", "Test it");8 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;9 b.default_step = test_step;
610
...@@ -13,6 +17,8 @@ pub fn build(b: *std.Build) !void {...@@ -13,6 +17,8 @@ pub fn build(b: *std.Build) !void {
13 },17 },
14 });18 });
1519
20 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
21
16 const kernel = b.addExecutable(.{22 const kernel = b.addExecutable(.{
17 .name = "kernel",23 .name = "kernel",
18 .root_module = b.createModule(.{24 .root_module = b.createModule(.{
test/standalone/elf2/build.zig+7
...@@ -1,4 +1,8 @@...@@ -1,4 +1,8 @@
1pub const supports_skip_non_native = true;
2
1pub fn build(b: *Build) void {3pub fn build(b: *Build) void {
4 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
5
2 const test_step = b.step("test", "Test the new ELF linker");6 const test_step = b.step("test", "Test the new ELF linker");
3 b.default_step = test_step;7 b.default_step = test_step;
48
...@@ -15,6 +19,9 @@ pub fn build(b: *Build) void {...@@ -15,6 +19,9 @@ pub fn build(b: *Build) void {
15 .cpu_arch = .x86_64,19 .cpu_arch = .x86_64,
16 .os_tag = .linux,20 .os_tag = .linux,
17 });21 });
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
18 addOne(b, test_step, x86_64_linux_target, false, .static, false, false, "elf2-hello-selfhosted-static");25 addOne(b, test_step, x86_64_linux_target, false, .static, false, false, "elf2-hello-selfhosted-static");
19 addOne(b, test_step, x86_64_linux_target, false, .static, true, false, "elf2-hello-selfhosted-static-pie");26 addOne(b, test_step, x86_64_linux_target, false, .static, true, false, "elf2-hello-selfhosted-static-pie");
20 addOne(b, test_step, x86_64_linux_target, true, .static, false, false, "elf2-hello-llvm-static");27 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 @@...@@ -1,6 +1,17 @@
1const std = @import("std");1const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
3pub fn build(b: *std.Build) void {5pub 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
4 const test_step = b.step("test", "Test it");15 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;16 b.default_step = test_step;
617
...@@ -8,10 +19,7 @@ pub fn build(b: *std.Build) void {...@@ -8,10 +19,7 @@ pub fn build(b: *std.Build) void {
8 .name = "bootloader",19 .name = "bootloader",
9 .root_module = b.createModule(.{20 .root_module = b.createModule(.{
10 .root_source_file = b.path("bootloader.zig"),21 .root_source_file = b.path("bootloader.zig"),
11 .target = b.resolveTargetQuery(.{22 .target = target,
12 .cpu_arch = .x86,
13 .os_tag = .freestanding,
14 }),
15 .optimize = .small,23 .optimize = .small,
16 }),24 }),
17 });25 });
test/standalone/entry_point/build.zig+11-3
...@@ -1,11 +1,19 @@...@@ -1,11 +1,19 @@
1pub const supports_skip_non_native = true;
2
1pub fn build(b: *std.Build) !void {3pub 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
2 const mod = b.createModule(.{12 const mod = b.createModule(.{
3 // Setting the entry point doesn't work properly on all targets right now. Since we're13 // Setting the entry point doesn't work properly on all targets right now. Since we're
4 // really just trying to make sure that the compiler *frontend* respects `-fentry` and14 // really just trying to make sure that the compiler *frontend* respects `-fentry` and
5 // includes it in the cache manifest, just test for a target where it works.15 // includes it in the cache manifest, just test for a target where it works.
6 .target = b.resolveTargetQuery(try .parse(.{16 .target = target,
7 .arch_os_abi = "x86_64-linux",
8 })),
9 .optimize = .fast, // non-Debug build for reproducible output17 .optimize = .fast, // non-Debug build for reproducible output
10 .root_source_file = b.path("main.zig"),18 .root_source_file = b.path("main.zig"),
11 });19 });
test/standalone/glibc_compat/build.zig+15-3
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub const supports_skip_non_native = true;
5
4// To run executables linked against a specific glibc version, the6// To run executables linked against a specific glibc version, the
5// run-time glibc version needs to be new enough. Check the host's glibc7// run-time glibc version needs to be new enough. Check the host's glibc
6// version. Note that this does not allow for translation/vm/emulation8// version. Note that this does not allow for translation/vm/emulation
...@@ -8,17 +10,23 @@ const builtin = @import("builtin");...@@ -8,17 +10,23 @@ const builtin = @import("builtin");
8const running_glibc_ver = builtin.os.versionRange().gnuLibCVersion();10const running_glibc_ver = builtin.os.versionRange().gnuLibCVersion();
911
10pub fn build(b: *std.Build) void {12pub fn build(b: *std.Build) void {
13 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
14
11 const test_step = b.step("test", "Test");15 const test_step = b.step("test", "Test");
12 b.default_step = test_step;16 b.default_step = test_step;
1317
14 for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {18 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
15 const exe = b.addExecutable(.{25 const exe = b.addExecutable(.{
16 .name = t,26 .name = t,
17 .root_module = b.createModule(.{27 .root_module = b.createModule(.{
18 .root_source_file = null,28 .root_source_file = null,
19 .target = b.resolveTargetQuery(std.Target.Query.parse(29 .target = target,
20 .{ .arch_os_abi = t },
21 ) catch unreachable),
22 .link_libc = true,30 .link_libc = true,
23 }),31 }),
24 });32 });
...@@ -49,6 +57,8 @@ pub fn build(b: *std.Build) void {...@@ -49,6 +57,8 @@ pub fn build(b: *std.Build) void {
49 .{ .arch_os_abi = t },57 .{ .arch_os_abi = t },
50 ) catch unreachable);58 ) catch unreachable);
5159
60 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
61
52 const glibc_ver = target.result.os.version_range.linux.glibc;62 const glibc_ver = target.result.os.version_range.linux.glibc;
5363
54 // only build test if glibc version supports the architecture64 // only build test if glibc version supports the architecture
...@@ -103,6 +113,8 @@ pub fn build(b: *std.Build) void {...@@ -103,6 +113,8 @@ pub fn build(b: *std.Build) void {
103 .{ .arch_os_abi = t },113 .{ .arch_os_abi = t },
104 ) catch unreachable);114 ) catch unreachable);
105115
116 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
117
106 if (target.result.cpu.arch.isLoongArch()) continue; // https://github.com/Vexu/arocc/issues/1096118 if (target.result.cpu.arch.isLoongArch()) continue; // https://github.com/Vexu/arocc/issues/1096
107119
108 const glibc_ver = target.result.os.version_range.linux.glibc;120 const glibc_ver = target.result.os.version_range.linux.glibc;
test/standalone/install_raw_hex/build.zig+6
...@@ -1,7 +1,11 @@...@@ -1,7 +1,11 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
33
4pub const supports_skip_non_native = true;
5
4pub fn build(b: *std.Build) void {6pub fn build(b: *std.Build) void {
7 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
8
5 const test_step = b.step("test", "Test it");9 const test_step = b.step("test", "Test it");
6 b.default_step = test_step;10 b.default_step = test_step;
711
...@@ -12,6 +16,8 @@ pub fn build(b: *std.Build) void {...@@ -12,6 +16,8 @@ pub fn build(b: *std.Build) void {
12 .abi = .gnueabihf,16 .abi = .gnueabihf,
13 });17 });
1418
19 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
20
15 const optimize: std.builtin.Optimize = .debug;21 const optimize: std.builtin.Optimize = .debug;
1622
17 const elf = b.addExecutable(.{23 const elf = b.addExecutable(.{
test/standalone/tsan/build.zig+6
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");1const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
3const targets: []const std.Target.Query = &.{5const targets: []const std.Target.Query = &.{
4 .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none },6 .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none },
5 .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none },7 .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none },
...@@ -32,6 +34,8 @@ const targets: []const std.Target.Query = &.{...@@ -32,6 +34,8 @@ const targets: []const std.Target.Query = &.{
32};34};
3335
34pub fn build(b: *std.Build) !void {36pub fn build(b: *std.Build) !void {
37 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
38
35 const test_step = b.step("test", "Test the program");39 const test_step = b.step("test", "Test the program");
36 b.default_step = test_step;40 b.default_step = test_step;
3741
...@@ -40,6 +44,8 @@ pub fn build(b: *std.Build) !void {...@@ -40,6 +44,8 @@ pub fn build(b: *std.Build) !void {
40 for (targets) |query| {44 for (targets) |query| {
41 const target = b.resolveTargetQuery(query);45 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
43 switch (target.result.os.tag) {49 switch (target.result.os.tag) {
44 .macos => {50 .macos => {
45 // compiling tsan on macos requires system headers that aren't present during cross-compilation51 // 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 @@...@@ -1,6 +1,10 @@
1const std = @import("std");1const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
3pub fn build(b: *std.Build) void {5pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
4 const test_step = b.step("test", "Test it");8 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;9 b.default_step = test_step;
610
...@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {...@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {
10 .abi = .gnu,14 .abi = .gnu,
11 });15 });
1216
17 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
18
13 {19 {
14 const exe = b.addExecutable(.{20 const exe = b.addExecutable(.{
15 .name = "main",21 .name = "main",
test/standalone/windows_resources/build.zig+6
...@@ -1,6 +1,10 @@...@@ -1,6 +1,10 @@
1const std = @import("std");1const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
3pub fn build(b: *std.Build) void {5pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
4 const test_step = b.step("test", "Test it");8 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;9 b.default_step = test_step;
610
...@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {...@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {
10 .abi = .gnu,14 .abi = .gnu,
11 });15 });
1216
17 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
18
13 const generated_h_step = b.addWriteFile("generated.h", "#define GENERATED_DEFINE \"foo\"");19 const generated_h_step = b.addWriteFile("generated.h", "#define GENERATED_DEFINE \"foo\"");
1420
15 add(b, b.graph.host, .any, test_step, generated_h_step);21 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...@@ -2374,6 +2374,7 @@ pub fn addErrorTraceTests(b: *std.Build, options: ErrorTracesContext.Options) *S
2374pub fn addStandaloneTests(2374pub fn addStandaloneTests(
2375 b: *std.Build,2375 b: *std.Build,
2376 optimize_modes: []const OptimizeMode,2376 optimize_modes: []const OptimizeMode,
2377 skip_non_native: bool,
2377 enable_macos_sdk: bool,2378 enable_macos_sdk: bool,
2378 enable_ios_sdk: bool,2379 enable_ios_sdk: bool,
2379 enable_symlinks_windows: bool,2380 enable_symlinks_windows: bool,
...@@ -2388,6 +2389,7 @@ pub fn addStandaloneTests(...@@ -2388,6 +2389,7 @@ pub fn addStandaloneTests(
2388 .simple_skip_release_safe = mem.findScalar(OptimizeMode, optimize_modes, .safe) == null,2389 .simple_skip_release_safe = mem.findScalar(OptimizeMode, optimize_modes, .safe) == null,
2389 .simple_skip_release_fast = mem.findScalar(OptimizeMode, optimize_modes, .fast) == null,2390 .simple_skip_release_fast = mem.findScalar(OptimizeMode, optimize_modes, .fast) == null,
2390 .simple_skip_release_small = mem.findScalar(OptimizeMode, optimize_modes, .small) == null,2391 .simple_skip_release_small = mem.findScalar(OptimizeMode, optimize_modes, .small) == null,
2392 .skip_non_native = skip_non_native,
2391 });2393 });
2392 const test_cases_dep_step = test_cases_dep.builder.default_step;2394 const test_cases_dep_step = test_cases_dep.builder.default_step;
2393 test_cases_dep_step.name = test_cases_dep_name;2395 test_cases_dep_step.name = test_cases_dep_name;