| 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 | const optimize: std.builtin.Optimize = .debug; |
| 8 | const target = b.standardTargetOptions(.{}); |
| 9 | |
| 10 | const exe_names: []const []const u8 = &.{ |
| 11 | "test", |
| 12 | "test-dync", |
| 13 | "test-no-llvm", |
| 14 | "test-no-llvm-dync", |
| 15 | "test-exe-no-llvm", |
| 16 | "test-dync-exe-no-llvm", |
| 17 | "test-no-llvm-exe-no-llvm", |
| 18 | "test-no-llvm-dync-exe-no-llvm", |
| 19 | }; |
| 20 | const lib_names: []const []const u8 = &.{ |
| 21 | "mathtest", |
| 22 | "mathtest-dync", |
| 23 | "mathtest-no-llvm", |
| 24 | "mathtest-no-llvm-dync", |
| 25 | "mathtest-exe-no-llvm", |
| 26 | "mathtest-dync-exe-no-llvm", |
| 27 | "mathtest-no-llvm-exe-no-llvm", |
| 28 | "mathtest-no-llvm-dync-exe-no-llvm", |
| 29 | }; |
| 30 | const lib_link_libc: []const bool = &.{ false, true, false, true, false, true, false, true }; |
| 31 | const lib_use_llvm: []const bool = &.{ true, true, false, false, true, true, false, false }; |
| 32 | const exe_use_llvm: []const bool = &.{ true, true, true, true, false, false, false, false }; |
| 33 | |
| 34 | for ( |
| 35 | exe_names, |
| 36 | lib_names, |
| 37 | lib_link_libc, |
| 38 | lib_use_llvm, |
| 39 | exe_use_llvm, |
| 40 | ) |exe_name, lib_name, dyn_libc, lib_llvm, exe_llvm| { |
| 41 | const no_llvm = !lib_llvm or !exe_llvm; |
| 42 | if (no_llvm and target.result.os.tag == .macos) continue; // TODO |
| 43 | if (no_llvm and target.result.os.tag == .freebsd) continue; // TODO |
| 44 | if (no_llvm and target.result.os.tag == .netbsd) continue; // TODO |
| 45 | if (no_llvm and target.result.os.tag == .openbsd) continue; // TODO |
| 46 | if (no_llvm and target.result.cpu.arch == .aarch64) continue; // TODO |
| 47 | if (no_llvm and target.result.cpu.arch == .loongarch64) continue; // TODO |
| 48 | if (no_llvm and target.result.cpu.arch == .powerpc64le) continue; // TODO |
| 49 | if (no_llvm and target.result.cpu.arch == .riscv64) continue; // TODO |
| 50 | if (no_llvm and target.result.cpu.arch == .s390x) continue; // TODO |
| 51 | |
| 52 | const lib = b.addLibrary(.{ |
| 53 | .linkage = .dynamic, |
| 54 | .name = lib_name, |
| 55 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 56 | .root_module = b.createModule(.{ |
| 57 | .root_source_file = b.path("mathtest.zig"), |
| 58 | .target = target, |
| 59 | .optimize = optimize, |
| 60 | .link_libc = dyn_libc, |
| 61 | }), |
| 62 | .use_llvm = lib_llvm, |
| 63 | }); |
| 64 | |
| 65 | const exe = b.addExecutable(.{ |
| 66 | .name = exe_name, |
| 67 | .root_module = b.createModule(.{ |
| 68 | .root_source_file = null, |
| 69 | .target = target, |
| 70 | .optimize = optimize, |
| 71 | .link_libc = true, |
| 72 | }), |
| 73 | .use_llvm = exe_llvm, |
| 74 | }); |
| 75 | exe.root_module.addCSourceFile(.{ |
| 76 | .file = b.path("test.c"), |
| 77 | .flags = &[_][]const u8{"-std=c99"}, |
| 78 | }); |
| 79 | exe.root_module.linkLibrary(lib); |
| 80 | |
| 81 | const run_cmd = b.addRunArtifact(exe); |
| 82 | test_step.dependOn(&run_cmd.step); |
| 83 | } |
| 84 | } |