Skip to content

Commit 62d1724

Browse files
committed
test: add a standalone test for compiling tsan
1 parent 4e685b8 commit 62d1724

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

test/standalone/build.zig.zon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
.run_cwd = .{
209209
.path = "run_cwd",
210210
},
211+
.tsan = .{
212+
.path = "tsan",
213+
},
211214
},
212215
.paths = .{
213216
"build.zig",

test/standalone/tsan/build.zig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const std = @import("std");
2+
3+
pub 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 is_macos = b.graph.host.result.os.tag == .macos;
8+
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+
// x86_64 fails to build due to missing headers
13+
.{ .macos, &.{.aarch64} },
14+
15+
// Missing system headers
16+
// https://github.com/ziglang/zig/issues/24736
17+
// .{ .freebsd, &.{ .aarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } },
18+
// https://github.com/ziglang/zig/issues/24737
19+
// .{ .netbsd, &.{ .aarch64, .aarch64_be, .x86_64 } },
20+
21+
// TSan doesn't have full support for windows yet.
22+
// .{ .windows, &.{ .aarch64, .x86_64 } },
23+
}) |entry| {
24+
// compiling tsan on macos requires system headers that aren't present during cross-compilation
25+
if (entry[0] == .macos and !is_macos) continue;
26+
27+
for (entry[1]) |arch| {
28+
const target = b.resolveTargetQuery(.{
29+
.os_tag = entry[0],
30+
.cpu_arch = arch,
31+
});
32+
const exe = b.addExecutable(.{
33+
.name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(arch) }),
34+
.root_module = b.createModule(.{
35+
.root_source_file = b.path("main.zig"),
36+
.target = target,
37+
.optimize = .Debug,
38+
.sanitize_thread = true,
39+
}),
40+
});
41+
const install_exe = b.addInstallArtifact(exe, .{});
42+
test_step.dependOn(&install_exe.step);
43+
}
44+
}
45+
}

test/standalone/tsan/main.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const std = @import("std");
2+
3+
pub fn main() !void {}

0 commit comments

Comments
 (0)