authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-09 11:44:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-10 08:36:08+02:00
log03422925b127a8d369fc82ce333e2d77366c3849
tree71929570027d7b7c4011b2aab825c75790cbc1db
parent40cde789f792769a1d938f6bc620b6a67c3b8099
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

test-standalone: resurrect tsan test

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

2 files changed, 45 insertions(+), 27 deletions(-)

test/standalone/build.zig.zon+3-4
......@@ -156,10 +156,9 @@
156156 .run_cwd = .{
157157 .path = "run_cwd",
158158 },
159 // https://github.com/ziglang/zig/issues/25471
160 // .tsan = .{
161 // .path = "tsan",
162 // },
159 .tsan = .{
160 .path = "tsan",
161 },
163162 .posix = .{
164163 .path = "posix",
165164 },
test/standalone/tsan/build.zig+42-23
......@@ -1,34 +1,56 @@
11const std = @import("std");
22
3const targets: []const std.Target.Query = &.{
4 .{ .cpu_arch = .aarch64, .os_tag = .freebsd, .abi = .none },
5 .{ .cpu_arch = .x86_64, .os_tag = .freebsd, .abi = .none },
6
7 .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
8 .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .musl },
9 .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .gnu },
10 .{ .cpu_arch = .aarch64_be, .os_tag = .linux, .abi = .musl },
11 .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnu },
12 .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .musl },
13 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabi64 },
14 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .muslabi64 },
15 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabi64 },
16 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .muslabi64 },
17 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .gnu },
18 .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .musl },
19 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .gnu },
20 .{ .cpu_arch = .riscv64, .os_tag = .linux, .abi = .musl },
21 .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .gnu },
22 // .{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .musl },
23 .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu },
24 .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
25
26 .{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = .none },
27
28 // .{ .cpu_arch = .x86_64, .os_tag = .netbsd, .abi = .none },
29
30 // .{ .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu },
31 // .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu },
32};
33
334pub fn build(b: *std.Build) !void {
435 const test_step = b.step("test", "Test the program");
536 b.default_step = test_step;
637
738 const is_macos = b.graph.host.result.os.tag == .macos;
839
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 } },
40 for (targets) |query| {
41 const target = b.resolveTargetQuery(query);
1342
14 // powerpc64, powerpc64le, and riscv64 are not supported by TSan yet.
15 .{ .freebsd, &.{ .aarch64, .x86_64 } },
16
17 .{ .netbsd, &.{.x86_64} },
18
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
43 switch (target.result.os.tag) {
2444 .macos => {
45 // compiling tsan on macos requires system headers that aren't present during cross-compilation
2546 if (!is_macos) continue;
26 const target = b.resolveTargetQuery(.{});
47
2748 const exe = b.addExecutable(.{
28 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(target.result.cpu.arch) }),
49 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }),
50 .linkage = .dynamic,
2951 .root_module = b.createModule(.{
3052 .root_source_file = b.path("main.zig"),
31 .target = target,
53 .target = b.graph.host,
3254 .optimize = .debug,
3355 .sanitize_thread = true,
3456 }),
......@@ -36,13 +58,10 @@ pub fn build(b: *std.Build) !void {
3658 const install_exe = b.addInstallArtifact(exe, .{});
3759 test_step.dependOn(&install_exe.step);
3860 },
39 else => for (entry[1]) |arch| {
40 const target = b.resolveTargetQuery(.{
41 .os_tag = entry[0],
42 .cpu_arch = arch,
43 });
61 else => {
4462 const exe = b.addExecutable(.{
45 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(arch) }),
63 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(target.result.os.tag), @tagName(target.result.cpu.arch) }),
64 .linkage = .dynamic,
4665 .root_module = b.createModule(.{
4766 .root_source_file = b.path("main.zig"),
4867 .target = target,