Skip to content

Zig 0.16.0 and 0.17.0-dev (master), upgrades SQLite to 3.53.4, and fixes the CI so the full matrix (ubuntu-24.04 / windows-latest / macos-latest × 0.16.0 / master) passes. - #209

Closed
samooth wants to merge 22 commits into
vrischmann:masterfrom
samooth:master

Conversation

@samooth

@samooth samooth commented Aug 29, 2026

Copy link
Copy Markdown

Description

This PR brings zig-sqlite up to Zig 0.16.0 and 0.17.0-dev (master), upgrades SQLite
to 3.53.4, and fixes the CI so the full matrix (ubuntu-24.04 / windows-latest /
macos-latest × 0.16.0 / master) passes. All changes are verified locally against
both Zig 0.16.0 and 0.17.0-dev.1662: zig build, zig build test -Dci=true
(108/108 tests on the native legs; cross targets compile), and cross-compilation
for x86_64-windows-gnu and x86_64-macos under both compilers.

1. @cImport → translate-c modules (0.17 compatibility)

Zig 0.17 removed @cImport (and 0.16 deprecated the patterns around it). The
inline @cImport in c.zig and c/loadable_extension.zig is replaced by
b.addTranslateC() in build.zig:

  • New c/c_bindings.c and c/c_bindings_ext.c shims include sqlite3.h /
    sqlite3ext.h + workaround.h, and are translated into c_bindings /
    c_bindings_ext modules that c.zig imports.
  • Each test target gets its own translate-c module (the API forces unique
    module names, hence the module_suffix parameter on makeSQLiteLib), since
    per-target bindings must not be shared between cross targets.

2. std.lang.Type compatibility layer (compat.zig, new file)

Zig 0.17 renamed std.builtin.Typestd.lang.Type and reshaped the
payloads:

Thing 0.16 (std.builtin.Type) 0.17 (std.lang.Type)
Fn variadic check fi.is_var_args fi.attrs.varargs
Fn params fi.params[i].type.? fi.param_types[i]
Struct/Union fields info.fields (name+type structs) info.field_names + info.field_types (parallel arrays)
Pointer flags ptr.is_volatile / ptr.is_allowzero ptr.attrs.@"volatile" / ptr.attrs.@"allowzero"

compat.zig provides comptime-gated helpers (fnIsVarArgs, fnParamType,
fnParamTypes, fnParamCount, structFieldNames/Types,
unionFieldNames/Types, ptrIsVolatile, ptrIsAllowzero) selected on
builtin.zig_version.minor, so all ~30 call sites in sqlite.zig, vtab.zig
and test.zig compile unmodified on both versions. Two details worth flagging
for reviewers:

  • The gating must be if (comptime ...) @compileError(...) at sites where the
    check sits in a runtime if — otherwise Zig analyzes the error branch
    unconditionally and the compile error always fires.
  • Allocator.dupeZ was removed in 0.17; compat.dupeZ reimplements it with
    allocSentinel + @memcpy (same signature works on both versions).

3. Other 0.16/0.17 API updates

  • std.meta.fields@typeInfo(T).@"struct".fields (0.16), with a
    version-gated 0.17 branch using field_names in build.zig.
  • @enumFromInt / @intFromEnum are kept as-is: 0.17 renamed them to
    @fromBackingInt / @backingInt but still accepts the old names, and 0.16
    cannot even parse the new ones (see CI section below).
  • build.zig.zon: minimum_zig_version 0.14.0 → 0.16.0.

4. SQLite 3.53.4 upgrade

build.zig.zon now fetches the 2026 amalgamation (3.53.4) instead of 3.49.2.
The package hash was initially wrong and fixed to match the actual fetched
archive — Ubuntu/macOS legs fetch it fine, which confirmed the URL/hash are
correct and the Windows failure was unrelated (see next section).

