summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGravatar Lue2023-05-17 12:25:55 +0000
committerGravatar Vincent Rischmann2023-05-17 21:29:58 +0200
commit53630451bbfe354de5b4cbbb1d2f3b32a8173069 (patch)
treee7e973fb91f2dabaec5f7a81bfb4ee90889885fe /build.zig
parentfix build (diff)
downloadzig-sqlite-53630451bbfe354de5b4cbbb1d2f3b32a8173069.tar.gz
zig-sqlite-53630451bbfe354de5b4cbbb1d2f3b32a8173069.tar.xz
zig-sqlite-53630451bbfe354de5b4cbbb1d2f3b32a8173069.zip
Fix build failures on latest Zig
Now the correct build APIs and `@memset` builtin are used. Unfortunately cImport fails for `aarch64` and `riscv64` targets, but I'm not sure how to fix this.
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig30
1 files changed, 16 insertions, 14 deletions
diff --git a/build.zig b/build.zig
index 2478df6..4a645e5 100644
--- a/build.zig
+++ b/build.zig
@@ -1,9 +1,9 @@
1const std = @import("std"); 1const std = @import("std");
2const builtin = @import("builtin"); 2const builtin = @import("builtin");
3 3
4var sqlite3: ?*std.build.LibExeObjStep = null; 4var sqlite3: ?*std.Build.Step.Compile = null;
5 5
6fn linkSqlite(b: *std.build.LibExeObjStep) void { 6fn linkSqlite(b: *std.Build.Step.Compile) void {
7 if (sqlite3) |lib| { 7 if (sqlite3) |lib| {
8 b.linkLibrary(lib); 8 b.linkLibrary(lib);
9 } else { 9 } else {
@@ -176,7 +176,7 @@ const all_test_targets = switch (builtin.target.cpu.arch) {
176 }, 176 },
177}; 177};
178 178
179pub fn build(b: *std.build.Builder) !void { 179pub fn build(b: *std.Build) !void {
180 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true; 180 const in_memory = b.option(bool, "in_memory", "Should the tests run with sqlite in memory (default true)") orelse true;
181 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one"); 181 const dbfile = b.option([]const u8, "dbfile", "Always use this database file instead of a temporary one");
182 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); 182 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)");
@@ -199,7 +199,7 @@ pub fn build(b: *std.build.Builder) !void {
199 // Add a top-level step to run the preprocess-files tool 199 // Add a top-level step to run the preprocess-files tool
200 const preprocess_files_run = b.step("preprocess-files", "Run the preprocess-files tool"); 200 const preprocess_files_run = b.step("preprocess-files", "Run the preprocess-files tool");
201 201
202 const preprocess_files_tool_run = preprocess_files_tool.run(); 202 const preprocess_files_tool_run = b.addRunArtifact(preprocess_files_tool);
203 preprocess_files_run.dependOn(&preprocess_files_tool_run.step); 203 preprocess_files_run.dependOn(&preprocess_files_tool_run.step);
204 204
205 // If the target is native we assume the user didn't change it with -Dtarget and run all test targets. 205 // If the target is native we assume the user didn't change it with -Dtarget and run all test targets.
@@ -222,10 +222,19 @@ pub fn build(b: *std.build.Builder) !void {
222 for (test_targets) |test_target| { 222 for (test_targets) |test_target| {
223 const bundled = use_bundled orelse test_target.bundled; 223 const bundled = use_bundled orelse test_target.bundled;
224 const cross_target = getTarget(test_target.target, bundled); 224 const cross_target = getTarget(test_target.target, bundled);
225 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
226 const test_name = b.fmt("{s}-{s}-{s}", .{
227 try cross_target.zigTriple(b.allocator),
228 @tagName(optimize),
229 single_threaded_txt,
230 });
225 231
226 const tests = b.addTest(.{ 232 const tests = b.addTest(.{
233 .name = test_name,
227 .target = cross_target, 234 .target = cross_target,
235 .optimize = optimize,
228 .root_source_file = .{ .path = "sqlite.zig" }, 236 .root_source_file = .{ .path = "sqlite.zig" },
237 .single_threaded = test_target.single_threaded,
229 }); 238 });
230 239
231 if (bundled) { 240 if (bundled) {
@@ -239,6 +248,9 @@ pub fn build(b: *std.build.Builder) !void {
239 sqlite3 = lib; 248 sqlite3 = lib;
240 } 249 }
241 250
251 if (bundled) tests.addIncludePath("c");
252 linkSqlite(tests);
253
242 const lib = b.addStaticLibrary(.{ 254 const lib = b.addStaticLibrary(.{
243 .name = "zig-sqlite", 255 .name = "zig-sqlite",
244 .root_source_file = .{ .path = "sqlite.zig" }, 256 .root_source_file = .{ .path = "sqlite.zig" },
@@ -248,16 +260,6 @@ pub fn build(b: *std.build.Builder) !void {
248 if (bundled) lib.addIncludePath("c"); 260 if (bundled) lib.addIncludePath("c");
249 linkSqlite(lib); 261 linkSqlite(lib);
250 262
251 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
252 tests.setName(b.fmt("{s}-{s}-{s} ", .{
253 try cross_target.zigTriple(b.allocator),
254 @tagName(optimize),
255 single_threaded_txt,
256 }));
257 tests.single_threaded = test_target.single_threaded;
258 if (bundled) tests.addIncludePath("c");
259 linkSqlite(tests);
260
261 const tests_options = b.addOptions(); 263 const tests_options = b.addOptions();
262 tests.addOptions("build_options", tests_options); 264 tests.addOptions("build_options", tests_options);
263 265