summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2024-04-14 20:10:41 +0200
committerGravatar Vincent Rischmann2024-04-14 20:10:49 +0200
commit947b4ade92e6a0919aa4a7b845ec674082e7dc51 (patch)
tree7d6b97fa2eac9ecc89ebb25963733e33220f4132 /build.zig
parentall: use our workaround function for SQLITE_TRANSIENT (diff)
downloadzig-sqlite-947b4ade92e6a0919aa4a7b845ec674082e7dc51.tar.gz
zig-sqlite-947b4ade92e6a0919aa4a7b845ec674082e7dc51.tar.xz
zig-sqlite-947b4ade92e6a0919aa4a7b845ec674082e7dc51.zip
build: rework and fix the CI tests
* stop having a global sqlite3 compile step variable * remove the test_lib which doesn't do anything
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig61
1 files changed, 21 insertions, 40 deletions
diff --git a/build.zig b/build.zig
index 9beb65d..460df86 100644
--- a/build.zig
+++ b/build.zig
@@ -4,17 +4,6 @@ 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
7var sqlite3: ?*Step.Compile = null;
8
9fn linkSqlite(b: *Step.Compile) void {
10 if (sqlite3) |lib| {
11 b.linkLibrary(lib);
12 } else {
13 b.linkLibC();
14 b.linkSystemLibrary("sqlite3");
15 }
16}
17
18fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { 7fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget {
19 if (bundled) { 8 if (bundled) {
20 var tmp = original_target; 9 var tmp = original_target;
@@ -335,6 +324,20 @@ pub fn build(b: *std.Build) !void {
335 single_threaded_txt, 324 single_threaded_txt,
336 }); 325 });
337 326
327 const test_sqlite_lib = b.addStaticLibrary(.{
328 .name = "sqlite",
329 .target = cross_target,
330 .optimize = optimize,
331 });
332 test_sqlite_lib.addCSourceFiles(.{
333 .files = &[_][]const u8{
334 "c/sqlite3.c",
335 "c/workaround.c",
336 },
337 .flags = c_flags,
338 });
339 test_sqlite_lib.linkLibC();
340
338 const tests = b.addTest(.{ 341 const tests = b.addTest(.{
339 .name = test_name, 342 .name = test_name,
340 .target = cross_target, 343 .target = cross_target,
@@ -342,44 +345,22 @@ pub fn build(b: *std.Build) !void {
342 .root_source_file = .{ .path = "sqlite.zig" }, 345 .root_source_file = .{ .path = "sqlite.zig" },
343 .single_threaded = test_target.single_threaded, 346 .single_threaded = test_target.single_threaded,
344 }); 347 });
345 const run_tests = b.addRunArtifact(tests); 348 tests.addIncludePath(.{ .path = "c" });
346
347 if (bundled) { 349 if (bundled) {
348 const lib = b.addStaticLibrary(.{ 350 tests.linkLibrary(test_sqlite_lib);
349 .name = "sqlite", 351 } else {
350 .target = cross_target, 352 tests.linkLibC();
351 .optimize = optimize, 353 tests.addCSourceFile(.{ .file = .{ .path = "c/workaround.c" }, .flags = c_flags });
352 }); 354 tests.linkSystemLibrary("sqlite3");
353 lib.addCSourceFiles(.{
354 .files = &[_][]const u8{
355 "c/sqlite3.c",
356 "c/workaround.c",
357 },
358 .flags = c_flags,
359 });
360 lib.linkLibC();
361 sqlite3 = lib;
362 } 355 }
363 356
364 if (bundled) tests.addIncludePath(.{ .path = "c" });
365 linkSqlite(tests);
366
367 const lib = b.addStaticLibrary(.{
368 .name = "zig-sqlite",
369 .root_source_file = .{ .path = "sqlite.zig" },
370 .target = cross_target,
371 .optimize = optimize,
372 });
373 lib.addCSourceFile(.{ .file = .{ .path = "c/workaround.c" }, .flags = c_flags });
374 if (bundled) lib.addIncludePath(.{ .path = "c" });
375 linkSqlite(lib);
376
377 const tests_options = b.addOptions(); 357 const tests_options = b.addOptions();
378 tests.root_module.addImport("build_options", tests_options.createModule()); 358 tests.root_module.addImport("build_options", tests_options.createModule());
379 359
380 tests_options.addOption(bool, "in_memory", in_memory); 360 tests_options.addOption(bool, "in_memory", in_memory);
381 tests_options.addOption(?[]const u8, "dbfile", dbfile); 361 tests_options.addOption(?[]const u8, "dbfile", dbfile);
382 362
363 const run_tests = b.addRunArtifact(tests);
383 test_step.dependOn(&run_tests.step); 364 test_step.dependOn(&run_tests.step);
384 } 365 }
385 366