diff options
| -rw-r--r-- | build.zig | 30 | ||||
| -rw-r--r-- | sqlite.zig | 4 | ||||
| -rw-r--r-- | tools/preprocess_files.zig | 2 |
3 files changed, 19 insertions, 17 deletions
| @@ -1,9 +1,9 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | var sqlite3: ?*std.build.LibExeObjStep = null; | 4 | var sqlite3: ?*std.Build.Step.Compile = null; |
| 5 | 5 | ||
| 6 | fn linkSqlite(b: *std.build.LibExeObjStep) void { | 6 | fn 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 | ||
| 179 | pub fn build(b: *std.build.Builder) !void { | 179 | pub 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 | ||
| @@ -3360,7 +3360,7 @@ test "sqlite: bind custom type" { | |||
| 3360 | var i: usize = 0; | 3360 | var i: usize = 0; |
| 3361 | while (i < 20) : (i += 1) { | 3361 | while (i < 20) : (i += 1) { |
| 3362 | var my_data: MyData = undefined; | 3362 | var my_data: MyData = undefined; |
| 3363 | mem.set(u8, &my_data.data, @intCast(u8, i)); | 3363 | @memset(&my_data.data, @intCast(u8, i)); |
| 3364 | 3364 | ||
| 3365 | var arena = heap.ArenaAllocator.init(testing.allocator); | 3365 | var arena = heap.ArenaAllocator.init(testing.allocator); |
| 3366 | defer arena.deinit(); | 3366 | defer arena.deinit(); |
| @@ -3390,7 +3390,7 @@ test "sqlite: bind custom type" { | |||
| 3390 | 3390 | ||
| 3391 | for (rows, 0..) |row, i| { | 3391 | for (rows, 0..) |row, i| { |
| 3392 | var exp_data: MyData = undefined; | 3392 | var exp_data: MyData = undefined; |
| 3393 | mem.set(u8, &exp_data.data, @intCast(u8, i)); | 3393 | @memset(&exp_data.data, @intCast(u8, i)); |
| 3394 | 3394 | ||
| 3395 | try testing.expectEqualSlices(u8, &exp_data.data, &row.data.data); | 3395 | try testing.expectEqualSlices(u8, &exp_data.data, &row.data.data); |
| 3396 | } | 3396 | } |
diff --git a/tools/preprocess_files.zig b/tools/preprocess_files.zig index d5fce7b..3a54a93 100644 --- a/tools/preprocess_files.zig +++ b/tools/preprocess_files.zig | |||
| @@ -247,7 +247,7 @@ fn preprocessSqlite3ExtHeaderFile(gpa: mem.Allocator) !void { | |||
| 247 | 247 | ||
| 248 | pub fn main() !void { | 248 | pub fn main() !void { |
| 249 | var gpa = heap.GeneralPurposeAllocator(.{}){}; | 249 | var gpa = heap.GeneralPurposeAllocator(.{}){}; |
| 250 | defer if (gpa.deinit()) debug.panic("leaks detected\n", .{}); | 250 | defer if (gpa.deinit() == .leak) debug.panic("leaks detected\n", .{}); |
| 251 | 251 | ||
| 252 | try preprocessSqlite3HeaderFile(gpa.allocator()); | 252 | try preprocessSqlite3HeaderFile(gpa.allocator()); |
| 253 | try preprocessSqlite3ExtHeaderFile(gpa.allocator()); | 253 | try preprocessSqlite3ExtHeaderFile(gpa.allocator()); |