summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.builds/alpine-edge-amd64.yml8
-rw-r--r--.builds/debian-stable-amd64.yml4
-rw-r--r--.builds/freebsd-latest-amd64.yml8
-rw-r--r--.github/workflows/main.yml6
-rw-r--r--build.zig178
5 files changed, 150 insertions, 54 deletions
diff --git a/.builds/alpine-edge-amd64.yml b/.builds/alpine-edge-amd64.yml
index 0869f6d..93595a7 100644
--- a/.builds/alpine-edge-amd64.yml
+++ b/.builds/alpine-edge-amd64.yml
@@ -25,11 +25,3 @@ tasks:
25 - test_filesystem: | 25 - test_filesystem: |
26 cd zig-sqlite 26 cd zig-sqlite
27 TERM=dumb zig build test -Din_memory=false 27 TERM=dumb zig build test -Din_memory=false
28
29 - test_in_memory_with_bundled_library: |
30 cd zig-sqlite
31 TERM=dumb zig build test -Din_memory=true -Duse_bundled
32
33 - test_filesystem_with_bundled_library: |
34 cd zig-sqlite
35 TERM=dumb zig build test -Din_memory=false -Duse_bundled
diff --git a/.builds/debian-stable-amd64.yml b/.builds/debian-stable-amd64.yml
index 813f8e3..7fc831c 100644
--- a/.builds/debian-stable-amd64.yml
+++ b/.builds/debian-stable-amd64.yml
@@ -24,7 +24,3 @@ tasks:
24 - test_filesystem: | 24 - test_filesystem: |
25 cd zig-sqlite 25 cd zig-sqlite
26 TERM=dumb zig build test -Din_memory=false 26 TERM=dumb zig build test -Din_memory=false
27
28 - test_with_bundled_library: |
29 cd zig-sqlite
30 TERM=dumb zig build test -Din_memory -Duse_bundled
diff --git a/.builds/freebsd-latest-amd64.yml b/.builds/freebsd-latest-amd64.yml
index a380814..f8c4202 100644
--- a/.builds/freebsd-latest-amd64.yml
+++ b/.builds/freebsd-latest-amd64.yml
@@ -24,11 +24,3 @@ tasks:
24 - test_filesystem: | 24 - test_filesystem: |
25 cd zig-sqlite 25 cd zig-sqlite
26 TERM=dumb zig build test -Din_memory=false 26 TERM=dumb zig build test -Din_memory=false
27
28 - test_in_memory_with_bundled_library: |
29 cd zig-sqlite
30 TERM=dumb zig build test -Din_memory=true -Duse_bundled
31
32 - test_filesystem_with_bundled_library: |
33 cd zig-sqlite
34 TERM=dumb zig build test -Din_memory=false -Duse_bundled
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 5b3bf4d..a7cc6e0 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -39,9 +39,6 @@ jobs:
39 - name: Run Tests in memory 39 - name: Run Tests in memory
40 run: zig build test -Din_memory=true 40 run: zig build test -Din_memory=true
41 41
42 - name: Run Tests in memory using the bundled SQLite
43 run: zig build test -Din_memory=true -Duse_bundled
44
45 test-with-filesystem: 42 test-with-filesystem:
46 strategy: 43 strategy:
47 matrix: 44 matrix:
@@ -57,6 +54,3 @@ jobs:
57 54
58 - name: Run Tests with filesystem 55 - name: Run Tests with filesystem
59 run: zig build test -Din_memory=false 56 run: zig build test -Din_memory=false
60
61 - name: Run Tests with filesystem using the bundled SQLite
62 run: zig build test -Din_memory=false -Duse_bundled
diff --git a/build.zig b/build.zig
index 2d6a8dc..2f294fb 100644
--- a/build.zig
+++ b/build.zig
@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
1const std = @import("std"); 2const std = @import("std");
2 3
3var sqlite3: ?*std.build.LibExeObjStep = null; 4var sqlite3: ?*std.build.LibExeObjStep = null;
@@ -37,40 +38,161 @@ fn getTarget(original_target: std.zig.CrossTarget, bundled: bool) std.zig.CrossT
37 return original_target; 38 return original_target;
38} 39}
39 40
41const TestTarget = struct {
42 target: std.zig.CrossTarget = @as(std.zig.CrossTarget, .{}),
43 mode: builtin.Mode = .Debug,
44 single_threaded: bool = false,
45 bundled: bool,
46};
47
48const all_test_targets = switch (std.Target.current.cpu.arch) {
49 .x86_64 => switch (std.Target.current.os.tag) {
50 .linux => [_]TestTarget{
51 TestTarget{
52 .target = .{},
53 .bundled = false,
54 },
55 TestTarget{
56 .target = .{
57 .cpu_arch = .x86_64,
58 .abi = .musl,
59 },
60 .bundled = true,
61 },
62 TestTarget{
63 .target = .{
64 .cpu_arch = .i386,
65 .abi = .musl,
66 },
67 .bundled = true,
68 },
69 TestTarget{
70 .target = .{
71 .cpu_arch = .aarch64,
72 .abi = .musl,
73 },
74 .bundled = true,
75 },
76 TestTarget{
77 .target = .{
78 .cpu_arch = .riscv64,
79 .abi = .musl,
80 },
81 .bundled = true,
82 },
83 TestTarget{
84 .target = .{
85 .cpu_arch = .mips,
86 .abi = .musl,
87 },
88 .bundled = true,
89 },
90 TestTarget{
91 .target = .{
92 .cpu_arch = .arm,
93 .abi = .musleabihf,
94 },
95 .bundled = true,
96 },
97 },
98 .windows => [_]TestTarget{
99 TestTarget{
100 .target = .{},
101 .bundled = false,
102 },
103 TestTarget{
104 .target = .{
105 .cpu_arch = .x86_64,
106 },
107 .bundled = true,
108 },
109 TestTarget{
110 .target = .{
111 .cpu_arch = .i386,
112 },
113 .bundled = true,
114 },
115 },
116 .freebsd => [_]TestTarget{
117 TestTarget{
118 .target = .{},
119 .bundled = false,
120 },
121 TestTarget{
122 .target = .{
123 .cpu_arch = .x86_64,
124 },
125 .bundled = true,
126 },
127 },
128 else => [_]TestTarget{
129 TestTarget{
130 .target = .{},
131 .bundled = false,
132 },
133 },
134 },
135 else => [_]TestTarget{
136 TestTarget{
137 .target = .{},
138 .bundled = false,
139 },
140 },
141};
142
40pub fn build(b: *std.build.Builder) void { 143pub fn build(b: *std.build.Builder) void {
41 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true; 144 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true;
42 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one"); 145 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one");
43 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)") orelse false; 146 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)") orelse false;
147 const enable_qemu = b.option(bool, "enable_qemu", "Enable qemu for running tests (default false)") orelse false;
44 148
45 const target = getTarget(b.standardTargetOptions(.{}), use_bundled); 149 const target = b.standardTargetOptions(.{});
46 const mode = b.standardReleaseOptions();
47
48 // Build sqlite from source if asked
49 if (use_bundled) {
50 const lib = b.addStaticLibrary("sqlite", null);
51 lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"});
52 lib.linkLibC();
53 lib.setTarget(target);
54 lib.setBuildMode(mode);
55 sqlite3 = lib;
56 }
57 150
58 const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig"); 151 const test_targets = if (target.isNative())
59 lib.addIncludeDir("c"); 152 &all_test_targets
60 linkSqlite(lib); 153 else
61 lib.setTarget(target); 154 &[_]TestTarget{.{
62 lib.setBuildMode(mode); 155 .target = target,
63 lib.install(); 156 .bundled = use_bundled,
64 157 }};
65 var main_tests = b.addTest("sqlite.zig");
66 main_tests.addIncludeDir("c");
67 linkSqlite(main_tests);
68 main_tests.setBuildMode(mode);
69 main_tests.setTarget(target);
70 main_tests.setBuildMode(mode);
71 main_tests.addBuildOption(bool, "in_memory", in_memory);
72 main_tests.addBuildOption(?[]const u8, "dbfile", dbfile);
73 158
74 const test_step = b.step("test", "Run library tests"); 159 const test_step = b.step("test", "Run library tests");
75 test_step.dependOn(&main_tests.step); 160 for (test_targets) |test_target| {
161 const cross_target = getTarget(test_target.target, test_target.bundled);
162
163 const tests = b.addTest("sqlite.zig");
164
165 if (test_target.bundled) {
166 const lib = b.addStaticLibrary("sqlite", null);
167 lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"});
168 lib.linkLibC();
169 lib.setTarget(cross_target);
170 lib.setBuildMode(test_target.mode);
171 sqlite3 = lib;
172 }
173
174 const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig");
175 lib.addIncludeDir("c");
176 linkSqlite(lib);
177 lib.setTarget(cross_target);
178 lib.setBuildMode(test_target.mode);
179
180 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
181 tests.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{
182 cross_target.zigTriple(b.allocator),
183 @tagName(test_target.mode),
184 single_threaded_txt,
185 }));
186 tests.single_threaded = test_target.single_threaded;
187 tests.setBuildMode(test_target.mode);
188 tests.setTarget(cross_target);
189 tests.addIncludeDir("c");
190 linkSqlite(tests);
191 tests.enable_qemu = enable_qemu;
192
193 tests.addBuildOption(bool, "in_memory", in_memory);
194 tests.addBuildOption(?[]const u8, "dbfile", dbfile);
195
196 test_step.dependOn(&tests.step);
197 }
76} 198}