diff options
| author | 2024-01-28 09:47:41 +0800 | |
|---|---|---|
| committer | 2024-01-28 09:47:41 +0800 | |
| commit | 6674066839ac268c91ac109f843f1277477908f5 (patch) | |
| tree | dbe42547f4f0cb76b8d3a3d86823f1c5ae7e9aea /build.zig | |
| parent | fix: keep up with zig master (diff) | |
| download | zig-sqlite-6674066839ac268c91ac109f843f1277477908f5.tar.gz zig-sqlite-6674066839ac268c91ac109f843f1277477908f5.tar.xz zig-sqlite-6674066839ac268c91ac109f843f1277477908f5.zip | |
refactor TestTarget
Diffstat (limited to '')
| -rw-r--r-- | build.zig | 73 |
1 files changed, 38 insertions, 35 deletions
| @@ -1,6 +1,8 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const Step = std.Build.Step; | 3 | const Step = std.Build.Step; |
| 4 | const ResolvedTarget = std.Build.ResolvedTarget; | ||
| 5 | const Query = std.Target.Query; | ||
| 4 | 6 | ||
| 5 | var sqlite3: ?*Step.Compile = null; | 7 | var sqlite3: ?*Step.Compile = null; |
| 6 | 8 | ||
| @@ -13,7 +15,7 @@ fn linkSqlite(b: *Step.Compile) void { | |||
| 13 | } | 15 | } |
| 14 | } | 16 | } |
| 15 | 17 | ||
| 16 | fn getTarget(original_target: std.Build.ResolvedTarget, bundled: bool) std.Build.ResolvedTarget { | 18 | fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { |
| 17 | if (bundled) { | 19 | if (bundled) { |
| 18 | var tmp = original_target; | 20 | var tmp = original_target; |
| 19 | 21 | ||
| @@ -36,7 +38,7 @@ fn getTarget(original_target: std.Build.ResolvedTarget, bundled: bool) std.Build | |||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | const TestTarget = struct { | 40 | const TestTarget = struct { |
| 39 | target: std.Build.ResolvedTarget, | 41 | query: Query, |
| 40 | single_threaded: bool = false, | 42 | single_threaded: bool = false, |
| 41 | bundled: bool, | 43 | bundled: bool, |
| 42 | }; | 44 | }; |
| @@ -46,18 +48,18 @@ const ci_targets = switch (builtin.target.cpu.arch) { | |||
| 46 | .linux => [_]TestTarget{ | 48 | .linux => [_]TestTarget{ |
| 47 | // Targets linux but other CPU archs. | 49 | // Targets linux but other CPU archs. |
| 48 | TestTarget{ | 50 | TestTarget{ |
| 49 | .target = .{}, | 51 | .query = .{}, |
| 50 | .bundled = false, | 52 | .bundled = false, |
| 51 | }, | 53 | }, |
| 52 | TestTarget{ | 54 | TestTarget{ |
| 53 | .target = .{ | 55 | .query = .{ |
| 54 | .cpu_arch = .x86_64, | 56 | .cpu_arch = .x86_64, |
| 55 | .abi = .musl, | 57 | .abi = .musl, |
| 56 | }, | 58 | }, |
| 57 | .bundled = true, | 59 | .bundled = true, |
| 58 | }, | 60 | }, |
| 59 | TestTarget{ | 61 | TestTarget{ |
| 60 | .target = .{ | 62 | .query = .{ |
| 61 | .cpu_arch = .x86, | 63 | .cpu_arch = .x86, |
| 62 | .abi = .musl, | 64 | .abi = .musl, |
| 63 | }, | 65 | }, |
| @@ -66,14 +68,14 @@ const ci_targets = switch (builtin.target.cpu.arch) { | |||
| 66 | }, | 68 | }, |
| 67 | .windows => [_]TestTarget{ | 69 | .windows => [_]TestTarget{ |
| 68 | TestTarget{ | 70 | TestTarget{ |
| 69 | .target = .{ | 71 | .query = .{ |
| 70 | .cpu_arch = .x86_64, | 72 | .cpu_arch = .x86_64, |
| 71 | .abi = .gnu, | 73 | .abi = .gnu, |
| 72 | }, | 74 | }, |
| 73 | .bundled = true, | 75 | .bundled = true, |
| 74 | }, | 76 | }, |
| 75 | TestTarget{ | 77 | TestTarget{ |
| 76 | .target = .{ | 78 | .query = .{ |
| 77 | .cpu_arch = .x86, | 79 | .cpu_arch = .x86, |
| 78 | .abi = .gnu, | 80 | .abi = .gnu, |
| 79 | }, | 81 | }, |
| @@ -82,14 +84,14 @@ const ci_targets = switch (builtin.target.cpu.arch) { | |||
| 82 | }, | 84 | }, |
| 83 | .macos => [_]TestTarget{ | 85 | .macos => [_]TestTarget{ |
| 84 | TestTarget{ | 86 | TestTarget{ |
| 85 | .target = .{ | 87 | .query = .{ |
| 86 | .cpu_arch = .x86_64, | 88 | .cpu_arch = .x86_64, |
| 87 | }, | 89 | }, |
| 88 | .bundled = true, | 90 | .bundled = true, |
| 89 | }, | 91 | }, |
| 90 | // TODO(vincent): this fails for some reason | 92 | // TODO(vincent): this fails for some reason |
| 91 | // TestTarget{ | 93 | // TestTarget{ |
| 92 | // .target = .{ | 94 | // .query =.{ |
| 93 | // .cpu_arch = .aarch64, | 95 | // .cpu_arch = .aarch64, |
| 94 | // }, | 96 | // }, |
| 95 | // .bundled = true, | 97 | // .bundled = true, |
| @@ -97,14 +99,14 @@ const ci_targets = switch (builtin.target.cpu.arch) { | |||
| 97 | }, | 99 | }, |
| 98 | else => [_]TestTarget{ | 100 | else => [_]TestTarget{ |
| 99 | TestTarget{ | 101 | TestTarget{ |
| 100 | .target = .{}, | 102 | .query = .{}, |
| 101 | .bundled = false, | 103 | .bundled = false, |
| 102 | }, | 104 | }, |
| 103 | }, | 105 | }, |
| 104 | }, | 106 | }, |
| 105 | else => [_]TestTarget{ | 107 | else => [_]TestTarget{ |
| 106 | TestTarget{ | 108 | TestTarget{ |
| 107 | .target = .{ .query = .{}, .result = comptime std.zig.system.resolveTargetQuery(.{}) catch @panic("") }, | 109 | .query = .{}, |
| 108 | .bundled = false, | 110 | .bundled = false, |
| 109 | }, | 111 | }, |
| 110 | }, | 112 | }, |
| @@ -115,39 +117,39 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 115 | .linux => [_]TestTarget{ | 117 | .linux => [_]TestTarget{ |
| 116 | // Targets linux but other CPU archs. | 118 | // Targets linux but other CPU archs. |
| 117 | TestTarget{ | 119 | TestTarget{ |
| 118 | .target = .{}, | 120 | .query = .{}, |
| 119 | .bundled = false, | 121 | .bundled = false, |
| 120 | }, | 122 | }, |
| 121 | TestTarget{ | 123 | TestTarget{ |
| 122 | .target = .{ | 124 | .query = .{ |
| 123 | .cpu_arch = .x86_64, | 125 | .cpu_arch = .x86_64, |
| 124 | .abi = .musl, | 126 | .abi = .musl, |
| 125 | }, | 127 | }, |
| 126 | .bundled = true, | 128 | .bundled = true, |
| 127 | }, | 129 | }, |
| 128 | TestTarget{ | 130 | TestTarget{ |
| 129 | .target = .{ | 131 | .query = .{ |
| 130 | .cpu_arch = .x86, | 132 | .cpu_arch = .x86, |
| 131 | .abi = .musl, | 133 | .abi = .musl, |
| 132 | }, | 134 | }, |
| 133 | .bundled = true, | 135 | .bundled = true, |
| 134 | }, | 136 | }, |
| 135 | TestTarget{ | 137 | TestTarget{ |
| 136 | .target = .{ | 138 | .query = .{ |
| 137 | .cpu_arch = .aarch64, | 139 | .cpu_arch = .aarch64, |
| 138 | .abi = .musl, | 140 | .abi = .musl, |
| 139 | }, | 141 | }, |
| 140 | .bundled = true, | 142 | .bundled = true, |
| 141 | }, | 143 | }, |
| 142 | TestTarget{ | 144 | TestTarget{ |
| 143 | .target = .{ | 145 | .query = .{ |
| 144 | .cpu_arch = .riscv64, | 146 | .cpu_arch = .riscv64, |
| 145 | .abi = .musl, | 147 | .abi = .musl, |
| 146 | }, | 148 | }, |
| 147 | .bundled = true, | 149 | .bundled = true, |
| 148 | }, | 150 | }, |
| 149 | TestTarget{ | 151 | TestTarget{ |
| 150 | .target = .{ | 152 | .query = .{ |
| 151 | .cpu_arch = .mips, | 153 | .cpu_arch = .mips, |
| 152 | .abi = .musl, | 154 | .abi = .musl, |
| 153 | }, | 155 | }, |
| @@ -155,7 +157,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 155 | }, | 157 | }, |
| 156 | // TODO(vincent): failing for some time for unknown reasons | 158 | // TODO(vincent): failing for some time for unknown reasons |
| 157 | // TestTarget{ | 159 | // TestTarget{ |
| 158 | // .target = .{ | 160 | // .query =.{ |
| 159 | // .cpu_arch = .arm, | 161 | // .cpu_arch = .arm, |
| 160 | // .abi = .musleabihf, | 162 | // .abi = .musleabihf, |
| 161 | // }, | 163 | // }, |
| @@ -163,14 +165,14 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 163 | // }, | 165 | // }, |
| 164 | // Targets windows | 166 | // Targets windows |
| 165 | TestTarget{ | 167 | TestTarget{ |
| 166 | .target = .{ | 168 | .query = .{ |
| 167 | .cpu_arch = .x86_64, | 169 | .cpu_arch = .x86_64, |
| 168 | .os_tag = .windows, | 170 | .os_tag = .windows, |
| 169 | }, | 171 | }, |
| 170 | .bundled = true, | 172 | .bundled = true, |
| 171 | }, | 173 | }, |
| 172 | TestTarget{ | 174 | TestTarget{ |
| 173 | .target = .{ | 175 | .query = .{ |
| 174 | .cpu_arch = .x86, | 176 | .cpu_arch = .x86, |
| 175 | .os_tag = .windows, | 177 | .os_tag = .windows, |
| 176 | }, | 178 | }, |
| @@ -178,14 +180,14 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 178 | }, | 180 | }, |
| 179 | // Targets macOS | 181 | // Targets macOS |
| 180 | TestTarget{ | 182 | TestTarget{ |
| 181 | .target = .{ | 183 | .query = .{ |
| 182 | .cpu_arch = .x86_64, | 184 | .cpu_arch = .x86_64, |
| 183 | .os_tag = .macos, | 185 | .os_tag = .macos, |
| 184 | }, | 186 | }, |
| 185 | .bundled = true, | 187 | .bundled = true, |
| 186 | }, | 188 | }, |
| 187 | TestTarget{ | 189 | TestTarget{ |
| 188 | .target = .{ | 190 | .query = .{ |
| 189 | .cpu_arch = .aarch64, | 191 | .cpu_arch = .aarch64, |
| 190 | .os_tag = .macos, | 192 | .os_tag = .macos, |
| 191 | }, | 193 | }, |
| @@ -194,14 +196,14 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 194 | }, | 196 | }, |
| 195 | .windows => [_]TestTarget{ | 197 | .windows => [_]TestTarget{ |
| 196 | TestTarget{ | 198 | TestTarget{ |
| 197 | .target = .{ | 199 | .query = .{ |
| 198 | .cpu_arch = .x86_64, | 200 | .cpu_arch = .x86_64, |
| 199 | .abi = .gnu, | 201 | .abi = .gnu, |
| 200 | }, | 202 | }, |
| 201 | .bundled = true, | 203 | .bundled = true, |
| 202 | }, | 204 | }, |
| 203 | TestTarget{ | 205 | TestTarget{ |
| 204 | .target = .{ | 206 | .query = .{ |
| 205 | .cpu_arch = .x86, | 207 | .cpu_arch = .x86, |
| 206 | .abi = .gnu, | 208 | .abi = .gnu, |
| 207 | }, | 209 | }, |
| @@ -210,11 +212,11 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 210 | }, | 212 | }, |
| 211 | .freebsd => [_]TestTarget{ | 213 | .freebsd => [_]TestTarget{ |
| 212 | TestTarget{ | 214 | TestTarget{ |
| 213 | .target = .{}, | 215 | .query = .{}, |
| 214 | .bundled = false, | 216 | .bundled = false, |
| 215 | }, | 217 | }, |
| 216 | TestTarget{ | 218 | TestTarget{ |
| 217 | .target = .{ | 219 | .query = .{ |
| 218 | .cpu_arch = .x86_64, | 220 | .cpu_arch = .x86_64, |
| 219 | }, | 221 | }, |
| 220 | .bundled = true, | 222 | .bundled = true, |
| @@ -222,7 +224,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 222 | }, | 224 | }, |
| 223 | .macos => [_]TestTarget{ | 225 | .macos => [_]TestTarget{ |
| 224 | TestTarget{ | 226 | TestTarget{ |
| 225 | .target = .{ | 227 | .query = .{ |
| 226 | .cpu_arch = .x86_64, | 228 | .cpu_arch = .x86_64, |
| 227 | }, | 229 | }, |
| 228 | .bundled = true, | 230 | .bundled = true, |
| @@ -230,23 +232,23 @@ const all_test_targets = switch (builtin.target.cpu.arch) { | |||
| 230 | }, | 232 | }, |
| 231 | else => [_]TestTarget{ | 233 | else => [_]TestTarget{ |
| 232 | TestTarget{ | 234 | TestTarget{ |
| 233 | .target = .{}, | 235 | .query = .{}, |
| 234 | .bundled = false, | 236 | .bundled = false, |
| 235 | }, | 237 | }, |
| 236 | }, | 238 | }, |
| 237 | }, | 239 | }, |
| 238 | else => [_]TestTarget{ | 240 | else => [_]TestTarget{ |
| 239 | TestTarget{ | 241 | TestTarget{ |
| 240 | .target = .{}, | 242 | .query = .{}, |
| 241 | .bundled = false, | 243 | .bundled = false, |
| 242 | }, | 244 | }, |
| 243 | }, | 245 | }, |
| 244 | }; | 246 | }; |
| 245 | 247 | ||
| 246 | fn computeTestTargets(target: std.Build.ResolvedTarget, ci: ?bool) ?[]const TestTarget { | 248 | fn computeTestTargets(isNative: bool, ci: ?bool) ?[]const TestTarget { |
| 247 | if (ci != null and ci.?) return &ci_targets; | 249 | if (ci != null and ci.?) return &ci_targets; |
| 248 | 250 | ||
| 249 | if (target.isNative()) { | 251 | if (isNative) { |
| 250 | // If the target is native we assume the user didn't change it with -Dtarget and run all test targets. | 252 | // If the target is native we assume the user didn't change it with -Dtarget and run all test targets. |
| 251 | return &all_test_targets; | 253 | return &all_test_targets; |
| 252 | } | 254 | } |
| @@ -261,7 +263,8 @@ pub fn build(b: *std.Build) !void { | |||
| 261 | const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); | 263 | const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); |
| 262 | const ci = b.option(bool, "ci", "Build and test in the CI on GitHub"); | 264 | const ci = b.option(bool, "ci", "Build and test in the CI on GitHub"); |
| 263 | 265 | ||
| 264 | const target = b.standardTargetOptions(.{}); | 266 | const query = b.standardTargetOptionsQueryOnly(.{}); |
| 267 | const target = b.resolveTargetQuery(query); | ||
| 265 | const optimize = b.standardOptimizeOption(.{}); | 268 | const optimize = b.standardOptimizeOption(.{}); |
| 266 | 269 | ||
| 267 | _ = b.addModule("sqlite", .{ .root_source_file = .{ .path = "sqlite.zig" } }); | 270 | _ = b.addModule("sqlite", .{ .root_source_file = .{ .path = "sqlite.zig" } }); |
| @@ -300,8 +303,8 @@ pub fn build(b: *std.Build) !void { | |||
| 300 | const preprocess_files_tool_run = b.addRunArtifact(preprocess_files_tool); | 303 | const preprocess_files_tool_run = b.addRunArtifact(preprocess_files_tool); |
| 301 | preprocess_files_run.dependOn(&preprocess_files_tool_run.step); | 304 | preprocess_files_run.dependOn(&preprocess_files_tool_run.step); |
| 302 | 305 | ||
| 303 | const test_targets = computeTestTargets(target, ci) orelse &[_]TestTarget{.{ | 306 | const test_targets = computeTestTargets(query.isNative(), ci) orelse &[_]TestTarget{.{ |
| 304 | .target = target, | 307 | .query = query, |
| 305 | .bundled = use_bundled orelse false, | 308 | .bundled = use_bundled orelse false, |
| 306 | }}; | 309 | }}; |
| 307 | const test_step = b.step("test", "Run library tests"); | 310 | const test_step = b.step("test", "Run library tests"); |
| @@ -313,7 +316,7 @@ pub fn build(b: *std.Build) !void { | |||
| 313 | 316 | ||
| 314 | for (test_targets) |test_target| { | 317 | for (test_targets) |test_target| { |
| 315 | const bundled = use_bundled orelse test_target.bundled; | 318 | const bundled = use_bundled orelse test_target.bundled; |
| 316 | const cross_target = getTarget(test_target.target, bundled); | 319 | const cross_target = getTarget(b.resolveTargetQuery(test_target.query), bundled); |
| 317 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; | 320 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; |
| 318 | const test_name = b.fmt("{s}-{s}-{s}", .{ | 321 | const test_name = b.fmt("{s}-{s}-{s}", .{ |
| 319 | try cross_target.result.zigTriple(b.allocator), | 322 | try cross_target.result.zigTriple(b.allocator), |