authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-10 08:36:26+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-10 08:36:26+02:00
log79d9121670ebb73937ef0bed6d6b8044fada8715
tree0e687f443c234bd13807a4ccb6e01cf173094f28
parent0fd39f9e92a25f61562b0a067a9d7b2fdbed9f8c
parent38c1536b96888b17626b35acf911cef56668b54f
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Merge branch 'test-housekeeping'


55 files changed, 413 insertions(+), 854 deletions(-)

build.zig+1
......@@ -636,6 +636,7 @@ pub fn build(b: *std.Build) !void {
636636 test_step.dependOn(tests.addStandaloneTests(
637637 b,
638638 optimize_modes,
639 skip_non_native,
639640 enable_macos_sdk,
640641 enable_ios_sdk,
641642 enable_symlinks_windows,
lib/std/zig/target.zig+158
......@@ -537,6 +537,164 @@ pub fn compilerRtFloatAbi(target: *const std.Target, bits: u16) std.Target.Abi.F
537537 return .hard;
538538}
539539
540fn supportedCompatArch(host: *const std.Target, arch: std.Target.Cpu.Arch) bool {
541 // aarch64-freebsd and aarch64-linux can technically run 32-bit ARM binaries, but that depends
542 // on AArch32 support in the CPU. Since modern AArch64 CPUs have largely dropped this support,
543 // avoid reporting compatibility for 32-bit here since we'd just build a bunch of test binaries
544 // that never get run anyway. This added almost an hour's worth of useless work to aarch64-linux
545 // CI, for example.
546 //
547 // riscv64-linux and riscv64-netbsd similarly support 32-bit binaries. However, this requires a
548 // very recent kernel and for the kernel feature to be enabled. Additionally, contemporary
549 // RISC-V hardware is just too slow to justify building the 32-bit binaries.
550 return switch (host.os.tag) {
551 .illumos => switch (host.cpu.arch) {
552 .x86_64 => arch == .x86,
553 else => false,
554 },
555 .linux => switch (host.cpu.arch) {
556 .mips64 => arch == .mips,
557 .mips64el => arch == .mipsel,
558 .powerpc64 => arch == .powerpc,
559 .sparc64 => arch == .sparc,
560 .x86_64 => arch == .x86,
561 else => false,
562 },
563 .netbsd => switch (host.cpu.arch) {
564 .sparc64 => arch == .sparc,
565 .x86_64 => arch == .x86,
566 else => false,
567 },
568 .windows => switch (host.cpu.arch) {
569 .x86_64 => arch == .x86,
570 else => false,
571 },
572 else => false,
573 };
574}
575
576/// Intended for test code to determine whether it makes sense to run a test for a particular target
577/// on the host. This is not an objective check; it is best-effort and also makes subjective
578/// judgements for some targets.
579pub fn isNative(query: *const std.Target.Query, target: *const std.Target, host: *const std.Target) bool {
580 if (query.isNative()) return true;
581
582 if (target.cpu.arch != host.cpu.arch and !supportedCompatArch(host, target.cpu.arch))
583 return false;
584
585 if (target.os.tag != host.os.tag)
586 return false;
587
588 // This check is really only necessary for the case where `host.cpu.arch.isAarch64()` and
589 // `target.cpu.arch.isArm()`. As they are wholly separate `std.Target` families with their own
590 // feature bits, the logic below would produce complete nonsense.
591 //
592 // This does mean that we aren't actually checking feature compatibility between these two
593 // families even though we should. That's not a problem currently, but in the future, we may
594 // need to add a special code path just for this specific case...
595 if (target.cpu.arch.family() != host.cpu.arch.family())
596 return true;
597
598 // Remove features that don't actually affect compatibility.
599 const irrelevant: std.Target.Cpu.Feature.Set = switch (host.cpu.arch) {
600 .x86_64 => std.Target.x86.featureSet(&.{
601 .@"16bit_mode",
602 .@"32bit_mode",
603 .@"64bit",
604 .false_deps_bls,
605 .false_deps_compress,
606 .false_deps_expand,
607 .false_deps_getmant,
608 .false_deps_lzcnt,
609 .false_deps_mulc,
610 .false_deps_mullq,
611 .false_deps_perm,
612 .false_deps_popcnt,
613 .false_deps_range,
614 .false_deps_tzcnt,
615 .fast_11bytenop,
616 .fast_15bytenop,
617 .fast_7bytenop,
618 .fast_bextr,
619 .fast_dpwssd,
620 .fast_gather,
621 .fast_hops,
622 .fast_imm16,
623 .fast_lzcnt,
624 .fast_movbe,
625 .fast_scalar_fsqrt,
626 .fast_scalar_shift_masks,
627 .fast_shld_rotate,
628 .fast_variable_crosslane_shuffle,
629 .fast_variable_perlane_shuffle,
630 .fast_vector_fsqrt,
631 .fast_vector_shift_masks,
632 .faster_shift_than_shuffle,
633 .no_bypass_delay,
634 .no_bypass_delay_blend,
635 .no_bypass_delay_mov,
636 .no_bypass_delay_shuffle,
637 .prefer_128_bit,
638 .prefer_256_bit,
639 .prefer_legacy_setcc,
640 .prefer_mask_registers,
641 .prefer_movmsk_over_vtest,
642 .prefer_ndd_mem,
643 .prefer_no_gather,
644 .prefer_no_scatter,
645 .slow_3ops_lea,
646 .slow_incdec,
647 .slow_indirect_call,
648 .slow_lea,
649 .slow_pmaddwd,
650 .slow_pmulld,
651 .slow_pmullq,
652 .slow_shld,
653 .slow_two_mem_ops,
654 .slow_unaligned_mem_16,
655 .slow_unaligned_mem_32,
656 }),
657 .aarch64, .aarch64_be => std.Target.aarch64.featureSet(&.{
658 .addr_lsl_slow_14,
659 .align_cmp_csel_pairs,
660 .alu_lsl_fast,
661 .avoid_ldapur,
662 .disable_fast_inc_vl,
663 .exynos_cheap_as_move,
664 .fast_ld1_single,
665 .fixed_load_latency_4,
666 .fuse_address,
667 .fuse_addsub_2reg_const1,
668 .fuse_adrp_add,
669 .fuse_aes,
670 .fuse_arith_logic,
671 .fuse_crypto_eor,
672 .fuse_csel,
673 .fuse_cset,
674 .fuse_fcsel,
675 .fuse_literals,
676 .has_limited_64bit_vector_mul_bandwidth,
677 .predictable_select_expensive,
678 .slow_misaligned_128store,
679 .slow_paired_128,
680 .slow_strqro_store,
681 .use_experimental_zeroing_pseudos,
682 .use_fixed_over_scalable_if_equal_cost,
683 .use_postra_scheduler,
684 .use_reciprocal_square_root,
685 .use_wzr_to_vec_move,
686 }),
687 else => .empty,
688 };
689 var set = target.cpu.features;
690 set.removeFeatureSet(irrelevant);
691
692 if (!host.cpu.features.isSuperSetOf(set))
693 return false;
694
695 return true;
696}
697
540698const std = @import("std");
541699const assert = std.debug.assert;
542700const Allocator = std.mem.Allocator;
test/behavior/while.zig+8
......@@ -419,3 +419,11 @@ test "labeled break from else" {
419419 try S.doTheTest(5);
420420 try comptime S.doTheTest(5);
421421}
422
423fn infiniteLoop() noreturn {
424 while (true) {}
425}
426
427test "infinite while true" {
428 _ = &infiniteLoop;
429}
test/c_abi/cfuncs.c+11
......@@ -1,6 +1,7 @@
11#include <complex.h>
22#include <inttypes.h>
33#include <stdalign.h>
4#include <stdarg.h>
45#include <stdbool.h>
56#include <stdlib.h>
67#include <string.h>
......@@ -16775,6 +16776,16 @@ void c_x86_64_sysv_uint_int_uint_int(unsigned a, int b, unsigned c, int d) {
1677516776 assert_or_panic(d == -4);
1677616777}
1677716778
16779void c_varargs_fn_ptr(int n, ...) {
16780 assert_or_panic(n == 2);
16781 va_list ap;
16782 va_start(ap, n);
16783 void (*fn_ptr)(int) = va_arg(ap, void (*)(int));
16784 int arg = va_arg(ap, int);
16785 va_end(ap);
16786 fn_ptr(arg);
16787}
16788
1677816789void c_win64_varargs_u64_f64_u64_f64(uint64_t a, double b, uint64_t c, double d) {
1677916790 assert_or_panic(a == UINT64_C(0x3ff0000000000000));
1678016791 assert_or_panic(b == 2.0);
test/c_abi/main.zig+11
......@@ -18009,6 +18009,17 @@ test "x86_64 sysv args" {
1800918009 c_x86_64_sysv_uint_int_uint_int(1, -2, 3, -4);
1801018010}
1801118011
18012extern fn c_varargs_fn_ptr(n: c_int, ...) void;
18013
18014fn zigVaCb(x: c_int) callconv(.c) void {
18015 expect(x == 123) catch @panic("test failure: zigVaCb");
18016}
18017
18018test "function pointer through varargs" {
18019 // Bare function (not `&`), as in the original #12706 repro.
18020 c_varargs_fn_ptr(2, zigVaCb, @as(c_int, 123));
18021}
18022
1801218023extern fn c_win64_varargs_u64_f64_u64_f64(...) void;
1801318024extern fn c_win64_varargs_f64_u64_f64_u64(...) void;
1801418025
test/cases/custom_logfn_freestanding.zig created+25
......@@ -0,0 +1,25 @@
1const std = @import("std");
2
3pub const std_options: std.Options = .{
4 .logFn = log,
5};
6
7pub fn log(
8 comptime message_level: std.log.Level,
9 comptime scope: @EnumLiteral(),
10 comptime format: []const u8,
11 args: anytype,
12) void {
13 _ = message_level;
14 _ = scope;
15 _ = format;
16 _ = args;
17}
18
19pub fn main() anyerror!void {
20 std.log.info("All your codebase are belong to us.", .{});
21}
22
23// compile
24// output_mode=Exe
25// target=wasm32-freestanding
test/cases/empty_global_error_set.zig created+6
......@@ -0,0 +1,6 @@
1fn errorName(err: anyerror) [:0]const u8 {
2 return @errorName(err);
3}
4export const error_name: *const anyopaque = &errorName;
5
6// compile
test/cases/hello_world.zig deleted-13
......@@ -1,13 +0,0 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=selfhosted,llvm
9// target=x86_64-linux,x86_64-macos
10// link_libc=true
11//
12// hello world!
13//
test/cases/main_return_error_u8.zig created+8
......@@ -0,0 +1,8 @@
1const Err = error{Foo};
2
3pub fn main() !u8 {
4 return Err.Foo;
5}
6
7// compile
8// output_mode=Exe
test/cases/main_return_error_u8_non_zero.zig created+13
......@@ -0,0 +1,13 @@
1const Err = error{Foo};
2
3fn foo() u8 {
4 return @intCast(9);
5}
6
7pub fn main() !u8 {
8 if (foo() == 7) return Err.Foo;
9 return 123;
10}
11
12// compile
13// output_mode=Exe
test/cases/noreturn_call_as_arg.zig created+13
......@@ -0,0 +1,13 @@
1const std = @import("std");
2
3fn foo() noreturn {
4 std.process.exit(0);
5}
6
7fn bar(_: u8, _: u8) void {}
8
9pub fn main() void {
10 bar(foo(), @compileError("bad"));
11}
12
13// run
test/cases/noreturn_call_inline.zig created+15
......@@ -0,0 +1,15 @@
1const std = @import("std");
2
3pub fn main() void {
4 _ = bar();
5}
6
7inline fn bar() u8 {
8 noret();
9}
10
11inline fn noret() noreturn {
12 std.process.exit(0);
13}
14
15// run
test/gen_h.zig deleted-148
......@@ -1,148 +0,0 @@
1const tests = @import("tests.zig");
2
3pub fn addCases(cases: *tests.GenHContext) void {
4 cases.add("declare enum",
5 \\const Foo = extern enum { A, B, C };
6 \\export fn entry(foo: Foo) void { }
7 , &[_][]const u8{
8 \\enum Foo {
9 \\ A = 0,
10 \\ B = 1,
11 \\ C = 2
12 \\};
13 ,
14 \\void entry(enum Foo foo);
15 });
16
17 cases.add("declare struct",
18 \\const Foo = extern struct {
19 \\ A: i32,
20 \\ B: f32,
21 \\ C: bool,
22 \\ D: u64,
23 \\ E: u64,
24 \\ F: u64,
25 \\};
26 \\export fn entry(foo: Foo) void { }
27 , &[_][]const u8{
28 \\struct Foo {
29 \\ int32_t A;
30 \\ float B;
31 \\ bool C;
32 \\ uint64_t D;
33 \\ uint64_t E;
34 \\ uint64_t F;
35 \\};
36 ,
37 \\void entry(struct Foo foo);
38 \\
39 });
40
41 cases.add("declare union",
42 \\const Big = extern struct {
43 \\ A: u64,
44 \\ B: u64,
45 \\ C: u64,
46 \\ D: u64,
47 \\ E: u64,
48 \\};
49 \\const Foo = extern union {
50 \\ A: i32,
51 \\ B: f32,
52 \\ C: bool,
53 \\ D: Big,
54 \\};
55 \\export fn entry(foo: Foo) void {}
56 , &[_][]const u8{
57 \\struct Big {
58 \\ uint64_t A;
59 \\ uint64_t B;
60 \\ uint64_t C;
61 \\ uint64_t D;
62 \\ uint64_t E;
63 \\};
64 \\
65 \\union Foo {
66 \\ int32_t A;
67 \\ float B;
68 \\ bool C;
69 \\ struct Big D;
70 \\};
71 ,
72 \\void entry(union Foo foo);
73 \\
74 });
75
76 cases.add("declare opaque type",
77 \\const Foo = opaque {};
78 \\
79 \\export fn entry(foo: ?*Foo) void { }
80 , &[_][]const u8{
81 \\struct Foo;
82 ,
83 \\void entry(struct Foo * foo);
84 });
85
86 cases.add("array field-type",
87 \\const Foo = extern struct {
88 \\ A: [2]i32,
89 \\ B: [4]*u32,
90 \\};
91 \\export fn entry(foo: Foo, bar: [3]u8) void { }
92 , &[_][]const u8{
93 \\struct Foo {
94 \\ int32_t A[2];
95 \\ uint32_t * B[4];
96 \\};
97 ,
98 \\void entry(struct Foo foo, uint8_t bar[]);
99 \\
100 });
101
102 cases.add("ptr to zig struct",
103 \\const S = struct {
104 \\ a: u8,
105 \\};
106 \\
107 \\export fn a(s: *S) u8 {
108 \\ return s.a;
109 \\}
110 , &[_][]const u8{
111 \\struct S;
112 ,
113 \\uint8_t a(struct S * s);
114 \\
115 });
116
117 cases.add("ptr to zig union",
118 \\const U = union(enum) {
119 \\ A: u8,
120 \\ B: u16,
121 \\};
122 \\
123 \\export fn a(s: *U) u8 {
124 \\ return s.A;
125 \\}
126 , &[_][]const u8{
127 \\union U;
128 ,
129 \\uint8_t a(union U * s);
130 \\
131 });
132
133 cases.add("ptr to zig enum",
134 \\const E = enum(u8) {
135 \\ A,
136 \\ B,
137 \\};
138 \\
139 \\export fn a(s: *E) u8 {
140 \\ return @intFromEnum(s.*);
141 \\}
142 , &[_][]const u8{
143 \\enum E;
144 ,
145 \\uint8_t a(enum E * s);
146 \\
147 });
148}
test/src/Cases.zig+1-1
......@@ -495,7 +495,7 @@ pub fn lowerToBuildSteps(
495495
496496 if (case.case.? == .Error and options.skip_compile_errors) continue;
497497
498 if (options.skip_non_native and !@import("../tests.zig").isNative(&case.target, &b.graph.host.result))
498 if (options.skip_non_native and !std.zig.target.isNative(&case.target.query, &case.target.result, &b.graph.host.result))
499499 continue;
500500
501501 if (options.skip_spirv and case.target.query.cpu_arch != null and case.target.query.cpu_arch.?.isSpirV()) continue;
test/src/ErrorTrace.zig+1-1
......@@ -385,7 +385,7 @@ pub fn addCases(self: *ErrorTrace) void {
385385
386386 if (!self.options.test_extra_targets and params.extra_target) continue;
387387
388 if (self.options.skip_non_native and !tests.isNative(&resolved_target, &b.graph.host.result)) continue;
388 if (self.options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue;
389389
390390 if (self.options.skip_freebsd and target.os.tag == .freebsd) continue;
391391 if (self.options.skip_netbsd and target.os.tag == .netbsd) continue;
test/src/StackTrace.zig+1-1
......@@ -995,7 +995,7 @@ pub fn addCases(self: *StackTrace) void {
995995
996996 if (!self.options.test_extra_targets and params.extra_target) continue;
997997
998 if (self.options.skip_non_native and !tests.isNative(&resolved_target, &b.graph.host.result)) continue;
998 if (self.options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result)) continue;
999999
10001000 if (self.options.skip_freebsd and target.os.tag == .freebsd) continue;
10011001 if (self.options.skip_netbsd and target.os.tag == .netbsd) continue;
test/standalone/build.zig+8-3
......@@ -14,6 +14,7 @@ pub fn build(b: *std.Build) void {
1414 const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false;
1515 const simple_skip_release_fast = b.option(bool, "simple_skip_release_fast", "Simple tests skip release-fast builds") orelse false;
1616 const simple_skip_release_small = b.option(bool, "simple_skip_release_small", "Simple tests skip release-small builds") orelse false;
17 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
1718
1819 const simple_dep = b.dependency("simple", .{
1920 .skip_debug = simple_skip_debug,
......@@ -103,7 +104,7 @@ pub fn build(b: *std.Build) void {
103104 if (std.mem.eql(u8, dep_name, "simple")) continue;
104105
105106 const all_pkgs = @import("root").dependencies.packages;
106 inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| {
107 const forward_skip_non_native = inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| {
107108 if (std.mem.eql(u8, dep_hash, pkg_hash)) {
108109 const pkg = @field(all_pkgs, pkg_hash);
109110 if (!@hasDecl(pkg, "build_zig")) {
......@@ -121,11 +122,15 @@ pub fn build(b: *std.Build) void {
121122 {
122123 continue :add_dep_steps;
123124 }
124 break;
125 break @hasDecl(pkg.build_zig, "supports_skip_non_native") and
126 pkg.build_zig.supports_skip_non_native;
125127 }
126128 } else unreachable;
127129
128 const dep = b.dependency(dep_name, .{});
130 const dep = if (forward_skip_non_native)
131 b.dependency(dep_name, .{ .skip_non_native = skip_non_native })
132 else
133 b.dependency(dep_name, .{});
129134 const dep_step = dep.builder.default_step;
130135 dep_step.name = b.fmt("standalone_test_cases.{s}", .{dep_name});
131136 step.dependOn(dep_step);
test/standalone/build.zig.zon+3-28
......@@ -30,15 +30,9 @@
3030 .static_c_lib = .{
3131 .path = "static_c_lib",
3232 },
33 .issue_339 = .{
34 .path = "issue_339",
35 },
3633 .compile_asm = .{
3734 .path = "compile_asm",
3835 },
39 .issue_5825 = .{
40 .path = "issue_5825",
41 },
4236 .pkg_import = .{
4337 .path = "pkg_import",
4438 },
......@@ -132,24 +126,9 @@
132126 .c_embed_path = .{
133127 .path = "c_embed_path",
134128 },
135 .issue_12706 = .{
136 .path = "issue_12706",
137 },
138 .strip_empty_loop = .{
139 .path = "strip_empty_loop",
140 },
141 .strip_struct_init = .{
142 .path = "strip_struct_init",
143 },
144 .zerolength_check = .{
145 .path = "zerolength_check",
146 },
147129 .coff_dwarf = .{
148130 .path = "coff_dwarf",
149131 },
150 .compiler_rt_panic = .{
151 .path = "compiler_rt_panic",
152 },
153132 .ios = .{
154133 .path = "ios",
155134 },
......@@ -168,9 +147,6 @@
168147 .run_output_paths = .{
169148 .path = "run_output_paths",
170149 },
171 .empty_global_error_set = .{
172 .path = "empty_global_error_set",
173 },
174150 .config_header = .{
175151 .path = "config_header",
176152 },
......@@ -180,10 +156,9 @@
180156 .run_cwd = .{
181157 .path = "run_cwd",
182158 },
183 // https://github.com/ziglang/zig/issues/25471
184 // .tsan = .{
185 // .path = "tsan",
186 // },
159 .tsan = .{
160 .path = "tsan",
161 },
187162 .posix = .{
188163 .path = "posix",
189164 },
test/standalone/c_compiler/test.cpp+2-7
......@@ -1,9 +1,6 @@
11#include <cassert>
22#include <iostream>
3
4#ifndef _LIBCPP_HAS_NO_THREADS
53#include <future>
6#endif
74
85thread_local unsigned int tls_counter = 1;
96
......@@ -59,14 +56,12 @@ int main (int argc, char *argv[])
5956
6057 if (!ok) abort();
6158
62#ifndef _LIBCPP_HAS_NO_THREADS
6359 std::future<bool> fut = std::async(is_prime, 313);
6460 bool ret = fut.get();
6561 assert(ret);
66#endif
6762
68#if !defined(__wasm__) && !defined(__APPLE__)
69 // WASM and macOS are not passing this yet.
63#if !defined(__APPLE__)
64 // macOS is not passing this yet.
7065 // TODO file an issue for this and link it here.
7166 try {
7267 throw 20;
test/standalone/coff_dwarf/build.zig+6-11
......@@ -1,19 +1,12 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35/// This tests the path where DWARF information is embedded in a COFF binary
46pub fn build(b: *std.Build) void {
5 const host = b.graph.host;
6
7 // https://github.com/ziglang/zig/issues/25471
8 if (host.result.os.tag == .freebsd) return;
7 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
98
10 switch (host.result.cpu.arch) {
11 .aarch64,
12 .x86,
13 .x86_64,
14 => {},
15 else => return,
16 }
9 const host = b.graph.host;
1710
1811 const test_step = b.step("test", "Test it");
1912 b.default_step = test_step;
......@@ -24,6 +17,8 @@ pub fn build(b: *std.Build) void {
2417 else => b.resolveTargetQuery(.{ .os_tag = .windows }),
2518 };
2619
20 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &host.result)) return;
21
2722 const exe = b.addExecutable(.{
2823 .name = "main",
2924 .root_module = b.createModule(.{
test/standalone/compile_asm/build.zig+6
......@@ -1,6 +1,10 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) !void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
48 const test_step = b.step("test", "Test it");
59 b.default_step = test_step;
610
......@@ -13,6 +17,8 @@ pub fn build(b: *std.Build) !void {
1317 },
1418 });
1519
20 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
21
1622 const kernel = b.addExecutable(.{
1723 .name = "kernel",
1824 .root_module = b.createModule(.{
test/standalone/compiler_rt_panic/build.zig deleted-28
......@@ -1,28 +0,0 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const target = b.standardTargetOptions(.{});
8 const optimize = b.standardOptimizeOption(.{});
9
10 if (target.result.ofmt != .elf or !(target.result.abi.isMusl() or target.result.abi.isGnu()))
11 return;
12
13 const exe = b.addExecutable(.{
14 .name = "main",
15 .root_module = b.createModule(.{
16 .root_source_file = null,
17 .optimize = optimize,
18 .target = target,
19 .link_libc = true,
20 }),
21 });
22 exe.root_module.addCSourceFile(.{
23 .file = b.path("main.c"),
24 .flags = &.{},
25 });
26 exe.link_gc_sections = false;
27 exe.bundle_compiler_rt = true;
28}
test/standalone/compiler_rt_panic/main.c deleted-11
......@@ -1,11 +0,0 @@
1#include <stddef.h>
2
3void *__memset_chk(void *dest, int c, size_t n, size_t dest_n);
4
5char foo[128];
6
7int main() {
8 __memset_chk(&foo[0], 0xff, 128, 128);
9 return foo[64];
10}
11
test/standalone/dirname/has_basename.zig deleted-37
......@@ -1,37 +0,0 @@
1//! Checks that the basename of the given path matches a string.
2//!
3//! Usage:
4//!
5//! ```
6//! has_basename <path> <basename>
7//! ```
8//!
9//! <path> must be absolute.
10//!
11//! Returns a non-zero exit code if basename
12//! does not match the given string.
13
14const std = @import("std");
15
16pub fn main(init: std.process.Init) !void {
17 var args = try init.minimal.args.iterateAllocator(init.gpa);
18 defer args.deinit();
19 _ = args.next() orelse unreachable; // skip binary name
20
21 const path = args.next() orelse {
22 std.log.err("missing <path> argument", .{});
23 return error.BadUsage;
24 };
25
26 const basename = args.next() orelse {
27 std.log.err("missing <basename> argument", .{});
28 return error.BadUsage;
29 };
30
31 const actual_basename = std.fs.path.basename(path);
32 if (std.mem.eql(u8, actual_basename, basename)) {
33 return;
34 }
35
36 return error.NotEqual;
37}
test/standalone/elf2/build.zig+7
......@@ -1,4 +1,8 @@
1pub const supports_skip_non_native = true;
2
13pub fn build(b: *Build) void {
4 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
5
26 const test_step = b.step("test", "Test the new ELF linker");
37 b.default_step = test_step;
48
......@@ -15,6 +19,9 @@ pub fn build(b: *Build) void {
1519 .cpu_arch = .x86_64,
1620 .os_tag = .linux,
1721 });
22
23 if (skip_non_native and !std.zig.target.isNative(&x86_64_linux_target.query, &x86_64_linux_target.result, &b.graph.host.result)) return;
24
1825 addOne(b, test_step, x86_64_linux_target, false, .static, false, false, "elf2-hello-selfhosted-static");
1926 addOne(b, test_step, x86_64_linux_target, false, .static, true, false, "elf2-hello-selfhosted-static-pie");
2027 addOne(b, test_step, x86_64_linux_target, true, .static, false, false, "elf2-hello-llvm-static");
test/standalone/embed_generated_file/build.zig+12-4
......@@ -1,6 +1,17 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
8 const target = b.resolveTargetQuery(.{
9 .cpu_arch = .x86,
10 .os_tag = .freestanding,
11 });
12
13 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
14
415 const test_step = b.step("test", "Test it");
516 b.default_step = test_step;
617
......@@ -8,10 +19,7 @@ pub fn build(b: *std.Build) void {
819 .name = "bootloader",
920 .root_module = b.createModule(.{
1021 .root_source_file = b.path("bootloader.zig"),
11 .target = b.resolveTargetQuery(.{
12 .cpu_arch = .x86,
13 .os_tag = .freestanding,
14 }),
22 .target = target,
1523 .optimize = .small,
1624 }),
1725 });
test/standalone/empty_global_error_set/build.zig deleted-24
......@@ -1,24 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4pub fn build(b: *std.Build) void {
5 const test_step = b.step("test", "Test it");
6 b.default_step = test_step;
7
8 for ([_]bool{ false, true }) |use_llvm| {
9 const main = b.addObject(.{
10 .name = "main",
11 .root_module = b.createModule(.{
12 .root_source_file = b.path("main.zig"),
13 .target = b.resolveTargetQuery(.{
14 .cpu_arch = .x86_64,
15 .os_tag = .linux,
16 }),
17 }),
18 .use_llvm = use_llvm,
19 .use_lld = use_llvm,
20 });
21 _ = main.getEmittedBin();
22 test_step.dependOn(&main.step);
23 }
24}
test/standalone/empty_global_error_set/main.zig deleted-4
......@@ -1,4 +0,0 @@
1fn errorName(err: anyerror) [:0]const u8 {
2 return @errorName(err);
3}
4export const error_name: *const anyopaque = &errorName;
test/standalone/entry_point/build.zig+11-3
......@@ -1,11 +1,19 @@
1pub const supports_skip_non_native = true;
2
13pub fn build(b: *std.Build) !void {
4 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
5
6 const target = b.resolveTargetQuery(try .parse(.{
7 .arch_os_abi = "x86_64-linux",
8 }));
9
10 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
11
212 const mod = b.createModule(.{
313 // Setting the entry point doesn't work properly on all targets right now. Since we're
414 // really just trying to make sure that the compiler *frontend* respects `-fentry` and
515 // includes it in the cache manifest, just test for a target where it works.
6 .target = b.resolveTargetQuery(try .parse(.{
7 .arch_os_abi = "x86_64-linux",
8 })),
16 .target = target,
917 .optimize = .fast, // non-Debug build for reproducible output
1018 .root_source_file = b.path("main.zig"),
1119 });
test/standalone/glibc_compat/build.zig+15-3
......@@ -1,6 +1,8 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4pub const supports_skip_non_native = true;
5
46// To run executables linked against a specific glibc version, the
57// run-time glibc version needs to be new enough. Check the host's glibc
68// version. Note that this does not allow for translation/vm/emulation
......@@ -8,17 +10,23 @@ const builtin = @import("builtin");
810const running_glibc_ver = builtin.os.versionRange().gnuLibCVersion();
911
1012pub fn build(b: *std.Build) void {
13 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
14
1115 const test_step = b.step("test", "Test");
1216 b.default_step = test_step;
1317
1418 for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
19 const target = b.resolveTargetQuery(std.Target.Query.parse(
20 .{ .arch_os_abi = t },
21 ) catch unreachable);
22
23 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
24
1525 const exe = b.addExecutable(.{
1626 .name = t,
1727 .root_module = b.createModule(.{
1828 .root_source_file = null,
19 .target = b.resolveTargetQuery(std.Target.Query.parse(
20 .{ .arch_os_abi = t },
21 ) catch unreachable),
29 .target = target,
2230 .link_libc = true,
2331 }),
2432 });
......@@ -49,6 +57,8 @@ pub fn build(b: *std.Build) void {
4957 .{ .arch_os_abi = t },
5058 ) catch unreachable);
5159
60 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
61
5262 const glibc_ver = target.result.os.version_range.linux.glibc;
5363
5464 // only build test if glibc version supports the architecture
......@@ -103,6 +113,8 @@ pub fn build(b: *std.Build) void {
103113 .{ .arch_os_abi = t },
104114 ) catch unreachable);
105115
116 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
117
106118 if (target.result.cpu.arch.isLoongArch()) continue; // https://github.com/Vexu/arocc/issues/1096
107119
108120 const glibc_ver = target.result.os.version_range.linux.glibc;
test/standalone/install_raw_hex/build.zig+6
......@@ -1,7 +1,11 @@
11const builtin = @import("builtin");
22const std = @import("std");
33
4pub const supports_skip_non_native = true;
5
46pub fn build(b: *std.Build) void {
7 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
8
59 const test_step = b.step("test", "Test it");
610 b.default_step = test_step;
711
......@@ -12,6 +16,8 @@ pub fn build(b: *std.Build) void {
1216 .abi = .gnueabihf,
1317 });
1418
19 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
20
1521 const optimize: std.builtin.Optimize = .debug;
1622
1723 const elf = b.addExecutable(.{
test/standalone/issue_12706/build.zig deleted-30
......@@ -1,30 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4pub fn build(b: *std.Build) void {
5 const test_step = b.step("test", "Test it");
6 b.default_step = test_step;
7
8 const optimize: std.builtin.Optimize = .debug;
9 const target = b.graph.host;
10
11 const exe = b.addExecutable(.{
12 .name = "main",
13 .root_module = b.createModule(.{
14 .root_source_file = b.path("main.zig"),
15 .optimize = optimize,
16 .target = target,
17 }),
18 });
19
20 const c_sources = [_][]const u8{
21 "test.c",
22 };
23 exe.root_module.addCSourceFiles(.{ .files = &c_sources });
24 exe.root_module.link_libc = true;
25
26 const run_cmd = b.addRunArtifact(exe);
27 run_cmd.expectExitCode(0);
28 run_cmd.skip_foreign_checks = true;
29 test_step.dependOn(&run_cmd.step);
30}
test/standalone/issue_12706/main.zig deleted-12
......@@ -1,12 +0,0 @@
1const std = @import("std");
2extern fn testFnPtr(n: c_int, ...) void;
3
4const val: c_int = 123;
5
6fn func(a: c_int) callconv(.c) void {
7 std.debug.assert(a == val);
8}
9
10pub fn main() void {
11 testFnPtr(2, func, val);
12}
test/standalone/issue_12706/test.c deleted-11
......@@ -1,11 +0,0 @@
1#include <stdarg.h>
2
3void testFnPtr(int n, ...) {
4 va_list ap;
5 va_start(ap, n);
6
7 void (*fnPtr)(int) = va_arg(ap, void (*)(int));
8 int arg = va_arg(ap, int);
9 fnPtr(arg);
10 va_end(ap);
11}
\ No newline at end of file
test/standalone/issue_339/build.zig deleted-23
......@@ -1,23 +0,0 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const optimize: std.builtin.Optimize = .debug;
8 const target = b.graph.host;
9
10 const obj = b.addObject(.{
11 .name = "test",
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("test.zig"),
14 .target = target,
15 .optimize = optimize,
16 }),
17 });
18
19 // TODO: actually check the output
20 _ = obj.getEmittedBin();
21
22 test_step.dependOn(&obj.step);
23}
test/standalone/issue_339/test.zig deleted-13
......@@ -1,13 +0,0 @@
1const StackTrace = @import("std").builtin.StackTrace;
2pub fn panic(msg: []const u8, stack_trace: ?*StackTrace, _: ?usize) noreturn {
3 _ = msg;
4 _ = stack_trace;
5 @breakpoint();
6 while (true) {}
7}
8
9fn bar() anyerror!void {}
10
11export fn foo() void {
12 bar() catch unreachable;
13}
test/standalone/issue_5825/build.zig deleted-43
......@@ -1,43 +0,0 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4pub fn build(b: *std.Build) void {
5 const test_step = b.step("test", "Test it");
6 b.default_step = test_step;
7
8 // Building for the msvc abi requires a native MSVC installation
9 if (builtin.os.tag != .windows or builtin.cpu.arch != .x86_64) return;
10
11 const target = b.resolveTargetQuery(.{
12 .cpu_arch = .x86_64,
13 .os_tag = .windows,
14 .abi = .msvc,
15 });
16 const optimize: std.builtin.Optimize = .debug;
17 const obj = b.addObject(.{
18 .name = "issue_5825",
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("main.zig"),
21 .optimize = optimize,
22 .target = target,
23 }),
24 });
25
26 const exe = b.addExecutable(.{
27 .name = "issue_5825",
28 .root_module = b.createModule(.{
29 .root_source_file = null,
30 .optimize = optimize,
31 .target = target,
32 }),
33 });
34 exe.subsystem = .console;
35 exe.root_module.linkSystemLibrary("kernel32", .{});
36 exe.root_module.linkSystemLibrary("ntdll", .{});
37 exe.root_module.addObject(obj);
38
39 // TODO: actually check the output
40 _ = exe.getEmittedBin();
41
42 test_step.dependOn(&exe.step);
43}
test/standalone/issue_5825/main.zig deleted-5
......@@ -1,5 +0,0 @@
1const std = @import("std");
2
3pub fn main() anyerror!void {
4 std.log.info("All your codebase are belong to us.", .{});
5}
test/standalone/simple/build.zig-20
......@@ -97,26 +97,6 @@ const cases = [_]Case{
9797 .{
9898 .src_path = "cat/main.zig",
9999 },
100 // https://github.com/ziglang/zig/issues/6025
101 //.{
102 // .src_path = "issue_9693/main.zig",
103 //},
104 .{
105 .src_path = "issue_7030.zig",
106 .target = .{
107 .cpu_arch = .wasm32,
108 .os_tag = .freestanding,
109 },
110 },
111100 .{ .src_path = "guess_number/main.zig" },
112 .{ .src_path = "main_return_error/error_u8.zig" },
113 .{ .src_path = "main_return_error/error_u8_non_zero.zig" },
114 .{ .src_path = "noreturn_call/inline.zig" },
115 .{ .src_path = "noreturn_call/as_arg.zig" },
116101 .{ .src_path = "std_enums_big_enums.zig" },
117 .{
118 .src_path = "issue_9402/main.zig",
119 .os_filter = .windows,
120 .link_libc = true,
121 },
122102};
test/standalone/simple/issue_7030.zig deleted-21
......@@ -1,21 +0,0 @@
1const std = @import("std");
2
3pub const std_options: std.Options = .{
4 .logFn = log,
5};
6
7pub fn log(
8 comptime message_level: std.log.Level,
9 comptime scope: @EnumLiteral(),
10 comptime format: []const u8,
11 args: anytype,
12) void {
13 _ = message_level;
14 _ = scope;
15 _ = format;
16 _ = args;
17}
18
19pub fn main() anyerror!void {
20 std.log.info("All your codebase are belong to us.", .{});
21}
test/standalone/simple/issue_9402/main.zig deleted-14
......@@ -1,14 +0,0 @@
1const FILE = extern struct {
2 dummy_field: u8,
3};
4
5extern fn _ftelli64([*c]FILE) i64;
6extern fn _fseeki64([*c]FILE, i64, c_int) c_int;
7
8pub export fn main(argc: c_int, argv: **u8) c_int {
9 _ = argv;
10 _ = argc;
11 _ = _ftelli64(null);
12 _ = _fseeki64(null, 123, 2);
13 return 0;
14}
test/standalone/simple/main_return_error/error_u8.zig deleted-5
......@@ -1,5 +0,0 @@
1const Err = error{Foo};
2
3pub fn main() !u8 {
4 return Err.Foo;
5}
test/standalone/simple/main_return_error/error_u8_non_zero.zig deleted-10
......@@ -1,10 +0,0 @@
1const Err = error{Foo};
2
3fn foo() u8 {
4 return @intCast(9);
5}
6
7pub fn main() !u8 {
8 if (foo() == 7) return Err.Foo;
9 return 123;
10}
test/standalone/simple/noreturn_call/as_arg.zig deleted-8
......@@ -1,8 +0,0 @@
1const std = @import("std");
2fn foo() noreturn {
3 std.process.exit(0);
4}
5fn bar(_: u8, _: u8) void {}
6pub fn main() void {
7 bar(foo(), @compileError("bad"));
8}
test/standalone/simple/noreturn_call/inline.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 _ = bar();
3}
4inline fn bar() u8 {
5 noret();
6}
7const std = @import("std");
8inline fn noret() noreturn {
9 std.process.exit(0);
10}
test/standalone/strip_empty_loop/build.zig deleted-24
......@@ -1,24 +0,0 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test the program");
5 b.default_step = test_step;
6
7 const optimize = std.builtin.Optimize.debug;
8 const target = b.graph.host;
9
10 const main = b.addExecutable(.{
11 .name = "main",
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("main.zig"),
14 .optimize = optimize,
15 .target = target,
16 .strip = true,
17 }),
18 });
19
20 // TODO: actually check the output
21 _ = main.getEmittedBin();
22
23 test_step.dependOn(&main.step);
24}
test/standalone/strip_empty_loop/main.zig deleted-3
......@@ -1,3 +0,0 @@
1pub fn main() noreturn {
2 while (true) {} // When built without debug info, this produces an Air loop with no instructions
3}
test/standalone/strip_struct_init/build.zig deleted-19
......@@ -1,19 +0,0 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 const optimize: std.builtin.Optimize = .debug;
8
9 const main = b.addTest(.{
10 .root_module = b.createModule(.{
11 .root_source_file = b.path("main.zig"),
12 .target = b.graph.host,
13 .optimize = optimize,
14 .strip = true,
15 }),
16 });
17
18 test_step.dependOn(&b.addRunArtifact(main).step);
19}
test/standalone/strip_struct_init/main.zig deleted-23
......@@ -1,23 +0,0 @@
1fn Func(comptime Type: type) type {
2 return struct { value: Type };
3}
4
5inline fn func(value: anytype) Func(@TypeOf(value)) {
6 return .{ .value = value };
7}
8
9test {
10 _ = func(type);
11}
12
13test {
14 const S = struct { field: u32 };
15 comptime var arr: [1]S = undefined;
16 arr[0] = .{ .field = 0 };
17}
18
19test {
20 const S = struct { u32 };
21 comptime var arr: [1]S = undefined;
22 arr[0] = .{0};
23}
test/standalone/tsan/build.zig+47-22
......@@ -1,34 +1,62 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
5const targets: []const std.Target.Query = &.{
6 .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none },
7 .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none },
8
9 .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
10 .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl },
11 .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .gnu },
12 .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .musl },
13 .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnu },
14 .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .musl },
15 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabi64 },
16 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .muslabi64 },
17 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabi64 },
18 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .muslabi64 },
19 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .gnu },
20 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .musl },
21 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .gnu },
22 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .musl },
23 .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .gnu },
24 // .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .musl },
25 .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu },
26 .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
27
28 .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = .none },
29
30 // .{ .cpu_arch = .x86_64, .os_tag = .netbsd, .abi = .none },
31
32 // .{ .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu },
33 // .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu },
34};
35
336pub fn build(b: *std.Build) !void {
37 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
38
439 const test_step = b.step("test", "Test the program");
540 b.default_step = test_step;
641
742 const is_macos = b.graph.host.result.os.tag == .macos;
843
9 for ([_]struct { std.Target.Os.Tag, []const std.Target.Cpu.Arch }{
10 // .s390x and mips64(el) fail to build
11 .{ .linux, &.{ .aarch64, .aarch64_be, .loongarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } },
12 .{ .macos, &.{ .aarch64, .x86_64 } },
13
14 // powerpc64, powerpc64le, and riscv64 are not supported by TSan yet.
15 .{ .freebsd, &.{ .aarch64, .x86_64 } },
44 for (targets) |query| {
45 const target = b.resolveTargetQuery(query);
1646
17 .{ .netbsd, &.{.x86_64} },
47 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) continue;
1848
19 // TSan doesn't have full support for windows yet.
20 // .{ .windows, &.{ .aarch64, .x86_64 } },
21 }) |entry| {
22 switch (entry[0]) {
23 // compiling tsan on macos requires system headers that aren't present during cross-compilation
49 switch (target.result.os.tag) {
2450 .macos => {
51 // compiling tsan on macos requires system headers that aren't present during cross-compilation
2552 if (!is_macos) continue;
26 const target = b.resolveTargetQuery(.{});
53
2754 const exe = b.addExecutable(.{
28 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(target.result.cpu.arch) }),
55 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }),
56 .linkage = .dynamic,
2957 .root_module = b.createModule(.{
3058 .root_source_file = b.path("main.zig"),
31 .target = target,
59 .target = b.graph.host,
3260 .optimize = .debug,
3361 .sanitize_thread = true,
3462 }),
......@@ -36,13 +64,10 @@ pub fn build(b: *std.Build) !void {
3664 const install_exe = b.addInstallArtifact(exe, .{});
3765 test_step.dependOn(&install_exe.step);
3866 },
39 else => for (entry[1]) |arch| {
40 const target = b.resolveTargetQuery(.{
41 .os_tag = entry[0],
42 .cpu_arch = arch,
43 });
67 else => {
4468 const exe = b.addExecutable(.{
45 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(arch) }),
69 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }),
70 .linkage = .dynamic,
4671 .root_module = b.createModule(.{
4772 .root_source_file = b.path("main.zig"),
4873 .target = target,
test/standalone/windows_entry_points/build.zig+6
......@@ -1,6 +1,10 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
48 const test_step = b.step("test", "Test it");
59 b.default_step = test_step;
610
......@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {
1014 .abi = .gnu,
1115 });
1216
17 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
18
1319 {
1420 const exe = b.addExecutable(.{
1521 .name = "main",
test/standalone/windows_resources/build.zig+6
......@@ -1,6 +1,10 @@
11const std = @import("std");
22
3pub const supports_skip_non_native = true;
4
35pub fn build(b: *std.Build) void {
6 const skip_non_native = b.option(bool, "skip_non_native", "Skip non-native targets") orelse false;
7
48 const test_step = b.step("test", "Test it");
59 b.default_step = test_step;
610
......@@ -10,6 +14,8 @@ pub fn build(b: *std.Build) void {
1014 .abi = .gnu,
1115 });
1216
17 if (skip_non_native and !std.zig.target.isNative(&target.query, &target.result, &b.graph.host.result)) return;
18
1319 const generated_h_step = b.addWriteFile("generated.h", "#define GENERATED_DEFINE \"foo\"");
1420
1521 add(b, b.graph.host, .any, test_step, generated_h_step);
test/standalone/zerolength_check/build.zig deleted-27
......@@ -1,27 +0,0 @@
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const test_step = b.step("test", "Test it");
5 b.default_step = test_step;
6
7 add(b, test_step, .debug);
8 add(b, test_step, .fast);
9 add(b, test_step, .small);
10 add(b, test_step, .safe);
11}
12
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize) void {
14 const unit_tests = b.addTest(.{ .root_module = b.createModule(.{
15 .root_source_file = b.path("src/main.zig"),
16 .target = b.resolveTargetQuery(.{
17 .os_tag = .wasi,
18 .cpu_arch = .wasm32,
19 .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}),
20 }),
21 .optimize = optimize,
22 }) });
23
24 const run_unit_tests = b.addRunArtifact(unit_tests);
25 run_unit_tests.skip_foreign_checks = true;
26 test_step.dependOn(&run_unit_tests.step);
27}
test/standalone/zerolength_check/src/main.zig deleted-24
......@@ -1,24 +0,0 @@
1const std = @import("std");
2
3test {
4 const dest = foo();
5 const source = foo();
6
7 @memcpy(dest, source);
8 @memmove(dest, source);
9 @memset(dest, 4);
10 @memset(dest, undefined);
11
12 const dest2 = foo2();
13 @memset(dest2, 0);
14}
15
16fn foo() []u8 {
17 const ptr = comptime std.mem.alignBackward(usize, std.math.maxInt(usize), 1);
18 return @as([*]align(1) u8, @ptrFromInt(ptr))[0..0];
19}
20
21fn foo2() []u64 {
22 const ptr = comptime std.mem.alignBackward(usize, std.math.maxInt(usize), 1);
23 return @as([*]align(1) u64, @ptrFromInt(ptr))[0..0];
24}
test/tests.zig+6-160
......@@ -2323,162 +2323,6 @@ pub const debugger_matrix: []const RunnerTarget = &.{
23232323 },
23242324};
23252325
2326fn supportedCompatArch(host: *const std.Target, arch: std.Target.Cpu.Arch) bool {
2327 // aarch64-freebsd and aarch64-linux can technically run 32-bit ARM binaries, but that depends
2328 // on AArch32 support in the CPU. Since modern AArch64 CPUs have largely dropped this support,
2329 // avoid reporting compatibility for 32-bit here since we'd just build a bunch of test binaries
2330 // that never get run anyway. This added almost an hour's worth of useless work to aarch64-linux
2331 // CI, for example.
2332 //
2333 // riscv64-linux and riscv64-netbsd similarly support 32-bit binaries. However, this requires a
2334 // very recent kernel and for the kernel feature to be enabled. Additionally, contemporary
2335 // RISC-V hardware is just too slow to justify building the 32-bit binaries.
2336 return switch (host.os.tag) {
2337 .illumos => switch (host.cpu.arch) {
2338 .x86_64 => arch == .x86,
2339 else => false,
2340 },
2341 .linux => switch (host.cpu.arch) {
2342 .mips64 => arch == .mips,
2343 .mips64el => arch == .mipsel,
2344 .powerpc64 => arch == .powerpc,
2345 .sparc64 => arch == .sparc,
2346 .x86_64 => arch == .x86,
2347 else => false,
2348 },
2349 .netbsd => switch (host.cpu.arch) {
2350 .sparc64 => arch == .sparc,
2351 .x86_64 => arch == .x86,
2352 else => false,
2353 },
2354 .windows => switch (host.cpu.arch) {
2355 .x86_64 => arch == .x86,
2356 else => false,
2357 },
2358 else => false,
2359 };
2360}
2361
2362pub fn isNative(actual_target: *const std.Build.ResolvedTarget, host: *const std.Target) bool {
2363 if (actual_target.query.isNative()) return true;
2364 const actual = &actual_target.result;
2365
2366 if (actual.cpu.arch != host.cpu.arch and !supportedCompatArch(host, actual.cpu.arch))
2367 return false;
2368
2369 if (actual.os.tag != host.os.tag)
2370 return false;
2371
2372 // This check is really only necessary for the case where `host.cpu.arch.isAarch64()` and
2373 // `actual.cpu.arch.isArm()`. As they are wholly separate `std.Target` families with their own
2374 // feature bits, the logic below would produce complete nonsense.
2375 //
2376 // This does mean that we aren't actually checking feature compatibility between these two
2377 // families even though we should. That's not a problem currently, but in the future, we may
2378 // need to add a special code path just for this specific case...
2379 if (actual.cpu.arch.family() != host.cpu.arch.family())
2380 return true;
2381
2382 // Remove features that don't actually affect compatibility.
2383 const irrelevant: std.Target.Cpu.Feature.Set = switch (host.cpu.arch) {
2384 .x86_64 => std.Target.x86.featureSet(&.{
2385 .@"16bit_mode",
2386 .@"32bit_mode",
2387 .@"64bit",
2388 .false_deps_bls,
2389 .false_deps_compress,
2390 .false_deps_expand,
2391 .false_deps_getmant,
2392 .false_deps_lzcnt,
2393 .false_deps_mulc,
2394 .false_deps_mullq,
2395 .false_deps_perm,
2396 .false_deps_popcnt,
2397 .false_deps_range,
2398 .false_deps_tzcnt,
2399 .fast_11bytenop,
2400 .fast_15bytenop,
2401 .fast_7bytenop,
2402 .fast_bextr,
2403 .fast_dpwssd,
2404 .fast_gather,
2405 .fast_hops,
2406 .fast_imm16,
2407 .fast_lzcnt,
2408 .fast_movbe,
2409 .fast_scalar_fsqrt,
2410 .fast_scalar_shift_masks,
2411 .fast_shld_rotate,
2412 .fast_variable_crosslane_shuffle,
2413 .fast_variable_perlane_shuffle,
2414 .fast_vector_fsqrt,
2415 .fast_vector_shift_masks,
2416 .faster_shift_than_shuffle,
2417 .no_bypass_delay,
2418 .no_bypass_delay_blend,
2419 .no_bypass_delay_mov,
2420 .no_bypass_delay_shuffle,
2421 .prefer_128_bit,
2422 .prefer_256_bit,
2423 .prefer_legacy_setcc,
2424 .prefer_mask_registers,
2425 .prefer_movmsk_over_vtest,
2426 .prefer_ndd_mem,
2427 .prefer_no_gather,
2428 .prefer_no_scatter,
2429 .slow_3ops_lea,
2430 .slow_incdec,
2431 .slow_indirect_call,
2432 .slow_lea,
2433 .slow_pmaddwd,
2434 .slow_pmulld,
2435 .slow_pmullq,
2436 .slow_shld,
2437 .slow_two_mem_ops,
2438 .slow_unaligned_mem_16,
2439 .slow_unaligned_mem_32,
2440 }),
2441 .aarch64, .aarch64_be => std.Target.aarch64.featureSet(&.{
2442 .addr_lsl_slow_14,
2443 .align_cmp_csel_pairs,
2444 .alu_lsl_fast,
2445 .avoid_ldapur,
2446 .disable_fast_inc_vl,
2447 .exynos_cheap_as_move,
2448 .fast_ld1_single,
2449 .fixed_load_latency_4,
2450 .fuse_address,
2451 .fuse_addsub_2reg_const1,
2452 .fuse_adrp_add,
2453 .fuse_aes,
2454 .fuse_arith_logic,
2455 .fuse_crypto_eor,
2456 .fuse_csel,
2457 .fuse_cset,
2458 .fuse_fcsel,
2459 .fuse_literals,
2460 .has_limited_64bit_vector_mul_bandwidth,
2461 .predictable_select_expensive,
2462 .slow_misaligned_128store,
2463 .slow_paired_128,
2464 .slow_strqro_store,
2465 .use_experimental_zeroing_pseudos,
2466 .use_fixed_over_scalable_if_equal_cost,
2467 .use_postra_scheduler,
2468 .use_reciprocal_square_root,
2469 .use_wzr_to_vec_move,
2470 }),
2471 else => .empty,
2472 };
2473 var set = actual.cpu.features;
2474 set.removeFeatureSet(irrelevant);
2475
2476 if (!host.cpu.features.isSuperSetOf(set))
2477 return false;
2478
2479 return true;
2480}
2481
24822326pub fn addStackTraceTests(b: *std.Build, options: StackTracesContext.Options) *Step {
24832327 const step = b.step("test-stack-traces", "Run the stack trace tests");
24842328
......@@ -2530,6 +2374,7 @@ pub fn addErrorTraceTests(b: *std.Build, options: ErrorTracesContext.Options) *S
25302374pub fn addStandaloneTests(
25312375 b: *std.Build,
25322376 optimize_modes: []const OptimizeMode,
2377 skip_non_native: bool,
25332378 enable_macos_sdk: bool,
25342379 enable_ios_sdk: bool,
25352380 enable_symlinks_windows: bool,
......@@ -2544,6 +2389,7 @@ pub fn addStandaloneTests(
25442389 .simple_skip_release_safe = mem.findScalar(OptimizeMode, optimize_modes, .safe) == null,
25452390 .simple_skip_release_fast = mem.findScalar(OptimizeMode, optimize_modes, .fast) == null,
25462391 .simple_skip_release_small = mem.findScalar(OptimizeMode, optimize_modes, .small) == null,
2392 .skip_non_native = skip_non_native,
25472393 });
25482394 const test_cases_dep_step = test_cases_dep.builder.default_step;
25492395 test_cases_dep_step.name = test_cases_dep_name;
......@@ -2830,7 +2676,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
28302676
28312677 if (!options.test_extra_targets and test_target.extra_target) continue;
28322678
2833 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
2679 if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result))
28342680 continue;
28352681
28362682 const target = &resolved_target.result;
......@@ -3156,7 +3002,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
31563002 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
31573003 const target = &resolved_target.result;
31583004
3159 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
3005 if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result))
31603006 continue;
31613007
31623008 if (options.test_target_filters.len > 0) {
......@@ -3249,7 +3095,7 @@ pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step {
32493095 for (link_targets) |link_target| {
32503096 const resolved_target = b.resolveTargetQuery(link_target.target);
32513097
3252 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
3098 if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result))
32533099 continue;
32543100
32553101 const target = &resolved_target.result;
......@@ -3399,7 +3245,7 @@ pub fn addRunnerTests(
33993245 for (matrix) |test_target| {
34003246 const resolved_target = b.resolveTargetQuery(test_target.target);
34013247
3402 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
3248 if (options.skip_non_native and !std.zig.target.isNative(&resolved_target.query, &resolved_target.result, &b.graph.host.result))
34033249 continue;
34043250
34053251 const target = &resolved_target.result;