summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig86
1 files changed, 76 insertions, 10 deletions
diff --git a/build.zig b/build.zig
index 8083ded..3b78513 100644
--- a/build.zig
+++ b/build.zig
@@ -43,6 +43,65 @@ const TestTarget = struct {
43 bundled: bool, 43 bundled: bool,
44}; 44};
45 45
46const ci_targets = switch (builtin.target.cpu.arch) {
47 .x86_64 => switch (builtin.target.os.tag) {
48 .linux => [_]TestTarget{
49 // Targets linux but other CPU archs.
50 TestTarget{
51 .target = .{},
52 .bundled = false,
53 },
54 TestTarget{
55 .target = .{
56 .cpu_arch = .x86_64,
57 .abi = .musl,
58 },
59 .bundled = true,
60 },
61 TestTarget{
62 .target = .{
63 .cpu_arch = .x86,
64 .abi = .musl,
65 },
66 .bundled = true,
67 },
68 },
69 .windows => [_]TestTarget{
70 TestTarget{
71 .target = .{
72 .cpu_arch = .x86_64,
73 .abi = .gnu,
74 },
75 .bundled = true,
76 },
77 TestTarget{
78 .target = .{
79 .cpu_arch = .x86,
80 .abi = .gnu,
81 },
82 .bundled = true,
83 },
84 },
85 .macos => [_]TestTarget{
86 TestTarget{
87 .target = .{
88 .cpu_arch = .x86_64,
89 },
90 .bundled = true,
91 },
92 // TODO(vincent): this fails for some reason
93 // TestTarget{
94 // .target = .{
95 // .cpu_arch = .aarch64,
96 // },
97 // .bundled = true,
98 // },
99 },
100 else => unreachable,
101 },
102 else => unreachable,
103};
104
46const all_test_targets = switch (builtin.target.cpu.arch) { 105const all_test_targets = switch (builtin.target.cpu.arch) {
47 .x86_64 => switch (builtin.target.os.tag) { 106 .x86_64 => switch (builtin.target.os.tag) {
48 .linux => [_]TestTarget{ 107 .linux => [_]TestTarget{
@@ -176,10 +235,26 @@ const all_test_targets = switch (builtin.target.cpu.arch) {
176 }, 235 },
177}; 236};
178 237
238fn computeTestTargets(target: std.zig.CrossTarget, ci: ?bool, use_bundled: ?bool) []const TestTarget {
239 if (ci != null and ci.?) return &ci_targets;
240
241 if (target.isNative()) {
242 // If the target is native we assume the user didn't change it with -Dtarget and run all test targets.
243 return &all_test_targets;
244 }
245
246 // Otherwise we run a single test target.
247 return &[_]TestTarget{.{
248 .target = target,
249 .bundled = use_bundled orelse false,
250 }};
251}
252
179pub fn build(b: *std.Build) !void { 253pub fn build(b: *std.Build) !void {
180 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true; 254 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true;
181 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one"); 255 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one");
182 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); 256 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)");
257 const ci = b.option(bool, "ci", "Build and test in the CI on GitHub");
183 258
184 const target = b.standardTargetOptions(.{}); 259 const target = b.standardTargetOptions(.{});
185 const optimize = b.standardOptimizeOption(.{}); 260 const optimize = b.standardOptimizeOption(.{});
@@ -220,16 +295,7 @@ pub fn build(b: *std.Build) !void {
220 const preprocess_files_tool_run = b.addRunArtifact(preprocess_files_tool); 295 const preprocess_files_tool_run = b.addRunArtifact(preprocess_files_tool);
221 preprocess_files_run.dependOn(&preprocess_files_tool_run.step); 296 preprocess_files_run.dependOn(&preprocess_files_tool_run.step);
222 297
223 // If the target is native we assume the user didn't change it with -Dtarget and run all test targets. 298 const test_targets = computeTestTargets(target, ci, use_bundled);
224 // Otherwise we run a single test target.
225 const test_targets = if (target.isNative())
226 &all_test_targets
227 else
228 &[_]TestTarget{.{
229 .target = target,
230 .bundled = use_bundled orelse false,
231 }};
232
233 const test_step = b.step("test", "Run library tests"); 299 const test_step = b.step("test", "Run library tests");
234 300
235 // By default the tests will only be execute for native test targets, however they will be compiled 301 // By default the tests will only be execute for native test targets, however they will be compiled