Skip to content

Embedded Swift support for SQLiteNIO - #5

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

Embedded Swift support for SQLiteNIO#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 SQLiteNIO compile under Embedded Swift. This builds on #4 (feat/wasi-nio-free) and retargets to base/vapor-main once that merges, so the diff here shows only the Embedded work. It is research grade and lower priority than #4, which does not depend on it; review that one first.

Everything is gated behind #if hasFeature(Embedded) or a Foundation-flavor canImport, so no other configuration changes at all:

  • SQLiteData's Encodable conformance moves to a conditional extension, and the deprecated SQLiteDataType.serialize(_:) is elided; Embedded Swift has no Encoder and no any Encodable.
  • The async withConnection(_:) protocol requirement that 1.13.0 added is elided under Embedded Swift: a generic method requirement cannot be placed in a witness table, and keeping it would make any SQLiteDatabase unusable there. The concrete SQLiteConnection.withConnection(_:) remains.
  • SQLiteError: LocalizedError, the Data bridges, and the Date bridge gate on canImport(FoundationEssentials) || canImport(Foundation); Embedded Swift has neither flavor. The errorDescription witness stays in the type body, so only the conformance is conditional.
  • SQLiteRow.description and SQLiteCustomFunction's error reporting rely on reflection (Array.description, any Error interpolation); reflection-free equivalents replace them under Embedded Swift.

Nothing here is for WASI. Regular WASI has FoundationEssentials and Codable and needs none of this, which is why it is a separate PR.

One prerequisite outside this repo: an Embedded-clean swift-log. Upstream swift-log does not compile under Embedded Swift (Logger.Level: Codable, Dictionary.description, and Array.description are all @_unavailableInEmbedded), so the build dies inside Logging before reaching a line of sqlite-nio code. I verified against a locally patched clone; that patch is not committed anywhere on this branch and the manifest still points at upstream apple/swift-log, so this PR cannot land until swift-log gains Embedded support. swift-collections needed nothing.

Verified locally: the Embedded build is green with swiftly run +main-snapshot-2026-06-12 swift build --swift-sdk DEVELOPMENT-SNAPSHOT-2026-06-12-a-wasm32-unknown-wasip1-embedded and the patched swift-log. Native (59 tests) and regular WASI are unchanged by construction, since every gate here is false outside Embedded Swift.

Motivation:

Embedded Swift has no reflection, no `Encoder`, no existential metatypes, no
generic protocol requirements, and no Foundation in either flavor. A handful of
SQLiteNIO 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 exactly those declarations. Every gate is `#if hasFeature(Embedded)` or a
Foundation-flavor `canImport`, so no other target is affected in any way.

- `SQLiteData`'s `Encodable` conformance and the deprecated
  `SQLiteDataType.serialize(_:)` move behind `#if !hasFeature(Embedded)`:
  Embedded Swift has no `Encoder` and no `any Encodable` existential.
- `SQLiteDatabase`'s `async` `withConnection(_:)` requirement moves behind the
  same gate: a generic method requirement cannot be placed in a witness table,
  and keeping it would make `any SQLiteDatabase` unusable under Embedded Swift.
  The concrete ``SQLiteConnection/withConnection(_:)`` remains available.
- `SQLiteError: LocalizedError`, the `Data` bridges, and the `Date` bridge gate
  on `canImport(FoundationEssentials) || canImport(Foundation)`. The
  `errorDescription` witness stays in the type body, so the conformance is the
  only conditional part.
- `Exports.swift`'s `ByteBuffer(data:)` shim, and its Foundation-flavor import,
  move behind the same gate; the rest of the `[UInt8]` stand-in needs only the
  stdlib.
- `SQLiteRow.description` and `SQLiteCustomFunction`'s error reporting use
  reflection (`Array.description`, `any Error` interpolation); reflection-free
  equivalents replace them under Embedded Swift.

Result:

SQLiteNIO compiles for `wasm32-unknown-wasip1-embedded`. Building for that 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