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 @@...@@ -156,10 +156,9 @@
156 .run_cwd = .{156 .run_cwd = .{
157 .path = "run_cwd",157 .path = "run_cwd",
158 },158 },
159 // https://github.com/ziglang/zig/issues/25471159 .tsan = .{
160 // .tsan = .{160 .path = "tsan",
161 // .path = "tsan",161 },
162 // },
163 .posix = .{162 .posix = .{
164 .path = "posix",163 .path = "posix",
165 },164 },
test/standalone/tsan/build.zig+42-23
...@@ -1,34 +1,56 @@...@@ -1,34 +1,56 @@
1const std = @import("std");1const 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
3pub fn build(b: *std.Build) !void {34pub fn build(b: *std.Build) !void {
4 const test_step = b.step("test", "Test the program");35 const test_step = b.step("test", "Test the program");
5 b.default_step = test_step;36 b.default_step = test_step;
637
7 const is_macos = b.graph.host.result.os.tag == .macos;38 const is_macos = b.graph.host.result.os.tag == .macos;
839
9 for ([_]struct { std.Target.Os.Tag, []const std.Target.Cpu.Arch }{40 for (targets) |query| {
10 // .s390x and mips64(el) fail to build41 const target = b.resolveTargetQuery(query);
11 .{ .linux, &.{ .aarch64, .aarch64_be, .loongarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } },
12 .{ .macos, &.{ .aarch64, .x86_64 } },
1342
14 // powerpc64, powerpc64le, and riscv64 are not supported by TSan yet.43 switch (target.result.os.tag) {
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
24 .macos => {44 .macos => {
45 // compiling tsan on macos requires system headers that aren't present during cross-compilation
25 if (!is_macos) continue;46 if (!is_macos) continue;
26 const target = b.resolveTargetQuery(.{});47
27 const exe = b.addExecutable(.{48 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,
29 .root_module = b.createModule(.{51 .root_module = b.createModule(.{
30 .root_source_file = b.path("main.zig"),52 .root_source_file = b.path("main.zig"),
31 .target = target,53 .target = b.graph.host,
32 .optimize = .debug,54 .optimize = .debug,
33 .sanitize_thread = true,55 .sanitize_thread = true,
34 }),56 }),
...@@ -36,13 +58,10 @@ pub fn build(b: *std.Build) !void {...@@ -36,13 +58,10 @@ pub fn build(b: *std.Build) !void {
36 const install_exe = b.addInstallArtifact(exe, .{});58 const install_exe = b.addInstallArtifact(exe, .{});
37 test_step.dependOn(&install_exe.step);59 test_step.dependOn(&install_exe.step);
38 },60 },
39 else => for (entry[1]) |arch| {61 else => {
40 const target = b.resolveTargetQuery(.{
41 .os_tag = entry[0],
42 .cpu_arch = arch,
43 });
44 const exe = b.addExecutable(.{62 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,
46 .root_module = b.createModule(.{65 .root_module = b.createModule(.{
47 .root_source_file = b.path("main.zig"),66 .root_source_file = b.path("main.zig"),
48 .target = target,67 .target = target,