| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub fn build(b: *std.Build) void { |
| 4 | const test_step = b.step("test", "Test it"); |
| 5 | b.default_step = test_step; |
| 6 | |
| 7 | if (@import("builtin").os.tag == .windows) { |
| 8 | // https://github.com/ziglang/zig/issues/14800 |
| 9 | return; |
| 10 | } |
| 11 | |
| 12 | add(b, test_step, .debug); |
| 13 | add(b, test_step, .fast); |
| 14 | add(b, test_step, .small); |
| 15 | add(b, test_step, .safe); |
| 16 | } |
| 17 | |
| 18 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize) void { |
| 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "test", |
| 21 | .root_module = b.createModule(.{ |
| 22 | .root_source_file = b.path("main.zig"), |
| 23 | .target = b.graph.host, |
| 24 | .optimize = optimize, |
| 25 | .link_libc = true, |
| 26 | }), |
| 27 | // extern threadlocals are not implemented in the self-hosted linker |
| 28 | .use_llvm = true, |
| 29 | }); |
| 30 | exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); |
| 31 | |
| 32 | const run_cmd = b.addRunArtifact(exe); |
| 33 | run_cmd.skip_foreign_checks = true; |
| 34 | run_cmd.expectExitCode(0); |
| 35 | |
| 36 | test_step.dependOn(&run_cmd.step); |
| 37 | } |