diff options
| author | 2020-12-23 01:53:57 +0100 | |
|---|---|---|
| committer | 2021-01-09 17:08:11 +0100 | |
| commit | d1612a251c2aea98ed0b34fdd2c88395f513cf94 (patch) | |
| tree | 78cdd622830f73ed0693bed0f6ed19d23d3a633e /build.zig | |
| parent | readme: update type mappings rules (diff) | |
| download | zig-sqlite-d1612a251c2aea98ed0b34fdd2c88395f513cf94.tar.gz zig-sqlite-d1612a251c2aea98ed0b34fdd2c88395f513cf94.tar.xz zig-sqlite-d1612a251c2aea98ed0b34fdd2c88395f513cf94.zip | |
allow building with the bundled sqlite source code
Diffstat (limited to '')
| -rw-r--r-- | build.zig | 38 |
1 files changed, 29 insertions, 9 deletions
| @@ -1,28 +1,48 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | ||
| 3 | 2 | ||
| 4 | fn linkAll(obj: *std.build.LibExeObjStep) void { | 3 | var sqlite3: ?*std.build.LibExeObjStep = null; |
| 5 | obj.linkLibC(); | 4 | |
| 6 | obj.linkSystemLibrary("sqlite3"); | 5 | fn linkSqlite(b: *std.build.LibExeObjStep) void { |
| 6 | b.linkLibC(); | ||
| 7 | |||
| 8 | if (sqlite3) |lib| { | ||
| 9 | b.linkLibrary(lib); | ||
| 10 | } else { | ||
| 11 | b.linkSystemLibrary("sqlite3"); | ||
| 12 | } | ||
| 7 | } | 13 | } |
| 8 | 14 | ||
| 9 | pub fn build(b: *Builder) void { | 15 | pub fn build(b: *std.build.Builder) void { |
| 10 | const target = b.standardTargetOptions(.{}); | 16 | const target = b.standardTargetOptions(.{}); |
| 11 | const mode = b.standardReleaseOptions(); | 17 | const mode = b.standardReleaseOptions(); |
| 12 | 18 | ||
| 19 | const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory") orelse false; | ||
| 20 | const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library") orelse false; | ||
| 21 | |||
| 22 | // Build sqlite from source if asked | ||
| 23 | if (use_bundled) { | ||
| 24 | const lib = b.addStaticLibrary("sqlite", null); | ||
| 25 | lib.addCSourceFile("sqlite3.c", &[_][]const u8{"-std=c99"}); | ||
| 26 | lib.linkLibC(); | ||
| 27 | lib.setTarget(target); | ||
| 28 | lib.setBuildMode(mode); | ||
| 29 | sqlite3 = lib; | ||
| 30 | } | ||
| 31 | |||
| 13 | const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig"); | 32 | const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig"); |
| 33 | lib.addIncludeDir("."); | ||
| 34 | linkSqlite(lib); | ||
| 14 | lib.setTarget(target); | 35 | lib.setTarget(target); |
| 15 | lib.setBuildMode(mode); | 36 | lib.setBuildMode(mode); |
| 16 | linkAll(lib); | ||
| 17 | lib.install(); | 37 | lib.install(); |
| 18 | 38 | ||
| 19 | const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory") orelse false; | ||
| 20 | |||
| 21 | var main_tests = b.addTest("sqlite.zig"); | 39 | var main_tests = b.addTest("sqlite.zig"); |
| 40 | main_tests.addIncludeDir("."); | ||
| 41 | linkSqlite(main_tests); | ||
| 42 | main_tests.setBuildMode(mode); | ||
| 22 | main_tests.setTarget(target); | 43 | main_tests.setTarget(target); |
| 23 | main_tests.setBuildMode(mode); | 44 | main_tests.setBuildMode(mode); |
| 24 | main_tests.addBuildOption(bool, "in_memory", in_memory); | 45 | main_tests.addBuildOption(bool, "in_memory", in_memory); |
| 25 | linkAll(main_tests); | ||
| 26 | 46 | ||
| 27 | const test_step = b.step("test", "Run library tests"); | 47 | const test_step = b.step("test", "Run library tests"); |
| 28 | test_step.dependOn(&main_tests.step); | 48 | test_step.dependOn(&main_tests.step); |