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

@scottmarchant scottmarchant commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Makes SQLiteKit compile under Embedded Swift. This builds on #4 (feat/wasi-nio-free) and retargets to base/vapor-main once that merges, so this diff shows only the Embedded work, which is purely additive. Research grade, lower priority than #4, and last in line of the three repos: it also depends on the sql-kit Embedded PR (PassiveLogic/sql-kit#4), because the Embedded SQLiteDataEncoder consumes SQLKit's SQLBindValue and SQLDataValue.

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 that Embedded Swift forbids; SQLKit's stringValue-based protocol defaults apply there instead.
  • 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 what SQLKit's SQLRow protocol exposes on that target.
  • SQLiteDataDecoder becomes an API-compatible placeholder (there is no Codable engine to drive it), and SQLiteDataEncoder maps SQLKit's driver-neutral SQLDataValue cases directly onto SQLiteData.

Two prerequisites outside this repo: the sql-kit Embedded PR above, and an Embedded-clean swift-log (upstream 1.14.0 does not compile under Embedded Swift; the build dies inside Logging before reaching SQLiteKit). The swift-log patch is verified against a local clone but not committed here, and the manifest still points at upstream.

Verified locally: the Embedded build is green (DEVELOPMENT-SNAPSHOT-2026-06-12-a-wasm32-unknown-wasip1-embedded, patched swift-log, sibling Embedded branches wired via swift package edit --path). Native and regular WASI behavior is unchanged by construction, since every gate here is false off Embedded, and the parent PR's results (9 native tests, no API breakage, zero NIO on WASI) carry over.

Motivation:

Embedded Swift has no Codable, no reflection, no casts to a generic type, and no
Foundation. A handful of SQLiteKit declarations depend on one of those and are the
only thing standing between the SwiftNIO-free configuration and a
`wasm32-unknown-wasip1-embedded` build.

Modifications:

Elide or substitute exactly those declarations. 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`, which is what replaces `Encodable`'s `encode(to:)`
  as the extraction path there.

Result:

SQLiteKit compiles for `wasm32-unknown-wasip1-embedded`.

On every other target the generated symbol graph is unchanged — the same symbols
with byte-identical `docComment` line counts — and
`diagnose-api-breaking-changes` reports no differences.

Building for the Embedded target additionally requires an Embedded-clean
`apple/swift-log`; see the pull request description.
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