summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2024-12-08 14:49:48 +0100
committerGravatar GitHub2024-12-08 14:49:48 +0100
commit3983d9c9c5193619a1a0ad4a9e334e8e43bb520e (patch)
treee16b9f6cb7aea9baf0678c0b53bb4fbc1bd99aec
parentMerge branch 'improve-readme' (diff)
parentbuild: always use the bundled sqlite source (diff)
downloadzig-sqlite-3983d9c9c5193619a1a0ad4a9e334e8e43bb520e.tar.gz
zig-sqlite-3983d9c9c5193619a1a0ad4a9e334e8e43bb520e.tar.xz
zig-sqlite-3983d9c9c5193619a1a0ad4a9e334e8e43bb520e.zip
Merge pull request #171 from vrischmann/always-use-bundled
always use the bundled sqlite source
-rw-r--r--build.zig52
1 files changed, 20 insertions, 32 deletions
diff --git a/build.zig b/build.zig
index 3b990ff..159fb6d 100644
--- a/build.zig
+++ b/build.zig
@@ -4,26 +4,22 @@ const Step = std.Build.Step;
4const ResolvedTarget = std.Build.ResolvedTarget; 4const ResolvedTarget = std.Build.ResolvedTarget;
5const Query = std.Target.Query; 5const Query = std.Target.Query;
6 6
7fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { 7fn getTarget(original_target: ResolvedTarget) ResolvedTarget {
8 if (bundled) { 8 var tmp = original_target;
9 var tmp = original_target; 9
10 10 if (tmp.result.isGnuLibC()) {
11 if (tmp.result.isGnuLibC()) { 11 const min_glibc_version = std.SemanticVersion{
12 const min_glibc_version = std.SemanticVersion{ 12 .major = 2,
13 .major = 2, 13 .minor = 28,
14 .minor = 28, 14 .patch = 0,
15 .patch = 0, 15 };
16 }; 16 const ver = tmp.result.os.version_range.linux.glibc;
17 const ver = tmp.result.os.version_range.linux.glibc; 17 if (ver.order(min_glibc_version) == .lt) {
18 if (ver.order(min_glibc_version) == .lt) { 18 std.debug.panic("sqlite requires glibc version >= 2.28", .{});
19 std.debug.panic("sqlite requires glibc version >= 2.28", .{});
20 }
21 } 19 }
22
23 return tmp;
24 } 20 }
25 21
26 return original_target; 22 return tmp;
27} 23}
28 24
29const TestTarget = struct { 25const TestTarget = struct {
@@ -111,7 +107,6 @@ fn computeTestTargets(isNative: bool, ci: ?bool) ?[]const TestTarget {
111pub fn build(b: *std.Build) !void { 107pub fn build(b: *std.Build) !void {
112 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true; 108 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true;
113 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one"); 109 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one");
114 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)");
115 const ci = b.option(bool, "ci", "Build and test in the CI on GitHub"); 110 const ci = b.option(bool, "ci", "Build and test in the CI on GitHub");
116 111
117 const query = b.standardTargetOptionsQueryOnly(.{}); 112 const query = b.standardTargetOptionsQueryOnly(.{});
@@ -171,7 +166,7 @@ pub fn build(b: *std.Build) !void {
171 const preprocess_files_tool = b.addExecutable(.{ 166 const preprocess_files_tool = b.addExecutable(.{
172 .name = "preprocess-files", 167 .name = "preprocess-files",
173 .root_source_file = b.path("tools/preprocess_files.zig"), 168 .root_source_file = b.path("tools/preprocess_files.zig"),
174 .target = getTarget(target, true), 169 .target = getTarget(target),
175 .optimize = optimize, 170 .optimize = optimize,
176 }); 171 });
177 172
@@ -183,7 +178,7 @@ pub fn build(b: *std.Build) !void {
183 178
184 const test_targets = computeTestTargets(query.isNative(), ci) orelse &[_]TestTarget{.{ 179 const test_targets = computeTestTargets(query.isNative(), ci) orelse &[_]TestTarget{.{
185 .query = query, 180 .query = query,
186 .bundled = use_bundled orelse false, 181 .bundled = true,
187 }}; 182 }};
188 const test_step = b.step("test", "Run library tests"); 183 const test_step = b.step("test", "Run library tests");
189 184
@@ -193,8 +188,7 @@ pub fn build(b: *std.Build) !void {
193 // If you want to execute tests for other targets you can pass -fqemu, -fdarling, -fwine, -frosetta. 188 // If you want to execute tests for other targets you can pass -fqemu, -fdarling, -fwine, -frosetta.
194 189
195 for (test_targets) |test_target| { 190 for (test_targets) |test_target| {
196 const bundled = use_bundled orelse test_target.bundled; 191 const cross_target = getTarget(b.resolveTargetQuery(test_target.query));
197 const cross_target = getTarget(b.resolveTargetQuery(test_target.query), bundled);
198 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; 192 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
199 const test_name = b.fmt("{s}-{s}-{s}", .{ 193 const test_name = b.fmt("{s}-{s}-{s}", .{
200 try cross_target.result.zigTriple(b.allocator), 194 try cross_target.result.zigTriple(b.allocator),
@@ -224,13 +218,7 @@ pub fn build(b: *std.Build) !void {
224 .single_threaded = test_target.single_threaded, 218 .single_threaded = test_target.single_threaded,
225 }); 219 });
226 tests.addIncludePath(b.path("c")); 220 tests.addIncludePath(b.path("c"));
227 if (bundled) { 221 tests.linkLibrary(test_sqlite_lib);
228 tests.linkLibrary(test_sqlite_lib);
229 } else {
230 tests.linkLibC();
231 tests.addCSourceFile(.{ .file = b.path("c/workaround.c"), .flags = c_flags });
232 tests.linkSystemLibrary("sqlite3");
233 }
234 222
235 const tests_options = b.addOptions(); 223 const tests_options = b.addOptions();
236 tests.root_module.addImport("build_options", tests_options.createModule()); 224 tests.root_module.addImport("build_options", tests_options.createModule());
@@ -244,7 +232,7 @@ pub fn build(b: *std.Build) !void {
244 232
245 const lib = b.addStaticLibrary(.{ 233 const lib = b.addStaticLibrary(.{
246 .name = "sqlite", 234 .name = "sqlite",
247 .target = getTarget(target, true), 235 .target = getTarget(target),
248 .optimize = optimize, 236 .optimize = optimize,
249 }); 237 });
250 lib.addCSourceFile(.{ .file = b.path("c/sqlite3.c"), .flags = c_flags }); 238 lib.addCSourceFile(.{ .file = b.path("c/sqlite3.c"), .flags = c_flags });
@@ -263,7 +251,7 @@ pub fn build(b: *std.Build) !void {
263 .name = "zigcrypto", 251 .name = "zigcrypto",
264 .root_source_file = b.path("examples/zigcrypto.zig"), 252 .root_source_file = b.path("examples/zigcrypto.zig"),
265 .version = null, 253 .version = null,
266 .target = getTarget(target, true), 254 .target = getTarget(target),
267 .optimize = optimize, 255 .optimize = optimize,
268 }); 256 });
269 zigcrypto_loadable_ext.addIncludePath(b.path("c")); 257 zigcrypto_loadable_ext.addIncludePath(b.path("c"));
@@ -275,7 +263,7 @@ pub fn build(b: *std.Build) !void {
275 const zigcrypto_test = b.addExecutable(.{ 263 const zigcrypto_test = b.addExecutable(.{
276 .name = "zigcrypto-test", 264 .name = "zigcrypto-test",
277 .root_source_file = b.path("examples/zigcrypto_test.zig"), 265 .root_source_file = b.path("examples/zigcrypto_test.zig"),
278 .target = getTarget(target, true), 266 .target = getTarget(target),
279 .optimize = optimize, 267 .optimize = optimize,
280 }); 268 });
281 zigcrypto_test.addIncludePath(b.path("c")); 269 zigcrypto_test.addIncludePath(b.path("c"));