| 1 | const std = @import("std"); |
| 2 | pub fn build(b: *std.Build) void { |
| 3 | const test_filters = b.option( |
| 4 | []const []const u8, |
| 5 | "test-filter", |
| 6 | "Skip tests that do not match any filter", |
| 7 | ) orelse &[0][]const u8{}; |
| 8 | const strip = b.option(bool, "strip", "Omit debug information"); |
| 9 | |
| 10 | const compiler_rt_lib = b.addLibrary(.{ |
| 11 | .linkage = .static, |
| 12 | .name = "compiler_rt", |
| 13 | .use_llvm = false, |
| 14 | .use_lld = false, |
| 15 | .root_module = b.createModule(.{ |
| 16 | .root_source_file = b.addWriteFiles().add("compiler_rt.zig", ""), |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64 }), |
| 18 | }), |
| 19 | }); |
| 20 | compiler_rt_lib.bundle_compiler_rt = true; |
| 21 | |
| 22 | for ([_]std.Target.Query{ |
| 23 | .{ |
| 24 | .cpu_arch = .x86_64, |
| 25 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 26 | .cpu_features_add = std.Target.x86.featureSet(&.{.bsf_bsr_0_clobbers_result}), |
| 27 | //.cpu_features_sub = std.Target.x86.featureSet(&.{.sse}), |
| 28 | }, |
| 29 | .{ |
| 30 | .cpu_arch = .x86_64, |
| 31 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 32 | .cpu_features_add = std.Target.x86.featureSet(&.{.bsf_bsr_0_clobbers_result}), |
| 33 | .cpu_features_sub = std.Target.x86.featureSet(&.{ |
| 34 | .cmov, |
| 35 | //.sse, |
| 36 | .sse2, |
| 37 | }), |
| 38 | }, |
| 39 | .{ |
| 40 | .cpu_arch = .x86_64, |
| 41 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 42 | .cpu_features_add = std.Target.x86.featureSet(&.{.sahf}), |
| 43 | .cpu_features_sub = std.Target.x86.featureSet(&.{.cmov}), |
| 44 | }, |
| 45 | //.{ |
| 46 | // .cpu_arch = .x86_64, |
| 47 | // .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 48 | // .cpu_features_sub = std.Target.x86.featureSet(&.{.sse}), |
| 49 | //}, |
| 50 | .{ |
| 51 | .cpu_arch = .x86_64, |
| 52 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 53 | .cpu_features_sub = std.Target.x86.featureSet(&.{.sse2}), |
| 54 | }, |
| 55 | .{ |
| 56 | .cpu_arch = .x86_64, |
| 57 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 58 | }, |
| 59 | .{ |
| 60 | .cpu_arch = .x86_64, |
| 61 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 62 | .cpu_features_add = std.Target.x86.featureSet(&.{ .adx, .gfni }), |
| 63 | }, |
| 64 | .{ |
| 65 | .cpu_arch = .x86_64, |
| 66 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 67 | .cpu_features_add = std.Target.x86.featureSet(&.{.sse3}), |
| 68 | }, |
| 69 | .{ |
| 70 | .cpu_arch = .x86_64, |
| 71 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 72 | .cpu_features_add = std.Target.x86.featureSet(&.{.ssse3}), |
| 73 | }, |
| 74 | .{ |
| 75 | .cpu_arch = .x86_64, |
| 76 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 77 | .cpu_features_add = std.Target.x86.featureSet(&.{.sse4_1}), |
| 78 | }, |
| 79 | .{ |
| 80 | .cpu_arch = .x86_64, |
| 81 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 82 | .cpu_features_add = std.Target.x86.featureSet(&.{.sse4_2}), |
| 83 | }, |
| 84 | .{ |
| 85 | .cpu_arch = .x86_64, |
| 86 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, |
| 87 | }, |
| 88 | .{ |
| 89 | .cpu_arch = .x86_64, |
| 90 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, |
| 91 | .cpu_features_add = std.Target.x86.featureSet(&.{ .adx, .fast_hops, .gfni, .pclmul, .slow_incdec }), |
| 92 | }, |
| 93 | .{ |
| 94 | .cpu_arch = .x86_64, |
| 95 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, |
| 96 | .cpu_features_add = std.Target.x86.featureSet(&.{.avx}), |
| 97 | }, |
| 98 | .{ |
| 99 | .cpu_arch = .x86_64, |
| 100 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, |
| 101 | .cpu_features_add = std.Target.x86.featureSet(&.{ .adx, .fast_hops, .gfni, .pclmul, .slow_incdec }), |
| 102 | .cpu_features_sub = std.Target.x86.featureSet(&.{.avx2}), |
| 103 | }, |
| 104 | .{ |
| 105 | .cpu_arch = .x86_64, |
| 106 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, |
| 107 | }, |
| 108 | .{ |
| 109 | .cpu_arch = .x86_64, |
| 110 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, |
| 111 | .cpu_features_add = std.Target.x86.featureSet(&.{ .adx, .fast_hops, .gfni, .slow_incdec, .vpclmulqdq }), |
| 112 | }, |
| 113 | .{ |
| 114 | .cpu_arch = .x86_64, |
| 115 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v4 }, |
| 116 | }, |
| 117 | |
| 118 | .{ |
| 119 | .cpu_arch = .x86_64, |
| 120 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 121 | .os_tag = .windows, |
| 122 | .abi = .none, |
| 123 | }, |
| 124 | .{ |
| 125 | .cpu_arch = .x86_64, |
| 126 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 127 | .cpu_features_add = std.Target.x86.featureSet(&.{.ssse3}), |
| 128 | .os_tag = .windows, |
| 129 | .abi = .none, |
| 130 | }, |
| 131 | .{ |
| 132 | .cpu_arch = .x86_64, |
| 133 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, |
| 134 | .os_tag = .windows, |
| 135 | .abi = .none, |
| 136 | }, |
| 137 | .{ |
| 138 | .cpu_arch = .x86_64, |
| 139 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, |
| 140 | .os_tag = .windows, |
| 141 | .abi = .none, |
| 142 | }, |
| 143 | |
| 144 | .{ |
| 145 | .cpu_arch = .x86_64, |
| 146 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64 }, |
| 147 | .os_tag = .windows, |
| 148 | .abi = .gnu, |
| 149 | }, |
| 150 | .{ |
| 151 | .cpu_arch = .x86_64, |
| 152 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 }, |
| 153 | .os_tag = .windows, |
| 154 | .abi = .gnu, |
| 155 | }, |
| 156 | .{ |
| 157 | .cpu_arch = .x86_64, |
| 158 | .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 }, |
| 159 | .os_tag = .windows, |
| 160 | .abi = .gnu, |
| 161 | }, |
| 162 | }) |query| { |
| 163 | const target = b.resolveTargetQuery(query); |
| 164 | const triple = query.zigTriple(b.allocator) catch @panic("OOM"); |
| 165 | const cpu = query.serializeCpuAlloc(b.allocator) catch @panic("OOM"); |
| 166 | for ([_][]const u8{ |
| 167 | "access.zig", |
| 168 | "binary.zig", |
| 169 | "cast.zig", |
| 170 | "unary.zig", |
| 171 | }) |path| { |
| 172 | const test_mod = b.createModule(.{ |
| 173 | .root_source_file = b.path(path), |
| 174 | .target = target, |
| 175 | .strip = strip, |
| 176 | }); |
| 177 | const test_exe = b.addTest(.{ |
| 178 | .name = std.fs.path.stem(path), |
| 179 | .filters = test_filters, |
| 180 | .use_llvm = false, |
| 181 | .use_lld = false, |
| 182 | .root_module = test_mod, |
| 183 | }); |
| 184 | test_exe.step.name = b.fmt("{s} {s}", .{ test_exe.step.name, cpu }); |
| 185 | if (!target.result.cpu.has(.x86, .sse2)) { |
| 186 | test_exe.bundle_compiler_rt = false; |
| 187 | test_mod.linkLibrary(compiler_rt_lib); |
| 188 | } |
| 189 | const test_run = b.addRunArtifact(test_exe); |
| 190 | test_run.step.name = b.fmt("{s} {s} {s}", .{ test_run.step.name, triple, cpu }); |
| 191 | b.default_step.dependOn(&test_run.step); |
| 192 | } |
| 193 | } |
| 194 | } |