From 947b4ade92e6a0919aa4a7b845ec674082e7dc51 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 14 Apr 2024 20:10:41 +0200 Subject: build: rework and fix the CI tests * stop having a global sqlite3 compile step variable * remove the test_lib which doesn't do anything --- build.zig | 61 +++++++++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 40 deletions(-) (limited to 'build.zig') 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; const ResolvedTarget = std.Build.ResolvedTarget; const Query = std.Target.Query; -var sqlite3: ?*Step.Compile = null; - -fn linkSqlite(b: *Step.Compile) void { - if (sqlite3) |lib| { - b.linkLibrary(lib); - } else { - b.linkLibC(); - b.linkSystemLibrary("sqlite3"); - } -} - fn getTarget(original_target: ResolvedTarget, bundled: bool) ResolvedTarget { if (bundled) { var tmp = original_target; @@ -335,6 +324,20 @@ pub fn build(b: *std.Build) !void { single_threaded_txt, }); + const test_sqlite_lib = b.addStaticLibrary(.{ + .name = "sqlite", + .target = cross_target, + .optimize = optimize, + }); + test_sqlite_lib.addCSourceFiles(.{ + .files = &[_][]const u8{ + "c/sqlite3.c", + "c/workaround.c", + }, + .flags = c_flags, + }); + test_sqlite_lib.linkLibC(); + const tests = b.addTest(.{ .name = test_name, .target = cross_target, @@ -342,44 +345,22 @@ pub fn build(b: *std.Build) !void { .root_source_file = .{ .path = "sqlite.zig" }, .single_threaded = test_target.single_threaded, }); - const run_tests = b.addRunArtifact(tests); - + tests.addIncludePath(.{ .path = "c" }); if (bundled) { - const lib = b.addStaticLibrary(.{ - .name = "sqlite", - .target = cross_target, - .optimize = optimize, - }); - lib.addCSourceFiles(.{ - .files = &[_][]const u8{ - "c/sqlite3.c", - "c/workaround.c", - }, - .flags = c_flags, - }); - lib.linkLibC(); - sqlite3 = lib; + tests.linkLibrary(test_sqlite_lib); + } else { + tests.linkLibC(); + tests.addCSourceFile(.{ .file = .{ .path = "c/workaround.c" }, .flags = c_flags }); + tests.linkSystemLibrary("sqlite3"); } - if (bundled) tests.addIncludePath(.{ .path = "c" }); - linkSqlite(tests); - - const lib = b.addStaticLibrary(.{ - .name = "zig-sqlite", - .root_source_file = .{ .path = "sqlite.zig" }, - .target = cross_target, - .optimize = optimize, - }); - lib.addCSourceFile(.{ .file = .{ .path = "c/workaround.c" }, .flags = c_flags }); - if (bundled) lib.addIncludePath(.{ .path = "c" }); - linkSqlite(lib); - const tests_options = b.addOptions(); tests.root_module.addImport("build_options", tests_options.createModule()); tests_options.addOption(bool, "in_memory", in_memory); tests_options.addOption(?[]const u8, "dbfile", dbfile); + const run_tests = b.addRunArtifact(tests); test_step.dependOn(&run_tests.step); } -- cgit v1.2.3