|
| 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 | + .{ .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 | +} |
0 commit comments