From ad4ded08b4b3d6d2ace6bb5e54e6ba699094ff3c Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 14 Apr 2024 19:09:33 +0200 Subject: build: add the workaround C file --- build.zig | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index cd617f7..9beb65d 100644 --- a/build.zig +++ b/build.zig @@ -267,6 +267,8 @@ pub fn build(b: *std.Build) !void { const target = b.resolveTargetQuery(query); const optimize = b.standardOptimizeOption(.{}); + const c_flags = &[_][]const u8{"-std=c99"}; + const sqlite_lib = b.addStaticLibrary(.{ .name = "sqlite", .target = target, @@ -274,9 +276,12 @@ pub fn build(b: *std.Build) !void { }); sqlite_lib.addIncludePath(.{ .path = "c/" }); - sqlite_lib.addCSourceFile(.{ - .file = .{ .path = "c/sqlite3.c" }, - .flags = &[_][]const u8{"-std=c99"}, + sqlite_lib.addCSourceFiles(.{ + .files = &[_][]const u8{ + "c/sqlite3.c", + "c/workaround.c", + }, + .flags = c_flags, }); sqlite_lib.linkLibC(); sqlite_lib.installHeader(.{ .path = "c/sqlite3.h" }, "sqlite3.h"); @@ -345,9 +350,12 @@ pub fn build(b: *std.Build) !void { .target = cross_target, .optimize = optimize, }); - lib.addCSourceFile(.{ - .file = .{ .path = "c/sqlite3.c" }, - .flags = &[_][]const u8{"-std=c99"}, + lib.addCSourceFiles(.{ + .files = &[_][]const u8{ + "c/sqlite3.c", + "c/workaround.c", + }, + .flags = c_flags, }); lib.linkLibC(); sqlite3 = lib; @@ -362,6 +370,7 @@ pub fn build(b: *std.Build) !void { .target = cross_target, .optimize = optimize, }); + lib.addCSourceFile(.{ .file = .{ .path = "c/workaround.c" }, .flags = c_flags }); if (bundled) lib.addIncludePath(.{ .path = "c" }); linkSqlite(lib); @@ -381,10 +390,7 @@ pub fn build(b: *std.Build) !void { .target = getTarget(target, true), .optimize = optimize, }); - lib.addCSourceFile(.{ - .file = .{ .path = "c/sqlite3.c" }, - .flags = &[_][]const u8{"-std=c99"}, - }); + lib.addCSourceFile(.{ .file = .{ .path = "c/sqlite3.c" }, .flags = c_flags }); lib.addIncludePath(.{ .path = "c" }); lib.linkLibC(); -- cgit v1.2.3 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 From 5890065d754ecaca9533ebfa46e72280576510b8 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 14 Apr 2024 20:19:40 +0200 Subject: build: stop building with the system library in CI GitHub Actions workflows run on Ubuntu 22.04 which provides sqlite 3.37, we depend on at least 3.38 so we can't test this. --- build.zig | 4 ---- 1 file changed, 4 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 460df86..de81563 100644 --- a/build.zig +++ b/build.zig @@ -36,10 +36,6 @@ const ci_targets = switch (builtin.target.cpu.arch) { .x86_64 => switch (builtin.target.os.tag) { .linux => [_]TestTarget{ // Targets linux but other CPU archs. - TestTarget{ - .query = .{}, - .bundled = false, - }, TestTarget{ .query = .{ .cpu_arch = .x86_64, -- cgit v1.2.3 From e9ad0f005c7da2b2aa2f012e84733bf9aea2340b Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 14 Apr 2024 20:23:17 +0200 Subject: build: revamp the CI targets --- build.zig | 63 +++++++++------------------------------------------------------ 1 file changed, 9 insertions(+), 54 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index de81563..af6ece1 100644 --- a/build.zig +++ b/build.zig @@ -35,66 +35,21 @@ const TestTarget = struct { const ci_targets = switch (builtin.target.cpu.arch) { .x86_64 => switch (builtin.target.os.tag) { .linux => [_]TestTarget{ - // Targets linux but other CPU archs. - TestTarget{ - .query = .{ - .cpu_arch = .x86_64, - .abi = .musl, - }, - .bundled = true, - }, - TestTarget{ - .query = .{ - .cpu_arch = .x86, - .abi = .musl, - }, - .bundled = true, - }, + TestTarget{ .query = .{ .cpu_arch = .x86_64, .abi = .musl }, .bundled = true }, + TestTarget{ .query = .{ .cpu_arch = .x86, .abi = .musl }, .bundled = true }, + TestTarget{ .query = .{ .cpu_arch = .aarch64, .abi = .musl }, .bundled = true }, }, .windows => [_]TestTarget{ - TestTarget{ - .query = .{ - .cpu_arch = .x86_64, - .abi = .gnu, - }, - .bundled = true, - }, - TestTarget{ - .query = .{ - .cpu_arch = .x86, - .abi = .gnu, - }, - .bundled = true, - }, + TestTarget{ .query = .{ .cpu_arch = .x86_64, .abi = .gnu }, .bundled = true }, + TestTarget{ .query = .{ .cpu_arch = .x86, .abi = .gnu }, .bundled = true }, }, .macos => [_]TestTarget{ - TestTarget{ - .query = .{ - .cpu_arch = .x86_64, - }, - .bundled = true, - }, - // TODO(vincent): this fails for some reason - // TestTarget{ - // .query =.{ - // .cpu_arch = .aarch64, - // }, - // .bundled = true, - // }, - }, - else => [_]TestTarget{ - TestTarget{ - .query = .{}, - .bundled = false, - }, - }, - }, - else => [_]TestTarget{ - TestTarget{ - .query = .{}, - .bundled = false, + TestTarget{ .query = .{ .cpu_arch = .x86_64 }, .bundled = true }, + TestTarget{ .query = .{ .cpu_arch = .aarch64 }, .bundled = true }, }, + else => unreachable, }, + else => unreachable, }; const all_test_targets = switch (builtin.target.cpu.arch) { -- cgit v1.2.3