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
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.
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
from
July 29, 2026 03:24
84ccd33 to
7923233
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.
Makes SQLiteNIO compile under Embedded Swift. This builds on #4 (
feat/wasi-nio-free) and retargets tobase/vapor-mainonce 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-flavorcanImport, so no other configuration changes at all:SQLiteData'sEncodableconformance moves to a conditional extension, and the deprecatedSQLiteDataType.serialize(_:)is elided; Embedded Swift has noEncoderand noany Encodable.asyncwithConnection(_:)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 makeany SQLiteDatabaseunusable there. The concreteSQLiteConnection.withConnection(_:)remains.SQLiteError: LocalizedError, theDatabridges, and theDatebridge gate oncanImport(FoundationEssentials) || canImport(Foundation); Embedded Swift has neither flavor. TheerrorDescriptionwitness stays in the type body, so only the conformance is conditional.SQLiteRow.descriptionandSQLiteCustomFunction's error reporting rely on reflection (Array.description,any Errorinterpolation); 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, andArray.descriptionare all@_unavailableInEmbedded), so the build dies insideLoggingbefore 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 upstreamapple/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-embeddedand the patched swift-log. Native (59 tests) and regular WASI are unchanged by construction, since every gate here is false outside Embedded Swift.