authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2025-08-07 14:27:53-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-11 03:02:54+02:00
log826b33863fe9ee46a30f80a10793bdbde80a96ca
tree2d78f4fbc0b7675cf61bb922cb1e35faf9ff4c63
parentc42187732d3c49a06b0097d0253036efd5153588

test: add a standalone test for compiling tsan


3 files changed, 65 insertions(+), 0 deletions(-)

test/standalone/build.zig.zon+3
......@@ -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 created+59
......@@ -0,0 +1,59 @@
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 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 .{ .macos, &.{ .x86_64, .aarch64 } },
13
14 // Missing system headers
15 // https://github.com/ziglang/zig/issues/24736
16 // .{ .freebsd, &.{ .aarch64, .powerpc64, .powerpc64le, .riscv64, .x86_64 } },
17 // https://github.com/ziglang/zig/issues/24737
18 // .{ .netbsd, &.{ .aarch64, .aarch64_be, .x86_64 } },
19
20 // TSan doesn't have full support for windows yet.
21 // .{ .windows, &.{ .aarch64, .x86_64 } },
22 }) |entry| {
23 switch (entry[0]) {
24 // compiling tsan on macos requires system headers that aren't present during cross-compilation
25 .macos => {
26 if (!is_macos) continue;
27 const target = b.resolveTargetQuery(.{});
28 const exe = b.addExecutable(.{
29 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(target.result.cpu.arch) }),
30 .root_module = b.createModule(.{
31 .root_source_file = b.path("main.zig"),
32 .target = target,
33 .optimize = .Debug,
34 .sanitize_thread = true,
35 }),
36 });
37 const install_exe = b.addInstallArtifact(exe, .{});
38 test_step.dependOn(&install_exe.step);
39 },
40 else => for (entry[1]) |arch| {
41 const target = b.resolveTargetQuery(.{
42 .os_tag = entry[0],
43 .cpu_arch = arch,
44 });
45 const exe = b.addExecutable(.{
46 .name = b.fmt("tsan_{s}_{s}", .{ @tagName(entry[0]), @tagName(arch) }),
47 .root_module = b.createModule(.{
48 .root_source_file = b.path("main.zig"),
49 .target = target,
50 .optimize = .Debug,
51 .sanitize_thread = true,
52 }),
53 });
54 const install_exe = b.addInstallArtifact(exe, .{});
55 test_step.dependOn(&install_exe.step);
56 },
57 }
58 }
59}
test/standalone/tsan/main.zig created+3
......@@ -0,0 +1,3 @@
1const std = @import("std");
2
3pub fn main() !void {}