Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.0
- run: zig fmt --check *.zig

test-in-memory:
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Setup zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.0

- name: Install qemu
if: ${{ matrix.os == 'ubuntu-24.04' }}
Expand Down
17 changes: 12 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mem = std.mem;
const ResolvedTarget = std.Build.ResolvedTarget;
const Query = std.Target.Query;
const builtin = @import("builtin");
const Translator = @import("translate_c").Translator;

fn getTarget(original_target: ResolvedTarget) ResolvedTarget {
var tmp = original_target;
Expand Down Expand Up @@ -106,16 +107,22 @@ fn computeTestTargets(isNative: bool, ci: ?bool) ?[]const TestTarget {
return null;
}

/// Translates `header` (which includes sqlite3.h) with the translate-c package,
/// which replaces `@cImport` and the deprecated `std.Build.addTranslateC`.
fn translateSQLite(b: *std.Build, dep: *std.Build.Dependency, header: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
const translate_c = b.addTranslateC(.{
.root_source_file = b.path(header),
const translate_c = b.dependency("translate_c", .{});
const t: Translator = .init(translate_c, .{
.c_source_file = b.path(header),
.target = target,
.optimize = optimize,
// Struct fields default to zero, as with @cImport, so struct literals such as
// vtab.zig's sqlite3_module compile against every SQLite version.
.default_init = true,
});
translate_c.addIncludePath(dep.path("."));
translate_c.addIncludePath(b.path("c"));
t.addIncludePath(dep.path("."));
t.addIncludePath(b.path("c"));

return translate_c.createModule();
return t.mod;
}

// This creates a SQLite static library from the SQLite dependency code.
Expand Down
6 changes: 6 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
.url = "https://www.sqlite.org/2025/sqlite-amalgamation-3490200.zip",
.hash = "N-V-__8AAH-mpwB7g3MnqYU-ooUBF1t99RP27dZ9addtMVXD",
},
// C bindings (replaces @cImport and the deprecated std.Build.addTranslateC),
// branch zig-0.17.x.
.translate_c = .{
.url = "git+https://codeberg.org/ziglang/translate-c?ref=zig-0.17.x#cfac21f3199b2b02ce3fd7db652aa456421fe4ab",
.hash = "translate_c-2.0.2-Q_BUWvBNBwDnyehSiuAJmdFcMYHYGA-Jc3KiYdrV2Dqx",
},
},
.paths = .{"."},
}