| 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 | "foo", |
| 22 | "foo-dync", |
| 23 | "foo-no-llvm", |
| 24 | "foo-no-llvm-dync", |
| 25 | "foo-exe-no-llvm", |
| 26 | "foo-dync-exe-no-llvm", |
| 27 | "foo-no-llvm-exe-no-llvm", |
| 28 | "foo-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 foo = b.addLibrary(.{ |
| 53 | .linkage = .static, |
| 54 | .name = lib_name, |
| 55 | .root_module = b.createModule(.{ |
| 56 | .root_source_file = null, |
| 57 | .optimize = optimize, |
| 58 | .target = target, |
| 59 | .link_libc = dyn_libc, |
| 60 | }), |
| 61 | .use_llvm = lib_llvm, |
| 62 | }); |
| 63 | foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); |
| 64 | foo.root_module.addIncludePath(b.path(".")); |
| 65 | |
| 66 | const test_exe = b.addTest(.{ |
| 67 | .name = exe_name, |
| 68 | .root_module = b.createModule(.{ |
| 69 | .root_source_file = b.path("foo.zig"), |
| 70 | .target = target, |
| 71 | .optimize = optimize, |
| 72 | .link_libc = dyn_libc, |
| 73 | }), |
| 74 | .use_llvm = exe_llvm, |
| 75 | }); |
| 76 | test_exe.root_module.linkLibrary(foo); |
| 77 | test_exe.root_module.addIncludePath(b.path(".")); |
| 78 | |
| 79 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 80 | } |
| 81 | } |