From 72388e28e4f3786743b33c4075b8f9dddc1babea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:14:52 +0200 Subject: [PATCH 01/19] test: remove orphan gen_h.zig --- test/gen_h.zig | 148 ------------------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 test/gen_h.zig diff --git a/test/gen_h.zig b/test/gen_h.zig deleted file mode 100644 index a41f4d6f82eae683ba857745bbf52c6538c11ebf..0000000000000000000000000000000000000000 --- a/test/gen_h.zig +++ /dev/null @@ -1,148 +0,0 @@ -const tests = @import("tests.zig"); - -pub fn addCases(cases: *tests.GenHContext) void { - cases.add("declare enum", - \\const Foo = extern enum { A, B, C }; - \\export fn entry(foo: Foo) void { } - , &[_][]const u8{ - \\enum Foo { - \\ A = 0, - \\ B = 1, - \\ C = 2 - \\}; - , - \\void entry(enum Foo foo); - }); - - cases.add("declare struct", - \\const Foo = extern struct { - \\ A: i32, - \\ B: f32, - \\ C: bool, - \\ D: u64, - \\ E: u64, - \\ F: u64, - \\}; - \\export fn entry(foo: Foo) void { } - , &[_][]const u8{ - \\struct Foo { - \\ int32_t A; - \\ float B; - \\ bool C; - \\ uint64_t D; - \\ uint64_t E; - \\ uint64_t F; - \\}; - , - \\void entry(struct Foo foo); - \\ - }); - - cases.add("declare union", - \\const Big = extern struct { - \\ A: u64, - \\ B: u64, - \\ C: u64, - \\ D: u64, - \\ E: u64, - \\}; - \\const Foo = extern union { - \\ A: i32, - \\ B: f32, - \\ C: bool, - \\ D: Big, - \\}; - \\export fn entry(foo: Foo) void {} - , &[_][]const u8{ - \\struct Big { - \\ uint64_t A; - \\ uint64_t B; - \\ uint64_t C; - \\ uint64_t D; - \\ uint64_t E; - \\}; - \\ - \\union Foo { - \\ int32_t A; - \\ float B; - \\ bool C; - \\ struct Big D; - \\}; - , - \\void entry(union Foo foo); - \\ - }); - - cases.add("declare opaque type", - \\const Foo = opaque {}; - \\ - \\export fn entry(foo: ?*Foo) void { } - , &[_][]const u8{ - \\struct Foo; - , - \\void entry(struct Foo * foo); - }); - - cases.add("array field-type", - \\const Foo = extern struct { - \\ A: [2]i32, - \\ B: [4]*u32, - \\}; - \\export fn entry(foo: Foo, bar: [3]u8) void { } - , &[_][]const u8{ - \\struct Foo { - \\ int32_t A[2]; - \\ uint32_t * B[4]; - \\}; - , - \\void entry(struct Foo foo, uint8_t bar[]); - \\ - }); - - cases.add("ptr to zig struct", - \\const S = struct { - \\ a: u8, - \\}; - \\ - \\export fn a(s: *S) u8 { - \\ return s.a; - \\} - , &[_][]const u8{ - \\struct S; - , - \\uint8_t a(struct S * s); - \\ - }); - - cases.add("ptr to zig union", - \\const U = union(enum) { - \\ A: u8, - \\ B: u16, - \\}; - \\ - \\export fn a(s: *U) u8 { - \\ return s.A; - \\} - , &[_][]const u8{ - \\union U; - , - \\uint8_t a(union U * s); - \\ - }); - - cases.add("ptr to zig enum", - \\const E = enum(u8) { - \\ A, - \\ B, - \\}; - \\ - \\export fn a(s: *E) u8 { - \\ return @intFromEnum(s.*); - \\} - , &[_][]const u8{ - \\enum E; - , - \\uint8_t a(enum E * s); - \\ - }); -} -- 2.54.0 From d7061f33786b5f7fa15cb73359100c1fc485646e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:25:46 +0200 Subject: [PATCH 02/19] test: move empty_global_error_set from test-standalone to test-cases --- .../empty_global_error_set.zig} | 2 ++ test/standalone/build.zig.zon | 3 --- .../empty_global_error_set/build.zig | 24 ------------------- 3 files changed, 2 insertions(+), 27 deletions(-) rename test/{standalone/empty_global_error_set/main.zig => cases/empty_global_error_set.zig} (91%) delete mode 100644 test/standalone/empty_global_error_set/build.zig diff --git a/test/standalone/empty_global_error_set/main.zig b/test/cases/empty_global_error_set.zig similarity index 91% rename from test/standalone/empty_global_error_set/main.zig rename to test/cases/empty_global_error_set.zig index ecf7cf5167709c8fad7b37c5a4b72c203a30b3f9..987e2e2628b7d87a6564c0ec2d25cca52f0e7c03 100644 --- a/test/standalone/empty_global_error_set/main.zig +++ b/test/cases/empty_global_error_set.zig @@ -2,3 +2,5 @@ fn errorName(err: anyerror) [:0]const u8 { return @errorName(err); } export const error_name: *const anyopaque = &errorName; + +// compile diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index e134d00bd7d5977cda3341787a3dfefca86b4b7c..895af508f35ee03916312dc6099d9c8c3e301641 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -168,9 +168,6 @@ .run_output_paths = .{ .path = "run_output_paths", }, - .empty_global_error_set = .{ - .path = "empty_global_error_set", - }, .config_header = .{ .path = "config_header", }, diff --git a/test/standalone/empty_global_error_set/build.zig b/test/standalone/empty_global_error_set/build.zig deleted file mode 100644 index ad971aa6d113791521ee42afdfb06070d06d0cbb..0000000000000000000000000000000000000000 --- a/test/standalone/empty_global_error_set/build.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - for ([_]bool{ false, true }) |use_llvm| { - const main = b.addObject(.{ - .name = "main", - .root_module = b.createModule(.{ - .root_source_file = b.path("main.zig"), - .target = b.resolveTargetQuery(.{ - .cpu_arch = .x86_64, - .os_tag = .linux, - }), - }), - .use_llvm = use_llvm, - .use_lld = use_llvm, - }); - _ = main.getEmittedBin(); - test_step.dependOn(&main.step); - } -} -- 2.54.0 From 78dbc6fab87fe6bd55525d13195c41559a60129f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:32:43 +0200 Subject: [PATCH 03/19] test: move strip_empty_loop from test-standalone to test-behavior --- test/behavior/while.zig | 8 ++++++++ test/standalone/build.zig.zon | 3 --- test/standalone/strip_empty_loop/build.zig | 24 ---------------------- test/standalone/strip_empty_loop/main.zig | 3 --- 4 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 test/standalone/strip_empty_loop/build.zig delete mode 100644 test/standalone/strip_empty_loop/main.zig diff --git a/test/behavior/while.zig b/test/behavior/while.zig index f08c045c831cdb2b2cecd99c6b968c2b869b8cf1..695d67f02045da638eafc71d7a651d68be17538a 100644 --- a/test/behavior/while.zig +++ b/test/behavior/while.zig @@ -419,3 +419,11 @@ test "labeled break from else" { try S.doTheTest(5); try comptime S.doTheTest(5); } + +fn infiniteLoop() noreturn { + while (true) {} +} + +test "infinite while true" { + _ = &infiniteLoop; +} diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 895af508f35ee03916312dc6099d9c8c3e301641..f0f7f6175be9106127036332c31e75e0e902e6fe 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -135,9 +135,6 @@ .issue_12706 = .{ .path = "issue_12706", }, - .strip_empty_loop = .{ - .path = "strip_empty_loop", - }, .strip_struct_init = .{ .path = "strip_struct_init", }, diff --git a/test/standalone/strip_empty_loop/build.zig b/test/standalone/strip_empty_loop/build.zig deleted file mode 100644 index 1e14c641f09d469c3f6cbd52ab679d940e8de468..0000000000000000000000000000000000000000 --- a/test/standalone/strip_empty_loop/build.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test the program"); - b.default_step = test_step; - - const optimize = std.builtin.Optimize.debug; - const target = b.graph.host; - - const main = b.addExecutable(.{ - .name = "main", - .root_module = b.createModule(.{ - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, - .strip = true, - }), - }); - - // TODO: actually check the output - _ = main.getEmittedBin(); - - test_step.dependOn(&main.step); -} diff --git a/test/standalone/strip_empty_loop/main.zig b/test/standalone/strip_empty_loop/main.zig deleted file mode 100644 index bfcb5ac94b34ced62025854026422057044003ee..0000000000000000000000000000000000000000 --- a/test/standalone/strip_empty_loop/main.zig +++ /dev/null @@ -1,3 +0,0 @@ -pub fn main() noreturn { - while (true) {} // When built without debug info, this produces an Air loop with no instructions -} -- 2.54.0 From c3ee048475bf99432e2d278fba5cc59ea05bde9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:49:11 +0200 Subject: [PATCH 04/19] test-cases: remove hello_world.zig Covered by test/standalone/simple/hello_world/*. --- test/cases/hello_world.zig | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 test/cases/hello_world.zig diff --git a/test/cases/hello_world.zig b/test/cases/hello_world.zig deleted file mode 100644 index 8a75c68d2b84bcdf2d179ffed204288a85a941e4..0000000000000000000000000000000000000000 --- a/test/cases/hello_world.zig +++ /dev/null @@ -1,13 +0,0 @@ -extern fn puts(s: [*:0]const u8) c_int; - -pub fn main() void { - _ = puts("hello world!"); -} - -// run -// backend=selfhosted,llvm -// target=x86_64-linux,x86_64-macos -// link_libc=true -// -// hello world! -// -- 2.54.0 From 562f265d391b3ecf0cdbcbef7aac6ae3fc1f0080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:14:22 +0200 Subject: [PATCH 05/19] test-standalone: remove orphan has_basename.zig in dirname --- test/standalone/dirname/has_basename.zig | 37 ------------------------ 1 file changed, 37 deletions(-) delete mode 100644 test/standalone/dirname/has_basename.zig diff --git a/test/standalone/dirname/has_basename.zig b/test/standalone/dirname/has_basename.zig deleted file mode 100644 index e0e408a3a491446cc17ed72c64d958bd88b62ec0..0000000000000000000000000000000000000000 --- a/test/standalone/dirname/has_basename.zig +++ /dev/null @@ -1,37 +0,0 @@ -//! Checks that the basename of the given path matches a string. -//! -//! Usage: -//! -//! ``` -//! has_basename -//! ``` -//! -//! must be absolute. -//! -//! Returns a non-zero exit code if basename -//! does not match the given string. - -const std = @import("std"); - -pub fn main(init: std.process.Init) !void { - var args = try init.minimal.args.iterateAllocator(init.gpa); - defer args.deinit(); - _ = args.next() orelse unreachable; // skip binary name - - const path = args.next() orelse { - std.log.err("missing argument", .{}); - return error.BadUsage; - }; - - const basename = args.next() orelse { - std.log.err("missing argument", .{}); - return error.BadUsage; - }; - - const actual_basename = std.fs.path.basename(path); - if (std.mem.eql(u8, actual_basename, basename)) { - return; - } - - return error.NotEqual; -} -- 2.54.0 From 5514aa95fa94ae0f1c32f5215f59713a850a553a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:12:40 +0200 Subject: [PATCH 06/19] test-standalone: remove stale comment in simple --- test/standalone/simple/build.zig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/standalone/simple/build.zig b/test/standalone/simple/build.zig index 45dd49648d619c2a73bda7b1928930a3a62963e3..5a24a955f41e5f2cf1d50386f7a9b95bdde87309 100644 --- a/test/standalone/simple/build.zig +++ b/test/standalone/simple/build.zig @@ -97,10 +97,6 @@ const cases = [_]Case{ .{ .src_path = "cat/main.zig", }, - // https://github.com/ziglang/zig/issues/6025 - //.{ - // .src_path = "issue_9693/main.zig", - //}, .{ .src_path = "issue_7030.zig", .target = .{ -- 2.54.0 From 41ca6e86577556d69c50c9ff49933c0f55922843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:36:58 +0200 Subject: [PATCH 07/19] test-standalone: remove issue_9402 from simple I do not think we need to add tests like this whenever new functions are added to MinGW-w64. We have plans for more sophisticated C ABI tooling. --- test/standalone/simple/build.zig | 5 ----- test/standalone/simple/issue_9402/main.zig | 14 -------------- 2 files changed, 19 deletions(-) delete mode 100644 test/standalone/simple/issue_9402/main.zig diff --git a/test/standalone/simple/build.zig b/test/standalone/simple/build.zig index 5a24a955f41e5f2cf1d50386f7a9b95bdde87309..730c3fc25c0259bc3f73a393add8e06871489f7b 100644 --- a/test/standalone/simple/build.zig +++ b/test/standalone/simple/build.zig @@ -110,9 +110,4 @@ const cases = [_]Case{ .{ .src_path = "noreturn_call/inline.zig" }, .{ .src_path = "noreturn_call/as_arg.zig" }, .{ .src_path = "std_enums_big_enums.zig" }, - .{ - .src_path = "issue_9402/main.zig", - .os_filter = .windows, - .link_libc = true, - }, }; diff --git a/test/standalone/simple/issue_9402/main.zig b/test/standalone/simple/issue_9402/main.zig deleted file mode 100644 index eea6bbf4b5e145b7a62b525a2f66bb4cb92b08a5..0000000000000000000000000000000000000000 --- a/test/standalone/simple/issue_9402/main.zig +++ /dev/null @@ -1,14 +0,0 @@ -const FILE = extern struct { - dummy_field: u8, -}; - -extern fn _ftelli64([*c]FILE) i64; -extern fn _fseeki64([*c]FILE, i64, c_int) c_int; - -pub export fn main(argc: c_int, argv: **u8) c_int { - _ = argv; - _ = argc; - _ = _ftelli64(null); - _ = _fseeki64(null, 123, 2); - return 0; -} -- 2.54.0 From cc410eaf341c7ad054cebcc010bb8e62fbc93098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:05:30 +0200 Subject: [PATCH 08/19] test-standalone: remove compiler_rt_panic It's not obvious to me what this was testing and it wasn't properly hooked up to the test_step anyway. --- test/standalone/build.zig.zon | 3 --- test/standalone/compiler_rt_panic/build.zig | 28 --------------------- test/standalone/compiler_rt_panic/main.c | 11 -------- 3 files changed, 42 deletions(-) delete mode 100644 test/standalone/compiler_rt_panic/build.zig delete mode 100644 test/standalone/compiler_rt_panic/main.c diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index f0f7f6175be9106127036332c31e75e0e902e6fe..70fa17180500779d389ac25eb5c491ac4939cb99 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -144,9 +144,6 @@ .coff_dwarf = .{ .path = "coff_dwarf", }, - .compiler_rt_panic = .{ - .path = "compiler_rt_panic", - }, .ios = .{ .path = "ios", }, diff --git a/test/standalone/compiler_rt_panic/build.zig b/test/standalone/compiler_rt_panic/build.zig deleted file mode 100644 index 27f38d369134eaff54ce3721383785dd93047df6..0000000000000000000000000000000000000000 --- a/test/standalone/compiler_rt_panic/build.zig +++ /dev/null @@ -1,28 +0,0 @@ -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - - if (target.result.ofmt != .elf or !(target.result.abi.isMusl() or target.result.abi.isGnu())) - return; - - const exe = b.addExecutable(.{ - .name = "main", - .root_module = b.createModule(.{ - .root_source_file = null, - .optimize = optimize, - .target = target, - .link_libc = true, - }), - }); - exe.root_module.addCSourceFile(.{ - .file = b.path("main.c"), - .flags = &.{}, - }); - exe.link_gc_sections = false; - exe.bundle_compiler_rt = true; -} diff --git a/test/standalone/compiler_rt_panic/main.c b/test/standalone/compiler_rt_panic/main.c deleted file mode 100644 index a11df761aaa60fc388163ccd76e82906767d146f..0000000000000000000000000000000000000000 --- a/test/standalone/compiler_rt_panic/main.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -void *__memset_chk(void *dest, int c, size_t n, size_t dest_n); - -char foo[128]; - -int main() { - __memset_chk(&foo[0], 0xff, 128, 128); - return foo[64]; -} - -- 2.54.0 From a3fe5cb793759d2b9526ac8b7ad96e30a08813d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:07:39 +0200 Subject: [PATCH 09/19] test-standalone: remove zerolength_check We don't need this anymore since our baseline CPU model for wasm is lime1. --- test/standalone/build.zig.zon | 3 --- test/standalone/zerolength_check/build.zig | 27 ------------------- test/standalone/zerolength_check/src/main.zig | 24 ----------------- 3 files changed, 54 deletions(-) delete mode 100644 test/standalone/zerolength_check/build.zig delete mode 100644 test/standalone/zerolength_check/src/main.zig diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 70fa17180500779d389ac25eb5c491ac4939cb99..d5489dbf828e89040ca2233fd3bfdf57a7e91366 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -138,9 +138,6 @@ .strip_struct_init = .{ .path = "strip_struct_init", }, - .zerolength_check = .{ - .path = "zerolength_check", - }, .coff_dwarf = .{ .path = "coff_dwarf", }, diff --git a/test/standalone/zerolength_check/build.zig b/test/standalone/zerolength_check/build.zig deleted file mode 100644 index 19102ef6d68bb0cd948b1b0598e5578776c48dc5..0000000000000000000000000000000000000000 --- a/test/standalone/zerolength_check/build.zig +++ /dev/null @@ -1,27 +0,0 @@ -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - add(b, test_step, .debug); - add(b, test_step, .fast); - add(b, test_step, .small); - add(b, test_step, .safe); -} - -fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize) void { - const unit_tests = b.addTest(.{ .root_module = b.createModule(.{ - .root_source_file = b.path("src/main.zig"), - .target = b.resolveTargetQuery(.{ - .os_tag = .wasi, - .cpu_arch = .wasm32, - .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}), - }), - .optimize = optimize, - }) }); - - const run_unit_tests = b.addRunArtifact(unit_tests); - run_unit_tests.skip_foreign_checks = true; - test_step.dependOn(&run_unit_tests.step); -} diff --git a/test/standalone/zerolength_check/src/main.zig b/test/standalone/zerolength_check/src/main.zig deleted file mode 100644 index 2f674ab4ff0aa086c4a85bdde01796e086ff7653..0000000000000000000000000000000000000000 --- a/test/standalone/zerolength_check/src/main.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -test { - const dest = foo(); - const source = foo(); - - @memcpy(dest, source); - @memmove(dest, source); - @memset(dest, 4); - @memset(dest, undefined); - - const dest2 = foo2(); - @memset(dest2, 0); -} - -fn foo() []u8 { - const ptr = comptime std.mem.alignBackward(usize, std.math.maxInt(usize), 1); - return @as([*]align(1) u8, @ptrFromInt(ptr))[0..0]; -} - -fn foo2() []u64 { - const ptr = comptime std.mem.alignBackward(usize, std.math.maxInt(usize), 1); - return @as([*]align(1) u64, @ptrFromInt(ptr))[0..0]; -} -- 2.54.0 From c3cb062d03d9c4eced740b61a76e6c746d67db8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:19:07 +0200 Subject: [PATCH 10/19] test-standalone: remove issue_339 I don't think this provides any useful coverage nowadays. --- test/standalone/build.zig.zon | 3 --- test/standalone/issue_339/build.zig | 23 ----------------------- test/standalone/issue_339/test.zig | 13 ------------- 3 files changed, 39 deletions(-) delete mode 100644 test/standalone/issue_339/build.zig delete mode 100644 test/standalone/issue_339/test.zig diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index d5489dbf828e89040ca2233fd3bfdf57a7e91366..39c2d3d3651d5d105814981d73cfd671da284e96 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -30,9 +30,6 @@ .static_c_lib = .{ .path = "static_c_lib", }, - .issue_339 = .{ - .path = "issue_339", - }, .compile_asm = .{ .path = "compile_asm", }, diff --git a/test/standalone/issue_339/build.zig b/test/standalone/issue_339/build.zig deleted file mode 100644 index 6e2ed10d4477f9fe9b9c8687fe7a081541d2d5eb..0000000000000000000000000000000000000000 --- a/test/standalone/issue_339/build.zig +++ /dev/null @@ -1,23 +0,0 @@ -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - const optimize: std.builtin.Optimize = .debug; - const target = b.graph.host; - - const obj = b.addObject(.{ - .name = "test", - .root_module = b.createModule(.{ - .root_source_file = b.path("test.zig"), - .target = target, - .optimize = optimize, - }), - }); - - // TODO: actually check the output - _ = obj.getEmittedBin(); - - test_step.dependOn(&obj.step); -} diff --git a/test/standalone/issue_339/test.zig b/test/standalone/issue_339/test.zig deleted file mode 100644 index e28839209c1988a68fb46c269a32d5d0b311cfd5..0000000000000000000000000000000000000000 --- a/test/standalone/issue_339/test.zig +++ /dev/null @@ -1,13 +0,0 @@ -const StackTrace = @import("std").builtin.StackTrace; -pub fn panic(msg: []const u8, stack_trace: ?*StackTrace, _: ?usize) noreturn { - _ = msg; - _ = stack_trace; - @breakpoint(); - while (true) {} -} - -fn bar() anyerror!void {} - -export fn foo() void { - bar() catch unreachable; -} -- 2.54.0 From 03d537b3035dae0c3ed73d24a50ecd42bd44523c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:21:23 +0200 Subject: [PATCH 11/19] test-standalone: remove issue_5825 This doesn't provide any coverage we don't already have in various other places. --- test/standalone/build.zig.zon | 3 -- test/standalone/issue_5825/build.zig | 43 ---------------------------- test/standalone/issue_5825/main.zig | 5 ---- 3 files changed, 51 deletions(-) delete mode 100644 test/standalone/issue_5825/build.zig delete mode 100644 test/standalone/issue_5825/main.zig diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 39c2d3d3651d5d105814981d73cfd671da284e96..373dfcf75b15b4614b964bc587e873444cccfc88 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -33,9 +33,6 @@ .compile_asm = .{ .path = "compile_asm", }, - .issue_5825 = .{ - .path = "issue_5825", - }, .pkg_import = .{ .path = "pkg_import", }, diff --git a/test/standalone/issue_5825/build.zig b/test/standalone/issue_5825/build.zig deleted file mode 100644 index 10a23101966b0e9b2a40043e7934eff377171059..0000000000000000000000000000000000000000 --- a/test/standalone/issue_5825/build.zig +++ /dev/null @@ -1,43 +0,0 @@ -const builtin = @import("builtin"); -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - // Building for the msvc abi requires a native MSVC installation - if (builtin.os.tag != .windows or builtin.cpu.arch != .x86_64) return; - - const target = b.resolveTargetQuery(.{ - .cpu_arch = .x86_64, - .os_tag = .windows, - .abi = .msvc, - }); - const optimize: std.builtin.Optimize = .debug; - const obj = b.addObject(.{ - .name = "issue_5825", - .root_module = b.createModule(.{ - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, - }), - }); - - const exe = b.addExecutable(.{ - .name = "issue_5825", - .root_module = b.createModule(.{ - .root_source_file = null, - .optimize = optimize, - .target = target, - }), - }); - exe.subsystem = .console; - exe.root_module.linkSystemLibrary("kernel32", .{}); - exe.root_module.linkSystemLibrary("ntdll", .{}); - exe.root_module.addObject(obj); - - // TODO: actually check the output - _ = exe.getEmittedBin(); - - test_step.dependOn(&exe.step); -} diff --git a/test/standalone/issue_5825/main.zig b/test/standalone/issue_5825/main.zig deleted file mode 100644 index d29869ff88feb94cd5a5fd28d760824920f269ac..0000000000000000000000000000000000000000 --- a/test/standalone/issue_5825/main.zig +++ /dev/null @@ -1,5 +0,0 @@ -const std = @import("std"); - -pub fn main() anyerror!void { - std.log.info("All your codebase are belong to us.", .{}); -} -- 2.54.0 From 47a2437afb3c392771eed8a26aac1bb3c84963af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:33:25 +0200 Subject: [PATCH 12/19] test-standalone: remove strip_struct_init We have stripped variants in the module test matrix, and I don't think the test code here provides useful coverage on its own. --- test/standalone/build.zig.zon | 3 --- test/standalone/strip_struct_init/build.zig | 19 ----------------- test/standalone/strip_struct_init/main.zig | 23 --------------------- 3 files changed, 45 deletions(-) delete mode 100644 test/standalone/strip_struct_init/build.zig delete mode 100644 test/standalone/strip_struct_init/main.zig diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 373dfcf75b15b4614b964bc587e873444cccfc88..4c4961ccb991405e08aae11733a09cf9ca7e467f 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -129,9 +129,6 @@ .issue_12706 = .{ .path = "issue_12706", }, - .strip_struct_init = .{ - .path = "strip_struct_init", - }, .coff_dwarf = .{ .path = "coff_dwarf", }, diff --git a/test/standalone/strip_struct_init/build.zig b/test/standalone/strip_struct_init/build.zig deleted file mode 100644 index 7dfeb9b45ed5cbdaf269f02e04c7bff4fa527285..0000000000000000000000000000000000000000 --- a/test/standalone/strip_struct_init/build.zig +++ /dev/null @@ -1,19 +0,0 @@ -const std = @import("std"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - const optimize: std.builtin.Optimize = .debug; - - const main = b.addTest(.{ - .root_module = b.createModule(.{ - .root_source_file = b.path("main.zig"), - .target = b.graph.host, - .optimize = optimize, - .strip = true, - }), - }); - - test_step.dependOn(&b.addRunArtifact(main).step); -} diff --git a/test/standalone/strip_struct_init/main.zig b/test/standalone/strip_struct_init/main.zig deleted file mode 100644 index 4f3d63c960cc147dfead795cdf55c00cbe18f1f5..0000000000000000000000000000000000000000 --- a/test/standalone/strip_struct_init/main.zig +++ /dev/null @@ -1,23 +0,0 @@ -fn Func(comptime Type: type) type { - return struct { value: Type }; -} - -inline fn func(value: anytype) Func(@TypeOf(value)) { - return .{ .value = value }; -} - -test { - _ = func(type); -} - -test { - const S = struct { field: u32 }; - comptime var arr: [1]S = undefined; - arr[0] = .{ .field = 0 }; -} - -test { - const S = struct { u32 }; - comptime var arr: [1]S = undefined; - arr[0] = .{0}; -} -- 2.54.0 From 40a50f5e2cd4900d2b3d13b353b18a8b6ae052af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 08:46:20 +0200 Subject: [PATCH 13/19] test: move issue_12706 from test-standalone to test-c-abi --- test/c_abi/cfuncs.c | 11 ++++++++++ test/c_abi/main.zig | 11 ++++++++++ test/standalone/build.zig.zon | 3 --- test/standalone/issue_12706/build.zig | 30 --------------------------- test/standalone/issue_12706/main.zig | 12 ----------- test/standalone/issue_12706/test.c | 11 ---------- 6 files changed, 22 insertions(+), 56 deletions(-) delete mode 100644 test/standalone/issue_12706/build.zig delete mode 100644 test/standalone/issue_12706/main.zig delete mode 100644 test/standalone/issue_12706/test.c diff --git a/test/c_abi/cfuncs.c b/test/c_abi/cfuncs.c index cce4f0d77497f2c6579fcd25eb0a6028dc2b1064..66e682571ecde322efbeca5617d89cc0904ab0d6 100644 --- a/test/c_abi/cfuncs.c +++ b/test/c_abi/cfuncs.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -16775,6 +16776,16 @@ void c_x86_64_sysv_uint_int_uint_int(unsigned a, int b, unsigned c, int d) { assert_or_panic(d == -4); } +void c_varargs_fn_ptr(int n, ...) { + assert_or_panic(n == 2); + va_list ap; + va_start(ap, n); + void (*fn_ptr)(int) = va_arg(ap, void (*)(int)); + int arg = va_arg(ap, int); + va_end(ap); + fn_ptr(arg); +} + void c_win64_varargs_u64_f64_u64_f64(uint64_t a, double b, uint64_t c, double d) { assert_or_panic(a == UINT64_C(0x3ff0000000000000)); assert_or_panic(b == 2.0); diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index e7b98a181148e9aecfe3aeb775e8e3f62c15f036..d0022d01babcc7d9fae9d5d6a987f3092c83eadf 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -18009,6 +18009,17 @@ test "x86_64 sysv args" { c_x86_64_sysv_uint_int_uint_int(1, -2, 3, -4); } +extern fn c_varargs_fn_ptr(n: c_int, ...) void; + +fn zigVaCb(x: c_int) callconv(.c) void { + expect(x == 123) catch @panic("test failure: zigVaCb"); +} + +test "function pointer through varargs" { + // Bare function (not `&`), as in the original #12706 repro. + c_varargs_fn_ptr(2, zigVaCb, @as(c_int, 123)); +} + extern fn c_win64_varargs_u64_f64_u64_f64(...) void; extern fn c_win64_varargs_f64_u64_f64_u64(...) void; diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 4c4961ccb991405e08aae11733a09cf9ca7e467f..9fd1de096b937d0b3cc0315228bc5fbfae8126c7 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -126,9 +126,6 @@ .c_embed_path = .{ .path = "c_embed_path", }, - .issue_12706 = .{ - .path = "issue_12706", - }, .coff_dwarf = .{ .path = "coff_dwarf", }, diff --git a/test/standalone/issue_12706/build.zig b/test/standalone/issue_12706/build.zig deleted file mode 100644 index e2b4d4fe2bf61750bd7e1435237385c502cde0b4..0000000000000000000000000000000000000000 --- a/test/standalone/issue_12706/build.zig +++ /dev/null @@ -1,30 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - const optimize: std.builtin.Optimize = .debug; - const target = b.graph.host; - - const exe = b.addExecutable(.{ - .name = "main", - .root_module = b.createModule(.{ - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, - }), - }); - - const c_sources = [_][]const u8{ - "test.c", - }; - exe.root_module.addCSourceFiles(.{ .files = &c_sources }); - exe.root_module.link_libc = true; - - const run_cmd = b.addRunArtifact(exe); - run_cmd.expectExitCode(0); - run_cmd.skip_foreign_checks = true; - test_step.dependOn(&run_cmd.step); -} diff --git a/test/standalone/issue_12706/main.zig b/test/standalone/issue_12706/main.zig deleted file mode 100644 index dc402ab92f80be8fae8a884c8c7b6b9452d57272..0000000000000000000000000000000000000000 --- a/test/standalone/issue_12706/main.zig +++ /dev/null @@ -1,12 +0,0 @@ -const std = @import("std"); -extern fn testFnPtr(n: c_int, ...) void; - -const val: c_int = 123; - -fn func(a: c_int) callconv(.c) void { - std.debug.assert(a == val); -} - -pub fn main() void { - testFnPtr(2, func, val); -} diff --git a/test/standalone/issue_12706/test.c b/test/standalone/issue_12706/test.c deleted file mode 100644 index 30b5c6269778dbf0ea000e2f9a65cb0b5ce0f67b..0000000000000000000000000000000000000000 --- a/test/standalone/issue_12706/test.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -void testFnPtr(int n, ...) { - va_list ap; - va_start(ap, n); - - void (*fnPtr)(int) = va_arg(ap, void (*)(int)); - int arg = va_arg(ap, int); - fnPtr(arg); - va_end(ap); -} \ No newline at end of file -- 2.54.0 From 4fb39f82c2a5a57b497c741093e95e1e8e1a57fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 09:04:42 +0200 Subject: [PATCH 14/19] test: move some test-standalone simple tests to test-cases --- .../error_u8.zig => cases/main_return_error_u8.zig} | 3 +++ .../main_return_error_u8_non_zero.zig} | 3 +++ .../as_arg.zig => cases/noreturn_call_as_arg.zig} | 5 +++++ .../inline.zig => cases/noreturn_call_inline.zig} | 7 ++++++- test/standalone/simple/build.zig | 4 ---- 5 files changed, 17 insertions(+), 5 deletions(-) rename test/{standalone/simple/main_return_error/error_u8.zig => cases/main_return_error_u8.zig} (68%) rename test/{standalone/simple/main_return_error/error_u8_non_zero.zig => cases/main_return_error_u8_non_zero.zig} (81%) rename test/{standalone/simple/noreturn_call/as_arg.zig => cases/noreturn_call_as_arg.zig} (93%) rename test/{standalone/simple/noreturn_call/inline.zig => cases/noreturn_call_inline.zig} (93%) diff --git a/test/standalone/simple/main_return_error/error_u8.zig b/test/cases/main_return_error_u8.zig similarity index 68% rename from test/standalone/simple/main_return_error/error_u8.zig rename to test/cases/main_return_error_u8.zig index 8fbe1e8f6595e350964d9ba61e4c94091988fe9c..3607e355dd6eb9a22aa8385db95618f15f60da50 100644 --- a/test/standalone/simple/main_return_error/error_u8.zig +++ b/test/cases/main_return_error_u8.zig @@ -3,3 +3,6 @@ const Err = error{Foo}; pub fn main() !u8 { return Err.Foo; } + +// compile +// output_mode=Exe diff --git a/test/standalone/simple/main_return_error/error_u8_non_zero.zig b/test/cases/main_return_error_u8_non_zero.zig similarity index 81% rename from test/standalone/simple/main_return_error/error_u8_non_zero.zig rename to test/cases/main_return_error_u8_non_zero.zig index 47fe7946ec1e4ce6fdd33a749fc11d313eb3f3ab..278223c114e3dbe7d7fe853ee05758a95ac97bfa 100644 --- a/test/standalone/simple/main_return_error/error_u8_non_zero.zig +++ b/test/cases/main_return_error_u8_non_zero.zig @@ -8,3 +8,6 @@ pub fn main() !u8 { if (foo() == 7) return Err.Foo; return 123; } + +// compile +// output_mode=Exe diff --git a/test/standalone/simple/noreturn_call/as_arg.zig b/test/cases/noreturn_call_as_arg.zig similarity index 93% rename from test/standalone/simple/noreturn_call/as_arg.zig rename to test/cases/noreturn_call_as_arg.zig index 08a4f0bd75803280775cd7644bec88b850e0b344..c9c792c02754c10c8965b2fc9f1b3d24103610a9 100644 --- a/test/standalone/simple/noreturn_call/as_arg.zig +++ b/test/cases/noreturn_call_as_arg.zig @@ -1,8 +1,13 @@ const std = @import("std"); + fn foo() noreturn { std.process.exit(0); } + fn bar(_: u8, _: u8) void {} + pub fn main() void { bar(foo(), @compileError("bad")); } + +// run diff --git a/test/standalone/simple/noreturn_call/inline.zig b/test/cases/noreturn_call_inline.zig similarity index 93% rename from test/standalone/simple/noreturn_call/inline.zig rename to test/cases/noreturn_call_inline.zig index 436d97896a774f5a84fa344822c9668026c4a432..966c8cad54d584cfd4ca818bc7a8e631022530fe 100644 --- a/test/standalone/simple/noreturn_call/inline.zig +++ b/test/cases/noreturn_call_inline.zig @@ -1,10 +1,15 @@ +const std = @import("std"); + pub fn main() void { _ = bar(); } + inline fn bar() u8 { noret(); } -const std = @import("std"); + inline fn noret() noreturn { std.process.exit(0); } + +// run diff --git a/test/standalone/simple/build.zig b/test/standalone/simple/build.zig index 730c3fc25c0259bc3f73a393add8e06871489f7b..43c0fae68ff2d8cdad96ce115c5ba1945b579d8d 100644 --- a/test/standalone/simple/build.zig +++ b/test/standalone/simple/build.zig @@ -105,9 +105,5 @@ const cases = [_]Case{ }, }, .{ .src_path = "guess_number/main.zig" }, - .{ .src_path = "main_return_error/error_u8.zig" }, - .{ .src_path = "main_return_error/error_u8_non_zero.zig" }, - .{ .src_path = "noreturn_call/inline.zig" }, - .{ .src_path = "noreturn_call/as_arg.zig" }, .{ .src_path = "std_enums_big_enums.zig" }, }; -- 2.54.0 From 1b2f003f06b5686326da6910def307170e2293e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 09:10:32 +0200 Subject: [PATCH 15/19] test: move issue_7030 from test-standalone simple cases to test-cases --- .../issue_7030.zig => cases/custom_logfn_freestanding.zig} | 4 ++++ test/standalone/simple/build.zig | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) rename test/{standalone/simple/issue_7030.zig => cases/custom_logfn_freestanding.zig} (86%) diff --git a/test/standalone/simple/issue_7030.zig b/test/cases/custom_logfn_freestanding.zig similarity index 86% rename from test/standalone/simple/issue_7030.zig rename to test/cases/custom_logfn_freestanding.zig index 021567751686c6db6ff1a2fbcbba50d074e99328..be33ce16f7abacaebd50fd3eb53694eaffbc2d54 100644 --- a/test/standalone/simple/issue_7030.zig +++ b/test/cases/custom_logfn_freestanding.zig @@ -19,3 +19,7 @@ pub fn log( pub fn main() anyerror!void { std.log.info("All your codebase are belong to us.", .{}); } + +// compile +// output_mode=Exe +// target=wasm32-freestanding diff --git a/test/standalone/simple/build.zig b/test/standalone/simple/build.zig index 43c0fae68ff2d8cdad96ce115c5ba1945b579d8d..d133d75dfc3c3a0b27b8791f9edacf9eacc8a46c 100644 --- a/test/standalone/simple/build.zig +++ b/test/standalone/simple/build.zig @@ -97,13 +97,6 @@ const cases = [_]Case{ .{ .src_path = "cat/main.zig", }, - .{ - .src_path = "issue_7030.zig", - .target = .{ - .cpu_arch = .wasm32, - .os_tag = .freestanding, - }, - }, .{ .src_path = "guess_number/main.zig" }, .{ .src_path = "std_enums_big_enums.zig" }, }; -- 2.54.0 From 40cde789f792769a1d938f6bc620b6a67c3b8099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 09:15:54 +0200 Subject: [PATCH 16/19] test-standalone: remove some dead #ifdefs in c_compiler --- test/standalone/c_compiler/test.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/standalone/c_compiler/test.cpp b/test/standalone/c_compiler/test.cpp index 1f3fe173d28a46a67e338ef7d57dd5466316d8fd..f3a12afe605f02cb5b4863513ccb0d3b9e19aa2d 100644 --- a/test/standalone/c_compiler/test.cpp +++ b/test/standalone/c_compiler/test.cpp @@ -1,9 +1,6 @@ #include #include - -#ifndef _LIBCPP_HAS_NO_THREADS #include -#endif thread_local unsigned int tls_counter = 1; @@ -59,14 +56,12 @@ int main (int argc, char *argv[]) if (!ok) abort(); -#ifndef _LIBCPP_HAS_NO_THREADS std::future fut = std::async(is_prime, 313); bool ret = fut.get(); assert(ret); -#endif -#if !defined(__wasm__) && !defined(__APPLE__) - // WASM and macOS are not passing this yet. +#if !defined(__APPLE__) + // macOS is not passing this yet. // TODO file an issue for this and link it here. try { throw 20; -- 2.54.0 From 03422925b127a8d369fc82ce333e2d77366c3849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 11:44:03 +0200 Subject: [PATCH 17/19] test-standalone: resurrect tsan test closes https://github.com/ziglang/zig/issues/25471 --- test/standalone/build.zig.zon | 7 ++-- test/standalone/tsan/build.zig | 65 ++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 9fd1de096b937d0b3cc0315228bc5fbfae8126c7..1b0f25bd998f37e2a7739154b650045cc1543c82 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -156,10 +156,9 @@ .run_cwd = .{ .path = "run_cwd", }, - // https://github.com/ziglang/zig/issues/25471 - // .tsan = .{ - // .path = "tsan", - // }, + .tsan = .{ + .path = "tsan", + }, .posix = .{ .path = "posix", }, diff --git a/test/standalone/tsan/build.zig b/test/standalone/tsan/build.zig index 3811ec0349d6aabc4dd32ca0eacb74fa4b9be6dc..486c773467f3aff0debdb9f101a446b06f9c66f1 100644 --- a/test/standalone/tsan/build.zig +++ b/test/standalone/tsan/build.zig @@ -1,34 +1,56 @@ const std = @import("std"); +const targets: []const std.Target.Query = &.{ + .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none }, + .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none }, + + .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabi64 }, + .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .muslabi64 }, + .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabi64 }, + .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .muslabi64 }, + .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .gnu }, + // .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .musl }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }, + .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, + + .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = .none }, + + // .{ .cpu_arch = .x86_64, .os_tag = .netbsd, .abi = .none }, + + // .{ .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu }, + // .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu }, +}; + pub fn build(b: *std.Build) !void { const test_step = b.step("test", "Test the program"); b.default_step = test_step; const is_macos = b.graph.host.result.os.tag == .macos; - for ([_]struct { std.Target.Os.Tag, []const std.Target.Cpu.Arch }{ - // .s390x and mips64(el) fail to build - .{ .linux, &.{ .aarch64, .aarch64_be, .loongarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } }, - .{ .macos, &.{ .aarch64, .x86_64 } }, + for (targets) |query| { + const target = b.resolveTargetQuery(query); - // powerpc64, powerpc64le, and riscv64 are not supported by TSan yet. - .{ .freebsd, &.{ .aarch64, .x86_64 } }, - - .{ .netbsd, &.{.x86_64} }, - - // TSan doesn't have full support for windows yet. - // .{ .windows, &.{ .aarch64, .x86_64 } }, - }) |entry| { - switch (entry[0]) { - // compiling tsan on macos requires system headers that aren't present during cross-compilation + switch (target.result.os.tag) { .macos => { + // compiling tsan on macos requires system headers that aren't present during cross-compilation if (!is_macos) continue; - const target = b.resolveTargetQuery(.{}); + const exe = b.addExecutable(.{ - .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(target.result.cpu.arch) }), + .name = b.fmt("tsan_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }), + .linkage = .dynamic, .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), - .target = target, + .target = b.graph.host, .optimize = .debug, .sanitize_thread = true, }), @@ -36,13 +58,10 @@ pub fn build(b: *std.Build) !void { const install_exe = b.addInstallArtifact(exe, .{}); test_step.dependOn(&install_exe.step); }, - else => for (entry[1]) |arch| { - const target = b.resolveTargetQuery(.{ - .os_tag = entry[0], - .cpu_arch = arch, - }); + else => { const exe = b.addExecutable(.{ - .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(arch) }), + .name = b.fmt("tsan_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }), + .linkage = .dynamic, .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), .target = target, -- 2.54.0 From 93316d6e613cbcf0b1f94da42bffdf9eac3223de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 09:57:20 +0200 Subject: [PATCH 18/19] std.zig.target: move isNative() here from test harness --- lib/std/zig/target.zig | 158 ++++++++++++++++++++++++++++++++++++++ test/src/Cases.zig | 2 +- test/src/ErrorTrace.zig | 2 +- test/src/StackTrace.zig | 2 +- test/tests.zig | 164 +--------------------------------------- 5 files changed, 165 insertions(+), 163 deletions(-) diff --git a/lib/std/zig/target.zig b/lib/std/zig/target.zig index 3f4f135470fa6a578e01e7f8a324083fb10e7423..7dc176756ec65c3ec9b4737c40c1a2c8314aed66 100644 --- a/lib/std/zig/target.zig +++ b/lib/std/zig/target.zig @@ -537,6 +537,164 @@ pub fn compilerRtFloatAbi(target: *const std.Target, bits: u16) std.Target.Abi.F return .hard; } +fn supportedCompatArch(host: *const std.Target, arch: std.Target.Cpu.Arch) bool { + // aarch64-freebsd and aarch64-linux can technically run 32-bit ARM binaries, but that depends + // on AArch32 support in the CPU. Since modern AArch64 CPUs have largely dropped this support, + // avoid reporting compatibility for 32-bit here since we'd just build a bunch of test binaries + // that never get run anyway. This added almost an hour's worth of useless work to aarch64-linux + // CI, for example. + // + // riscv64-linux and riscv64-netbsd similarly support 32-bit binaries. However, this requires a + // very recent kernel and for the kernel feature to be enabled. Additionally, contemporary + // RISC-V hardware is just too slow to justify building the 32-bit binaries. + return switch (host.os.tag) { + .illumos => switch (host.cpu.arch) { + .x86_64 => arch == .x86, + else => false, + }, + .linux => switch (host.cpu.arch) { + .mips64 => arch == .mips, + .mips64el => arch == .mipsel, + .powerpc64 => arch == .powerpc, + .sparc64 => arch == .sparc, + .x86_64 => arch == .x86, + else => false, + }, + .netbsd => switch (host.cpu.arch) { + .sparc64 => arch == .sparc, + .x86_64 => arch == .x86, + else => false, + }, + .windows => switch (host.cpu.arch) { + .x86_64 => arch == .x86, + else => false, + }, + else => false, + }; +} + +/// Intended for test code to determine whether it makes sense to run a test for a particular target +/// on the host. This is not an objective check; it is best-effort and also makes subjective +/// judgements for some targets. +pub fn isNative(query: *const std.Target.Query, target: *const std.Target, host: *const std.Target) bool { + if (query.isNative()) return true; + + if (target.cpu.arch != host.cpu.arch and !supportedCompatArch(host, target.cpu.arch)) + return false; + + if (target.os.tag != host.os.tag) + return false; + + // This check is really only necessary for the case where `host.cpu.arch.isAarch64()` and + // `target.cpu.arch.isArm()`. As they are wholly separate `std.Target` families with their own + // feature bits, the logic below would produce complete nonsense. + // + // This does mean that we aren't actually checking feature compatibility between these two + // families even though we should. That's not a problem currently, but in the future, we may + // need to add a special code path just for this specific case... + if (target.cpu.arch.family() != host.cpu.arch.family()) + return true; + + // Remove features that don't actually affect compatibility. + const irrelevant: std.Target.Cpu.Feature.Set = switch (host.cpu.arch) { + .x86_64 => std.Target.x86.featureSet(&.{ + .@"16bit_mode", + .@"32bit_mode", + .@"64bit", + .false_deps_bls, + .false_deps_compress, + .false_deps_expand, + .false_deps_getmant, + .false_deps_lzcnt, + .false_deps_mulc, + .false_deps_mullq, + .false_deps_perm, + .false_deps_popcnt, + .false_deps_range, + .false_deps_tzcnt, + .fast_11bytenop, + .fast_15bytenop, + .fast_7bytenop, + .fast_bextr, + .fast_dpwssd, + .fast_gather, + .fast_hops, + .fast_imm16, + .fast_lzcnt, + .fast_movbe, + .fast_scalar_fsqrt, + .fast_scalar_shift_masks, + .fast_shld_rotate, + .fast_variable_crosslane_shuffle, + .fast_variable_perlane_shuffle, + .fast_vector_fsqrt, + .fast_vector_shift_masks, + .faster_shift_than_shuffle, + .no_bypass_delay, + .no_bypass_delay_blend, + .no_bypass_delay_mov, + .no_bypass_delay_shuffle, + .prefer_128_bit, + .prefer_256_bit, + .prefer_legacy_setcc, + .prefer_mask_registers, + .prefer_movmsk_over_vtest, + .prefer_ndd_mem, + .prefer_no_gather, + .prefer_no_scatter, + .slow_3ops_lea, + .slow_incdec, + .slow_indirect_call, + .slow_lea, + .slow_pmaddwd, + .slow_pmulld, + .slow_pmullq, + .slow_shld, + .slow_two_mem_ops, + .slow_unaligned_mem_16, + .slow_unaligned_mem_32, + }), + .aarch64, .aarch64_be => std.Target.aarch64.featureSet(&.{ + .addr_lsl_slow_14, + .align_cmp_csel_pairs, + .alu_lsl_fast, + .avoid_ldapur, + .disable_fast_inc_vl, + .exynos_cheap_as_move, + .fast_ld1_single, + .fixed_load_latency_4, + .fuse_address, + .fuse_addsub_2reg_const1, + .fuse_adrp_add, + .fuse_aes, + .fuse_arith_logic, + .fuse_crypto_eor, + .fuse_csel, + .fuse_cset, + .fuse_fcsel, + .fuse_literals, + .has_limited_64bit_vector_mul_bandwidth, + .predictable_select_expensive, + .slow_misaligned_128store, + .slow_paired_128, + .slow_strqro_store, + .use_experimental_zeroing_pseudos, + .use_fixed_over_scalable_if_equal_cost, + .use_postra_scheduler, + .use_reciprocal_square_root, + .use_wzr_to_vec_move, + }), + else => .empty, + }; + var set = target.cpu.features; + set.removeFeatureSet(irrelevant); + + if (!host.cpu.features.isSuperSetOf(set)) + return false; + + return true; +} + const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; diff --git a/test/src/Cases.zig b/test/src/Cases.zig index b4fe4e65337b070c8ae99e867c418657b607b0d8..c6b3eb07d1ed6efdfd626952bac4ce484ca4efef 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -495,7 +495,7 @@ pub fn lowerToBuildSteps( if (case.case.? == .Error and options.skip_compile_errors) continue; - if (options.skip_non_native and !@import("../tests.zig").isNative(&case.target, &b.graph.host.result)) + if (options.skip_non_native and !std.zig.target.isNative(&case.target.query, &case.target.result, &b.graph.host.result)) continue; if (options.skip_spirv and case.target.query.cpu_arch != null and case.target.query.cpu_arch.?.isSpirV()) continue; diff --git a/test/src/ErrorTrace.zig b/test/src/ErrorTrace.zig index 57b26d492fe9a59fa741cd219cc9d27ec9d93ead..8a09ccee4088fa98658c24a6a2382d4e3f7593a4 100644 --- a/test/src/ErrorTrace.zig +++ b/test/src/ErrorTrace.zig @@ -385,7 +385,7 @@ pub fn addCases(self: *ErrorTrace) void { if (!self.options.test_extra_targets and params.extra_target) continue; - if (self.options.skip_non_native and !tests.isNative(&resolved_target, &b.graph.host.result)) continue; + if (self.options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue; if (self.options.skip_freebsd and target.os.tag == .freebsd) continue; if (self.options.skip_netbsd and target.os.tag == .netbsd) continue; diff --git a/test/src/StackTrace.zig b/test/src/StackTrace.zig index 156ac8984eaaca578e3752533d8f775029e030c2..c0ebbd71f86f08401b612f99513d06796b44bfd8 100644 --- a/test/src/StackTrace.zig +++ b/test/src/StackTrace.zig @@ -995,7 +995,7 @@ pub fn addCases(self: *StackTrace) void { if (!self.options.test_extra_targets and params.extra_target) continue; - if (self.options.skip_non_native and !tests.isNative(&resolved_target, &b.graph.host.result)) continue; + if (self.options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue; if (self.options.skip_freebsd and target.os.tag == .freebsd) continue; if (self.options.skip_netbsd and target.os.tag == .netbsd) continue; diff --git a/test/tests.zig b/test/tests.zig index c3c501c99d71403862b8f3bcbea7be5367184ae7..46fa29e9312190350e72deed1848fa27336a9a94 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2323,162 +2323,6 @@ pub const debugger_matrix: []const RunnerTarget = &.{ }, }; -fn supportedCompatArch(host: *const std.Target, arch: std.Target.Cpu.Arch) bool { - // aarch64-freebsd and aarch64-linux can technically run 32-bit ARM binaries, but that depends - // on AArch32 support in the CPU. Since modern AArch64 CPUs have largely dropped this support, - // avoid reporting compatibility for 32-bit here since we'd just build a bunch of test binaries - // that never get run anyway. This added almost an hour's worth of useless work to aarch64-linux - // CI, for example. - // - // riscv64-linux and riscv64-netbsd similarly support 32-bit binaries. However, this requires a - // very recent kernel and for the kernel feature to be enabled. Additionally, contemporary - // RISC-V hardware is just too slow to justify building the 32-bit binaries. - return switch (host.os.tag) { - .illumos => switch (host.cpu.arch) { - .x86_64 => arch == .x86, - else => false, - }, - .linux => switch (host.cpu.arch) { - .mips64 => arch == .mips, - .mips64el => arch == .mipsel, - .powerpc64 => arch == .powerpc, - .sparc64 => arch == .sparc, - .x86_64 => arch == .x86, - else => false, - }, - .netbsd => switch (host.cpu.arch) { - .sparc64 => arch == .sparc, - .x86_64 => arch == .x86, - else => false, - }, - .windows => switch (host.cpu.arch) { - .x86_64 => arch == .x86, - else => false, - }, - else => false, - }; -} - -pub fn isNative(actual_target: *const std.Build.ResolvedTarget, host: *const std.Target) bool { - if (actual_target.query.isNative()) return true; - const actual = &actual_target.result; - - if (actual.cpu.arch != host.cpu.arch and !supportedCompatArch(host, actual.cpu.arch)) - return false; - - if (actual.os.tag != host.os.tag) - return false; - - // This check is really only necessary for the case where `host.cpu.arch.isAarch64()` and - // `actual.cpu.arch.isArm()`. As they are wholly separate `std.Target` families with their own - // feature bits, the logic below would produce complete nonsense. - // - // This does mean that we aren't actually checking feature compatibility between these two - // families even though we should. That's not a problem currently, but in the future, we may - // need to add a special code path just for this specific case... - if (actual.cpu.arch.family() != host.cpu.arch.family()) - return true; - - // Remove features that don't actually affect compatibility. - const irrelevant: std.Target.Cpu.Feature.Set = switch (host.cpu.arch) { - .x86_64 => std.Target.x86.featureSet(&.{ - .@"16bit_mode", - .@"32bit_mode", - .@"64bit", - .false_deps_bls, - .false_deps_compress, - .false_deps_expand, - .false_deps_getmant, - .false_deps_lzcnt, - .false_deps_mulc, - .false_deps_mullq, - .false_deps_perm, - .false_deps_popcnt, - .false_deps_range, - .false_deps_tzcnt, - .fast_11bytenop, - .fast_15bytenop, - .fast_7bytenop, - .fast_bextr, - .fast_dpwssd, - .fast_gather, - .fast_hops, - .fast_imm16, - .fast_lzcnt, - .fast_movbe, - .fast_scalar_fsqrt, - .fast_scalar_shift_masks, - .fast_shld_rotate, - .fast_variable_crosslane_shuffle, - .fast_variable_perlane_shuffle, - .fast_vector_fsqrt, - .fast_vector_shift_masks, - .faster_shift_than_shuffle, - .no_bypass_delay, - .no_bypass_delay_blend, - .no_bypass_delay_mov, - .no_bypass_delay_shuffle, - .prefer_128_bit, - .prefer_256_bit, - .prefer_legacy_setcc, - .prefer_mask_registers, - .prefer_movmsk_over_vtest, - .prefer_ndd_mem, - .prefer_no_gather, - .prefer_no_scatter, - .slow_3ops_lea, - .slow_incdec, - .slow_indirect_call, - .slow_lea, - .slow_pmaddwd, - .slow_pmulld, - .slow_pmullq, - .slow_shld, - .slow_two_mem_ops, - .slow_unaligned_mem_16, - .slow_unaligned_mem_32, - }), - .aarch64, .aarch64_be => std.Target.aarch64.featureSet(&.{ - .addr_lsl_slow_14, - .align_cmp_csel_pairs, - .alu_lsl_fast, - .avoid_ldapur, - .disable_fast_inc_vl, - .exynos_cheap_as_move, - .fast_ld1_single, - .fixed_load_latency_4, - .fuse_address, - .fuse_addsub_2reg_const1, - .fuse_adrp_add, - .fuse_aes, - .fuse_arith_logic, - .fuse_crypto_eor, - .fuse_csel, - .fuse_cset, - .fuse_fcsel, - .fuse_literals, - .has_limited_64bit_vector_mul_bandwidth, - .predictable_select_expensive, - .slow_misaligned_128store, - .slow_paired_128, - .slow_strqro_store, - .use_experimental_zeroing_pseudos, - .use_fixed_over_scalable_if_equal_cost, - .use_postra_scheduler, - .use_reciprocal_square_root, - .use_wzr_to_vec_move, - }), - else => .empty, - }; - var set = actual.cpu.features; - set.removeFeatureSet(irrelevant); - - if (!host.cpu.features.isSuperSetOf(set)) - return false; - - return true; -} - pub fn addStackTraceTests(b: *std.Build, options: StackTracesContext.Options) *Step { const step = b.step("test-stack-traces", "Run the stack trace tests"); @@ -2830,7 +2674,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { if (!options.test_extra_targets and test_target.extra_target) continue; - if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) + if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue; const target = &resolved_target.result; @@ -3156,7 +3000,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); const target = &resolved_target.result; - if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) + if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue; if (options.test_target_filters.len > 0) { @@ -3249,7 +3093,7 @@ pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step { for (link_targets) |link_target| { const resolved_target = b.resolveTargetQuery(link_target.target); - if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) + if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue; const target = &resolved_target.result; @@ -3399,7 +3243,7 @@ pub fn addRunnerTests( for (matrix) |test_target| { const resolved_target = b.resolveTargetQuery(test_target.target); - if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) + if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue; const target = &resolved_target.result; -- 2.54.0 From 38c1536b96888b17626b35acf911cef56668b54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 9 Oct 2026 12:50:27 +0200 Subject: [PATCH 19/19] test-standalone: respect -Dskip-non-native in cross-compiling tests closes https://github.com/ziglang/zig/issues/25471 --- build.zig | 1 + test/standalone/build.zig | 11 ++++++++--- test/standalone/coff_dwarf/build.zig | 17 ++++++----------- test/standalone/compile_asm/build.zig | 6 ++++++ test/standalone/elf2/build.zig | 7 +++++++ test/standalone/embed_generated_file/build.zig | 16 ++++++++++++---- test/standalone/entry_point/build.zig | 14 +++++++++++--- test/standalone/glibc_compat/build.zig | 18 +++++++++++++++--- test/standalone/install_raw_hex/build.zig | 6 ++++++ test/standalone/tsan/build.zig | 6 ++++++ test/standalone/windows_entry_points/build.zig | 6 ++++++ test/standalone/windows_resources/build.zig | 6 ++++++ test/tests.zig | 2 ++ 13 files changed, 92 insertions(+), 24 deletions(-) diff --git a/build.zig b/build.zig index cecba0923eb6c8fd63b0093264a2aa2482b672b4..421b28adef3a31fe766d56baf74e200f9aa5b05b 100644 --- a/build.zig +++ b/build.zig @@ -636,6 +636,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addStandaloneTests( b, optimize_modes, + skip_non_native, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows, diff --git a/test/standalone/build.zig b/test/standalone/build.zig index ab4262c8b90686517cf32f90b7b99263c72d3969..c9648fd90e6e1c33dfd5179806cd2c65da62c089 100644 --- a/test/standalone/build.zig +++ b/test/standalone/build.zig @@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void { const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false; const simple_skip_release_fast = b.option(bool, "simple_skip_release_fast", "Simple tests skip release-fast builds") orelse false; const simple_skip_release_small = b.option(bool, "simple_skip_release_small", "Simple tests skip release-small builds") orelse false; + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; const simple_dep = b.dependency("simple", .{ .skip_debug = simple_skip_debug, @@ -103,7 +104,7 @@ pub fn build(b: *std.Build) void { if (std.mem.eql(u8, dep_name, "simple")) continue; const all_pkgs = @import("root").dependencies.packages; - inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| { + const forward_skip_non_native = inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| { if (std.mem.eql(u8, dep_hash, pkg_hash)) { const pkg = @field(all_pkgs, pkg_hash); if (!@hasDecl(pkg, "build_zig")) { @@ -121,11 +122,15 @@ pub fn build(b: *std.Build) void { { continue :add_dep_steps; } - break; + break @hasDecl(pkg.build_zig, "supports_skip_non_native") and + pkg.build_zig.supports_skip_non_native; } } else unreachable; - const dep = b.dependency(dep_name, .{}); + const dep = if (forward_skip_non_native) + b.dependency(dep_name, .{ .skip_non_native = skip_non_native }) + else + b.dependency(dep_name, .{}); const dep_step = dep.builder.default_step; dep_step.name = b.fmt("standalone_test_cases.{s}", .{dep_name}); step.dependOn(dep_step); diff --git a/test/standalone/coff_dwarf/build.zig b/test/standalone/coff_dwarf/build.zig index 6ff69e948964dac924043d3635a50df44757a279..03ee6723356318683da675b1fdd5c257285f3cd1 100644 --- a/test/standalone/coff_dwarf/build.zig +++ b/test/standalone/coff_dwarf/build.zig @@ -1,20 +1,13 @@ const std = @import("std"); +pub const supports_skip_non_native = true; + /// This tests the path where DWARF information is embedded in a COFF binary pub fn build(b: *std.Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const host = b.graph.host; - // https://github.com/ziglang/zig/issues/25471 - if (host.result.os.tag == .freebsd) return; - - switch (host.result.cpu.arch) { - .aarch64, - .x86, - .x86_64, - => {}, - else => return, - } - const test_step = b.step("test", "Test it"); b.default_step = test_step; @@ -24,6 +17,8 @@ pub fn build(b: *std.Build) void { else => b.resolveTargetQuery(.{ .os_tag = .windows }), }; + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &host.result)) return; + const exe = b.addExecutable(.{ .name = "main", .root_module = b.createModule(.{ diff --git a/test/standalone/compile_asm/build.zig b/test/standalone/compile_asm/build.zig index 1cd675bc9b6a14a7a31f7299255f8c85cf27a0cc..88956cd07b0192ad0e23c5a770cdb56706031766 100644 --- a/test/standalone/compile_asm/build.zig +++ b/test/standalone/compile_asm/build.zig @@ -1,6 +1,10 @@ const std = @import("std"); +pub const supports_skip_non_native = true; + pub fn build(b: *std.Build) !void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test it"); b.default_step = test_step; @@ -13,6 +17,8 @@ pub fn build(b: *std.Build) !void { }, }); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return; + const kernel = b.addExecutable(.{ .name = "kernel", .root_module = b.createModule(.{ diff --git a/test/standalone/elf2/build.zig b/test/standalone/elf2/build.zig index 6bc29c26e382fb8e52b66fb04969b280fb670e0b..1787a15362fe9522b292e4c6fa1366ceee8d8bd7 100644 --- a/test/standalone/elf2/build.zig +++ b/test/standalone/elf2/build.zig @@ -1,4 +1,8 @@ +pub const supports_skip_non_native = true; + pub fn build(b: *Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test the new ELF linker"); b.default_step = test_step; @@ -15,6 +19,9 @@ pub fn build(b: *Build) void { .cpu_arch = .x86_64, .os_tag = .linux, }); + + if (skip_non_native and !std.zig.target.isNative(&x86_64_linux_target.query, &x86_64_linux_target.result, &b.graph.host.result)) return; + addOne(b, test_step, x86_64_linux_target, false, .static, false, false, "elf2-hello-selfhosted-static"); addOne(b, test_step, x86_64_linux_target, false, .static, true, false, "elf2-hello-selfhosted-static-pie"); addOne(b, test_step, x86_64_linux_target, true, .static, false, false, "elf2-hello-llvm-static"); diff --git a/test/standalone/embed_generated_file/build.zig b/test/standalone/embed_generated_file/build.zig index 4669e8e440517ecd3af2243b02cba143f83cbae1..02dd8c4efc4774adff72477d6e43712182e59223 100644 --- a/test/standalone/embed_generated_file/build.zig +++ b/test/standalone/embed_generated_file/build.zig @@ -1,6 +1,17 @@ const std = @import("std"); +pub const supports_skip_non_native = true; + pub fn build(b: *std.Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + + const target = b.resolveTargetQuery(.{ + .cpu_arch = .x86, + .os_tag = .freestanding, + }); + + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return; + const test_step = b.step("test", "Test it"); b.default_step = test_step; @@ -8,10 +19,7 @@ pub fn build(b: *std.Build) void { .name = "bootloader", .root_module = b.createModule(.{ .root_source_file = b.path("bootloader.zig"), - .target = b.resolveTargetQuery(.{ - .cpu_arch = .x86, - .os_tag = .freestanding, - }), + .target = target, .optimize = .small, }), }); diff --git a/test/standalone/entry_point/build.zig b/test/standalone/entry_point/build.zig index 376b599d289165054717fef0e457ce9aa040e2e3..6dc1e9ab6c341f73dc042e98b71c7657c99e7d2b 100644 --- a/test/standalone/entry_point/build.zig +++ b/test/standalone/entry_point/build.zig @@ -1,11 +1,19 @@ +pub const supports_skip_non_native = true; + pub fn build(b: *std.Build) !void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + + const target = b.resolveTargetQuery(try .parse(.{ + .arch_os_abi = "x86_64-linux", + })); + + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return; + const mod = b.createModule(.{ // Setting the entry point doesn't work properly on all targets right now. Since we're // really just trying to make sure that the compiler *frontend* respects `-fentry` and // includes it in the cache manifest, just test for a target where it works. - .target = b.resolveTargetQuery(try .parse(.{ - .arch_os_abi = "x86_64-linux", - })), + .target = target, .optimize = .fast, // non-Debug build for reproducible output .root_source_file = b.path("main.zig"), }); diff --git a/test/standalone/glibc_compat/build.zig b/test/standalone/glibc_compat/build.zig index 202449a1e233b1940c632db8d87db3ec8645e984..7769deab301a387a3d035a6a0062ab4a9a971a9e 100644 --- a/test/standalone/glibc_compat/build.zig +++ b/test/standalone/glibc_compat/build.zig @@ -1,6 +1,8 @@ const std = @import("std"); const builtin = @import("builtin"); +pub const supports_skip_non_native = true; + // To run executables linked against a specific glibc version, the // run-time glibc version needs to be new enough. Check the host's glibc // version. Note that this does not allow for translation/vm/emulation @@ -8,17 +10,23 @@ const builtin = @import("builtin"); const running_glibc_ver = builtin.os.versionRange().gnuLibCVersion(); pub fn build(b: *std.Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test"); b.default_step = test_step; for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { + const target = b.resolveTargetQuery(std.Target.Query.parse( + .{ .arch_os_abi = t }, + ) catch unreachable); + + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue; + const exe = b.addExecutable(.{ .name = t, .root_module = b.createModule(.{ .root_source_file = null, - .target = b.resolveTargetQuery(std.Target.Query.parse( - .{ .arch_os_abi = t }, - ) catch unreachable), + .target = target, .link_libc = true, }), }); @@ -49,6 +57,8 @@ pub fn build(b: *std.Build) void { .{ .arch_os_abi = t }, ) catch unreachable); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue; + const glibc_ver = target.result.os.version_range.linux.glibc; // only build test if glibc version supports the architecture @@ -103,6 +113,8 @@ pub fn build(b: *std.Build) void { .{ .arch_os_abi = t }, ) catch unreachable); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue; + if (target.result.cpu.arch.isLoongArch()) continue; // https://github.com/Vexu/arocc/issues/1096 const glibc_ver = target.result.os.version_range.linux.glibc; diff --git a/test/standalone/install_raw_hex/build.zig b/test/standalone/install_raw_hex/build.zig index 3fd9e91a9a1184ca2de89beec01ae7dc7bf2c714..bc6a27ebd905cb2e3bdf6547caddd1f3bdb7b49e 100644 --- a/test/standalone/install_raw_hex/build.zig +++ b/test/standalone/install_raw_hex/build.zig @@ -1,7 +1,11 @@ const builtin = @import("builtin"); const std = @import("std"); +pub const supports_skip_non_native = true; + pub fn build(b: *std.Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test it"); b.default_step = test_step; @@ -12,6 +16,8 @@ pub fn build(b: *std.Build) void { .abi = .gnueabihf, }); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return; + const optimize: std.builtin.Optimize = .debug; const elf = b.addExecutable(.{ diff --git a/test/standalone/tsan/build.zig b/test/standalone/tsan/build.zig index 486c773467f3aff0debdb9f101a446b06f9c66f1..50101d38a53ce6e930ddbc2c3f6b6a7ebe5ee53d 100644 --- a/test/standalone/tsan/build.zig +++ b/test/standalone/tsan/build.zig @@ -1,5 +1,7 @@ const std = @import("std"); +pub const supports_skip_non_native = true; + const targets: []const std.Target.Query = &.{ .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none }, .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none }, @@ -32,6 +34,8 @@ const targets: []const std.Target.Query = &.{ }; pub fn build(b: *std.Build) !void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test the program"); b.default_step = test_step; @@ -40,6 +44,8 @@ pub fn build(b: *std.Build) !void { for (targets) |query| { const target = b.resolveTargetQuery(query); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue; + switch (target.result.os.tag) { .macos => { // compiling tsan on macos requires system headers that aren't present during cross-compilation diff --git a/test/standalone/windows_entry_points/build.zig b/test/standalone/windows_entry_points/build.zig index 2c75c3e6ba8cda977eb9fb0f1f73f5af3872e5b1..f1dcec2b3f7e0f0f5b37fd01e446464e7a3fc67d 100644 --- a/test/standalone/windows_entry_points/build.zig +++ b/test/standalone/windows_entry_points/build.zig @@ -1,6 +1,10 @@ const std = @import("std"); +pub const supports_skip_non_native = true; + pub fn build(b: *std.Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test it"); b.default_step = test_step; @@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void { .abi = .gnu, }); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return; + { const exe = b.addExecutable(.{ .name = "main", diff --git a/test/standalone/windows_resources/build.zig b/test/standalone/windows_resources/build.zig index 09d91a29ed986247cf47cded3b70b3e2952cb0fd..782b502f0a7cb6f5f0cc20599fa391ef2c29e801 100644 --- a/test/standalone/windows_resources/build.zig +++ b/test/standalone/windows_resources/build.zig @@ -1,6 +1,10 @@ const std = @import("std"); +pub const supports_skip_non_native = true; + pub fn build(b: *std.Build) void { + const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false; + const test_step = b.step("test", "Test it"); b.default_step = test_step; @@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void { .abi = .gnu, }); + if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return; + const generated_h_step = b.addWriteFile("generated.h", "#define GENERATED_DEFINE \"foo\""); add(b, b.graph.host, .any, test_step, generated_h_step); diff --git a/test/tests.zig b/test/tests.zig index 46fa29e9312190350e72deed1848fa27336a9a94..989d4482571365a13c165422f94f84ccb6b4c13c 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2374,6 +2374,7 @@ pub fn addErrorTraceTests(b: *std.Build, options: ErrorTracesContext.Options) *S pub fn addStandaloneTests( b: *std.Build, optimize_modes: []const OptimizeMode, + skip_non_native: bool, enable_macos_sdk: bool, enable_ios_sdk: bool, enable_symlinks_windows: bool, @@ -2388,6 +2389,7 @@ pub fn addStandaloneTests( .simple_skip_release_safe = mem.findScalar(OptimizeMode, optimize_modes, .safe) == null, .simple_skip_release_fast = mem.findScalar(OptimizeMode, optimize_modes, .fast) == null, .simple_skip_release_small = mem.findScalar(OptimizeMode, optimize_modes, .small) == null, + .skip_non_native = skip_non_native, }); const test_cases_dep_step = test_cases_dep.builder.default_step; test_cases_dep_step.name = test_cases_dep_name; -- 2.54.0