Skip to content

Commit 4dae104

Browse files
committed
feat: Add support for wasm when using in-memory-only sqlite database
1 parent 062386d commit 4dae104

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
unit-tests:
1717
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
1818
secrets: inherit
19+
with:
20+
with_wasm: true
1921

2022
# Make sure downstream dependents still work
2123
dependents-check:

Package@swift-5.9.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// swift-tools-version:5.9
22
import PackageDescription
33

4+
/// This list matches the [supported platforms on the Swift 5.10 release of SPM](https://github.com/swiftlang/swift-package-manager/blob/release/5.10/Sources/PackageDescription/SupportedPlatforms.swift#L34-L71)
5+
/// Don't add new platforms here unless raising the swift-tools-version of this manifest.
6+
let allPlatforms: [Platform] = [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS, .driverKit, .linux, .windows, .android, .wasi, .openbsd]
7+
let nonWASIPlatforms: [Platform] = allPlatforms.filter { $0 != .wasi }
8+
let wasiPlatform: [Platform] = [.wasi]
9+
410
let package = Package(
511
name: "sqlite-kit",
612
platforms: [
@@ -13,16 +19,23 @@ let package = Package(
1319
.library(name: "SQLiteKit", targets: ["SQLiteKit"]),
1420
],
1521
dependencies: [
16-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
17-
.package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.9.0"),
18-
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.3"),
19-
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
22+
.package(url: "https://github.com/PassiveLogic/nio-async-runtime.git", from: "1.0.0"),
23+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.89.0"),
24+
25+
// TODO: SM: Update below once everything is merged and release to the proper repositories
26+
// .package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.9.0"),
27+
.package(url: "https://github.com/PassiveLogic/sqlite-nio.git", branch: "feat/swift-wasm-support-v2"),
28+
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.33.1"),
29+
// .package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
30+
.package(url: "https://github.com/PassiveLogic/async-kit.git", branch: "feat/swift-wasm-support-v2"),
2031
],
2132
targets: [
2233
.target(
2334
name: "SQLiteKit",
2435
dependencies: [
2536
.product(name: "NIOFoundationCompat", package: "swift-nio"),
37+
.product(name: "NIOAsyncRuntime", package: "nio-async-runtime", condition: .when(platforms: wasiPlatform)),
38+
.product(name: "NIOPosix", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)),
2639
.product(name: "AsyncKit", package: "async-kit"),
2740
.product(name: "SQLiteNIO", package: "sqlite-nio"),
2841
.product(name: "SQLKit", package: "sql-kit"),

Sources/SQLiteKit/SQLiteConnectionSource.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import Foundation
55
#endif
66
import Logging
77
import AsyncKit
8+
#if canImport(NIOAsyncRuntime)
9+
import NIOAsyncRuntime
10+
#elseif canImport(NIOPosix)
811
import NIOPosix
12+
#endif
913
import SQLiteNIO
1014
import NIOCore
1115

@@ -16,7 +20,13 @@ public struct SQLiteConnectionSource: ConnectionPoolSource, Sendable {
1620
private let threadPool: NIOThreadPool
1721

1822
private var connectionStorage: SQLiteConnection.Storage {
23+
#if os(WASI)
24+
// NOTE: File urls and paths cause runtime errors currently. Currently using
25+
// in-memory connection for WASI targets.
26+
.memory
27+
#else
1928
.file(path: self.actualURL.absoluteString)
29+
#endif
2030
}
2131

2232
/// Create a new ``SQLiteConnectionSource``.

0 commit comments

Comments
 (0)