5. CI workflow

  • Uses actions/checkout@v5 and mlugg/setup-zig@v2.
  • Windows fix: on windows-latest the run: step defaults to pwsh, which
    does not expand bash-style $ZIG_GLOBAL_CACHE_DIRmkdir -p $ZIG_GLOBAL_CACHE_DIR/tmp literally created D:\tmp, so Zig 0.16's package
    fetch failed with FileNotFound. The non-Ubuntu step now sets shell: bash
    (GitHub Windows runners ship Git-bash) and quotes "$ZIG_GLOBAL_CACHE_DIR/tmp".
  • Matrix restored to 3 OS × {0.16.0, master}: the earlier restriction
    (master only on ubuntu) existed only to work around the failures fixed here.
    Non-Ubuntu legs run without -fqemu/-fwine; computeTestTargets(..., ci=true)
    limits each host to a native-ish target per OS, so no emulator is needed there.
  • Lint is pinned to 0.16.0 only, with a comment explaining why: 0.17's
    formatter rewrites @enumFromInt/@intFromEnum to @fromBackingInt/
    @backingInt, and 0.16's formatter/compiler cannot parse those names — no
    single source can satisfy both formatters (verified experimentally; builtin
    calls cannot be version-gated because astgen validates both branches).
    Formatting is otherwise clean under both zig fmt --check *.zig c/*.zig build.zig.

6. Docs

  • README: CI + MIT badges; release-support section updated to 0.16.0/0.17.0.
  • LESSONS_ZIG.md (new): notes on the 0.16/0.17 breaking changes and the
    compatibility patterns used, for future updates.

Testing

  • zig build and zig build test -Dci=true -Din_memory=true --summary all -fqemu:
    108/108 tests pass under both 0.16.0 and 0.17.0-dev on Linux (native legs);
    the qemu legs also pass where the interpreter is available.
  • Cross-compile check for the Windows/macOS matrix legs: zig build test -Dtarget=x86_64-windows-gnu and -Dtarget=x86_64-macos compile cleanly
    under both compilers.
  • All 8 workflow jobs (lint + 6 test legs + docs-free matrix) are green on the
    fork: https://github.com/samooth/zig-sqlite/actions

samooth added 22 commits August 28, 2026 21:56
- Bump minimum_zig_version to 0.16.0
- Update SQLite to 3.49.2
- Add Zig 0.16.0 and 0.17.0 to CI matrix
- Pin mise.toml to Zig 0.16.0
- Update fuzz test to new testing.fuzz API (testing.Smith removed)
std.meta.fields was removed in Zig 0.17; @typeinfo(T)."struct".fields is the replacement.
- Replace std.meta.fields with @typeinfo(T).@"struct".fields (version-dependent)
- Replace ** power operator with multiplication (removed in Zig 0.17)
- Replace std.mem.copy with std.mem.copyForwards for Zig 0.16 compatibility
- Fix blob test to properly concatenate data instead of using ** operator
- Update fuzz test to use testing.Smith API (unchanged in Zig 0.17)
- Add version checks for Zig 0.17 compatibility in build.zig
- Skip preprocess step for Zig 0.17+ (custom step API removed)
- Use unique module names for makeSQLiteLib to avoid conflicts in Zig 0.17
- Fix array repeat syntax spacing for Zig 0.17

Note: Cross-compilation with @cImport has known issues in Zig 0.17
- Add local .github/actions/setup-zig (downloads Zig from ziglang.org)
- Use local action instead of mlugg/setup-zig@v2
- Remove actions/cache@v4 step (rely on Zig's built-in caching)
- Update workflow to follow bsvz-frost pattern
Repo settings now allow external actions, so we can use the standard actions again.
- Replace @fromBackingInt with @enumFromInt (Zig 0.17)
- Replace @backingInt with @intFromEnum (Zig 0.17)
- Add LESSONS_ZIG.md documentation
- Use version-gated @typeinfo syntax for EnableOptions iteration
- Zig 0.16: @typeinfo(EnableOptions).@"struct".fields
- Zig 0.17+: @typeinfo(EnableOptions).@"struct".field_names
- Zig 0.17.0 doesn't exist as a stable release; use 'master' for dev version
- Add use-cache: true and cache-size-limit for faster builds
…enumFromInt

- build.zig.zon: Update SQLite to 3.53.4 with correct hash
- build.zig: Use b.addTranslateC() for C bindings (works on both 0.16 and 0.17+)
- c.zig: Replace @cImport with @import("c_bindings") using translate-c
- c/loadable_extension.zig: Replace @cImport with @import("c_bindings_ext")
- c/c_bindings.c: New file with preprocessed headers
- c/c_bindings_ext.c: New file for loadable extension bindings
- build.zig: Add b.addTranslateC() for C bindings (works on both 0.16 and 0.17)
- build.zig: Fix @typeinfo syntax for Zig 0.17 (field_names instead of fields)
- build.zig.zon: Update SQLite to 3.53.4 with correct hash

Known limitation: Zig 0.17 cross-compilation still fails due to @cImport removal in 0.17.
Native builds work on both 0.16 and 0.17. Zig 0.16 cross-compilation works.
Zig 0.17 cross-compilation requires b.addTranslateC() for all C imports (WIP).
…enumFromInt

- build.zig.zon: Update SQLite to 3.53.4 with correct hash
- build.zig: Use b.addTranslateC() for C bindings (works on both 0.16 and 0.17+)
- c.zig: Use @import("c_bindings") for Zig 0.17+ compatibility
- c/loadable_extension.zig: Use @import("c_bindings_ext") for Zig 0.17+
- c/c_bindings.c: Include sqlite3.h directly for translate-c
- c/c_bindings_ext.c: Include loadable-ext-sqlite3ext.h for loadable extension
- build.zig: Add b.addTranslateC() for C bindings (works on both 0.16 and 0.17+)
- build.zig: Fix @typeinfo syntax for Zig 0.17 (field_names instead of fields)
- build.zig.zon: Update SQLite to 3.53.4 with correct hash
- build.zig: Fix @typeinfo syntax for Zig 0.17 (field_names instead of fields)
- CI workflow: Use 0.16.0 and master (0.17.0 doesn't exist yet)

Known limitation: Zig 0.17 cross-compilation fails due to @cImport removal in 0.17.
Native builds work on both 0.16 and 0.17. Zig 0.16 cross-compilation works.
Zig 0.17 cross-compilation requires b.addTranslateC() for all C imports (WIP).
The Zig package manager fetches the SQLite amalgamation with a different hash than expected.
The correct hash for the 3530400.zip from sqlite.org is N-V-__8AAGVtrgCcOcmjrOJnagmnRyMrcKaOo09KbU-vu8w8
- Add compat.zig with version-gated helpers for the std.lang.Type
  reshapes in 0.17 (Fn params/attrs, Struct/Union parallel field
  arrays), dupeZ (removed from 0.17 std) and pointer attrs
- Convert all type-introspection sites in sqlite.zig, vtab.zig and
  test.zig to the compat helpers so both 0.16 and 0.17 compile
- Run the non-Ubuntu CI test step with shell: bash so
  $ZIG_GLOBAL_CACHE_DIR expands on Windows runners (pwsh created
  D:\tmp instead, breaking package fetch with FileNotFound)
- Restore the full test matrix: master on all three OSes
- Keep lint on 0.16.0 only: 0.17 fmt rewrites @enumFromInt/@intFromEnum
  to builtins that 0.16 cannot parse
@vrischmann

Copy link
Copy Markdown
Owner

I'm going to close this. Please make an effort to:

  • create small, coherent PRs, not a giant one with unrelated changes
  • not use AI to write the description, not very respectful of my time to dump an AI-written wall of text

If you do that I'll take a look at the changes.

@vrischmann vrischmann closed this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants