Skip to content

Embedded Swift support for SQLiteKit - #5

Draft
scottmarchant wants to merge 1 commit into
feat/wasi-nio-freefrom
feat/embedded-support
Draft

Embedded Swift support for SQLiteKit#5
scottmarchant wants to merge 1 commit into
feat/wasi-nio-freefrom
feat/embedded-support

Conversation

@scottmarchant

Copy link
Copy Markdown
Collaborator

Makes SQLiteKit compile under Embedded Swift. Stacked on #4 (feat/wasi-nio-free) so this diff shows only the Embedded work — 5 files, +67/−0, purely additive. It retargets to base/vapor-main once that merges.

Research-grade and lower priority than the WASI PR underneath it. Of the three repos this is the last to land, and it also depends on the sql-kit Embedded PR, since the Embedded SQLiteDataEncoder consumes SQLKit's SQLBindValue/SQLDataValue.

What changed

One commit. Every gate is #if hasFeature(Embedded) or #if canImport(Foundation).

  • SQLiteConfiguration.Storage.memory derives its identifier from system randomness where Foundation.UUID is unavailable.
  • SQLiteDatabaseVersion's isEqual(to:)/isOlder(than:) use as? Self, a cast to a generic type Embedded forbids; there SQLKit's stringValue-based protocol defaults apply instead.
  • Query logging omits the interpolated bind list under Embedded — no reflection.
  • The Decodable row-decoding entry points in SQLiteRow+SQLRow are elided, matching what SQLKit's SQLRow protocol exposes on that target.
  • SQLiteDataDecoder and SQLiteDataEncoder get Embedded-only variants: the decoder becomes an API-compatible placeholder (there's no Codable engine to drive), and the encoder maps SQLKit's driver-neutral SQLDataValue cases straight onto SQLiteData.

Upstream prerequisites

Two, both outside this repo:

  1. The sql-kit Embedded PR, for SQLBindValue/SQLDataValue.
  2. An Embedded-clean apple/swift-log. Upstream 1.14.0 doesn't compile under Embedded Swift and the build dies in Logging before reaching SQLiteKit. Verified against a locally patched clone — that override is not committed here, and the manifest still points at upstream.

Verification

Embedded wasi (swiftly run +main-snapshot-2026-06-12 ... --swift-sdk DEVELOPMENT-SNAPSHOT-2026-06-12-a-wasm32-unknown-wasip1-embedded), with the patched swift-log and the sibling Embedded branches wired via swift package edit --path: green.

Native and regular-wasi behaviour is unchanged by construction — every gate here is false off Embedded — and the parent PR's results (9/9 native, no API breakage, zero NIO on wasi) carry over.

Elide the declarations Embedded Swift cannot express. Every gate is
`#if hasFeature(Embedded)` or `#if canImport(Foundation)`, so no other target
changes.

- `SQLiteConfiguration.Storage.memory` derives its identifier from system
  randomness where `Foundation.UUID` is unavailable.
- `SQLiteDatabaseVersion`'s `isEqual(to:)`/`isOlder(than:)` use `as? Self`, a
  cast to a generic type Embedded Swift forbids; there the
  `SQLDatabaseReportedVersion` protocol's `stringValue`-based defaults apply.
- Query logging omits the interpolated bind list under Embedded Swift, which
  has no reflection.
- The `Decodable` row-decoding entry points in `SQLiteRow+SQLRow` are elided,
  matching SQLKit's `SQLRow` protocol on that target.
- `SQLiteDataDecoder` and `SQLiteDataEncoder` get Embedded-only variants: the
  decoder becomes an API-compatible placeholder (there is no Codable engine
  to drive), and the encoder maps SQLKit's driver-neutral `SQLDataValue`
  cases straight onto `SQLiteData`.

Building for `wasm32-unknown-wasip1-embedded` additionally requires an
Embedded-clean `apple/swift-log`; see the pull request description.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant