From d1612a251c2aea98ed0b34fdd2c88395f513cf94 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Wed, 23 Dec 2020 01:53:57 +0100 Subject: allow building with the bundled sqlite source code --- build.zig | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index a3f0de5..be2a729 100644 --- a/build.zig +++ b/build.zig @@ -1,28 +1,48 @@ const std = @import("std"); -const Builder = std.build.Builder; -fn linkAll(obj: *std.build.LibExeObjStep) void { - obj.linkLibC(); - obj.linkSystemLibrary("sqlite3"); +var sqlite3: ?*std.build.LibExeObjStep = null; + +fn linkSqlite(b: *std.build.LibExeObjStep) void { + b.linkLibC(); + + if (sqlite3) |lib| { + b.linkLibrary(lib); + } else { + b.linkSystemLibrary("sqlite3"); + } } -pub fn build(b: *Builder) void { +pub fn build(b: *std.build.Builder) void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); + const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory") orelse false; + const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library") orelse false; + + // Build sqlite from source if asked + if (use_bundled) { + const lib = b.addStaticLibrary("sqlite", null); + lib.addCSourceFile("sqlite3.c", &[_][]const u8{"-std=c99"}); + lib.linkLibC(); + lib.setTarget(target); + lib.setBuildMode(mode); + sqlite3 = lib; + } + const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig"); + lib.addIncludeDir("."); + linkSqlite(lib); lib.setTarget(target); lib.setBuildMode(mode); - linkAll(lib); lib.install(); - const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory") orelse false; - var main_tests = b.addTest("sqlite.zig"); + main_tests.addIncludeDir("."); + linkSqlite(main_tests); + main_tests.setBuildMode(mode); main_tests.setTarget(target); main_tests.setBuildMode(mode); main_tests.addBuildOption(bool, "in_memory", in_memory); - linkAll(main_tests); const test_step = b.step("test", "Run library tests"); test_step.dependOn(&main_tests.step); -- cgit v1.2.3 From 2a51619a12350c21689c32086c3482fb9815e260 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sat, 23 Jan 2021 19:09:01 +0100 Subject: build: default to in-memory tests Now that we use `std.testing.tmpDir` we're actually hitting the disk, which made me realize that the tests run significantly slower than before, because on my system `/tmp` is a tmpfs which is already in memory. --- build.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index be2a729..b48f43d 100644 --- a/build.zig +++ b/build.zig @@ -16,8 +16,8 @@ pub fn build(b: *std.build.Builder) void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); - const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory") orelse false; - const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library") orelse false; + const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true; + const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)") orelse false; // Build sqlite from source if asked if (use_bundled) { -- cgit v1.2.3