feat: Add Embedded Swift support for SQLiteNIO - #5
Draft
scottmarchant wants to merge 1 commit into
Draft
Conversation
scottmarchant
force-pushed
the
feat/wasi-nio-free
branch
from
July 28, 2026 21:00
88f4f62 to
ad4624e
Compare
scottmarchant
force-pushed
the
feat/embedded-support
branch
from
July 28, 2026 21:00
d2eda14 to
84ccd33
Compare
scottmarchant
force-pushed
the
feat/wasi-nio-free
branch
from
July 29, 2026 03:24
ad4624e to
d80081e
Compare
scottmarchant
force-pushed
the
feat/embedded-support
branch
2 times, most recently
from
July 29, 2026 22:20
7923233 to
1bf01f2
Compare
scottmarchant
force-pushed
the
feat/wasi-nio-free
branch
2 times, most recently
from
July 30, 2026 02:42
a699466 to
ba8e2cc
Compare
scottmarchant
force-pushed
the
feat/embedded-support
branch
from
July 30, 2026 02:43
1bf01f2 to
967513a
Compare
scottmarchant
force-pushed
the
feat/wasi-nio-free
branch
from
July 30, 2026 03:14
ba8e2cc to
d7abfbe
Compare
scottmarchant
force-pushed
the
feat/embedded-support
branch
from
July 30, 2026 03:14
967513a to
c3f48c2
Compare
scottmarchant
force-pushed
the
feat/embedded-support
branch
from
July 30, 2026 03:48
c3f48c2 to
8b1167c
Compare
scottmarchant
force-pushed
the
feat/wasi-nio-free
branch
from
July 30, 2026 04:48
d7abfbe to
ef86f0f
Compare
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. - The hook API gates whole-file on the same condition: hook events carry `Date` timestamps and observer identity rides on `UUID`, so the API cannot exist without one of the flavors. The `observerBuckets` container and `close()`'s `clearAllHooks()` call gate with it. - `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.
scottmarchant
force-pushed
the
feat/embedded-support
branch
from
July 30, 2026 04:49
8b1167c to
f00a97d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #4 (
feat/wasi-nio-free) and retargets tobase/vapor-mainonce that merges, so the diff here shows only the Embedded work. Research grade and lower priority than #4, which does not depend on this; review that one first.Makes SQLiteNIO compile for
wasm32-unknown-wasip1-embedded.Changes:
SQLiteData'sEncodableconformance moves to a conditional extension and the deprecatedSQLiteDataType.serialize(_:)is elided: Embedded Swift has noEncoderand noany Encodableexistential.asyncwithConnection(_:)protocol requirement 1.13.0 added is elided under Embedded Swift, because a generic method requirement cannot be placed in a witness table and keeping it would makeany SQLiteDatabaseunusable there. The concreteSQLiteConnection.withConnection(_:)remains available.SQLiteError: LocalizedError, theDatabridges, and theDatebridge gate oncanImport(FoundationEssentials) || canImport(Foundation), since Embedded Swift has neither flavor. TheerrorDescriptionwitness stays in the type body, so only the conformance is conditional.observerBucketsplusclose()'sclearAllHooks()call gate with it. This one is deliberately not narrowed: the hook API's public surface is Foundation-shaped, withDateonSQLiteCommitEvent/SQLiteRollbackEventandUUIDonSQLiteHookToken.id, so keeping it would mean either shipping stand-ins for both types or giving Embedded a different public API than every other target.SQLiteRow.descriptionandSQLiteCustomFunction's error reporting rely on reflection (Array.description,any Errorinterpolation), so reflection-free equivalents replace them under Embedded Swift.Where the full toolchain is present, nothing changes: every gate here is false outside Embedded Swift.
swift package diagnose-api-breaking-changesagainst #4's tip reports no breaking changes in SQLiteNIO, and the 59-test suite passes unchanged.What Embedded loses: the
Encodableconformance onSQLiteData, the deprecatedSQLiteDataType.serialize(_:), the protocol-levelasync withConnection(_:)(the concrete one stays),SQLiteError: LocalizedError, theDataandDatebridges, and the observation hook API. Nothing here affects regular WASI, which has FoundationEssentials and Codable and needs none of it. That is why this is a separate PR.Prerequisite outside this repo: an Embedded-clean swift-log. Upstream swift-log does not compile under Embedded Swift (
Logger.Level: Codable,Dictionary.description, andArray.descriptionare all@_unavailableInEmbedded), so the build dies insideLoggingbefore reaching a line of sqlite-nio code. This is verified against a locally patched clone; that patch is not committed anywhere on this branch and the manifest still points at upstreamapple/swift-log, so this cannot land until swift-log gains Embedded support. swift-collections needed nothing.Verification: 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-embeddedand the patched swift-log, exercised end to end by a downstream consumer whose Embedded test suite passes against this branch. Native and regular WASI are verified unchanged, not merely unchanged by construction: 59 tests green and no API breakage against #4.Notes for review: every gate is a capability gate (
hasFeature(Embedded)orcanImport), never a platform check; there is noos(WASI)anywhere in this stack. No SwiftPM traits, no versioned manifest, no tools-version bump, no new dependencies.