diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23cb57e..9f31477 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,6 +16,8 @@ jobs: unit-tests: uses: vapor/ci/.github/workflows/run-unit-tests.yml@main secrets: inherit + with: + with_wasm: true # Make sure downstream dependents still work dependents-check: diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift index ae4fbb4..5ee98de 100644 --- a/Package@swift-5.9.swift +++ b/Package@swift-5.9.swift @@ -1,6 +1,12 @@ // swift-tools-version:5.9 import PackageDescription +/// 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) +/// Don't add new platforms here unless raising the swift-tools-version of this manifest. +let allPlatforms: [Platform] = [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .visionOS, .driverKit, .linux, .windows, .android, .wasi, .openbsd] +let nonWASIPlatforms: [Platform] = allPlatforms.filter { $0 != .wasi } +let wasiPlatform: [Platform] = [.wasi] + let package = Package( name: "sqlite-kit", platforms: [ @@ -13,16 +19,23 @@ let package = Package( .library(name: "SQLiteKit", targets: ["SQLiteKit"]), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"), - .package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.9.0"), - .package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.3"), - .package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"), + .package(url: "https://github.com/PassiveLogic/nio-async-runtime.git", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.89.0"), + + // TODO: SM: Update below once everything is merged and release to the proper repositories +// .package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.9.0"), + .package(url: "https://github.com/PassiveLogic/sqlite-nio.git", branch: "feat/swift-wasm-support-v2"), + .package(url: "https://github.com/vapor/sql-kit.git", from: "3.33.1"), +// .package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"), + .package(url: "https://github.com/PassiveLogic/async-kit.git", branch: "feat/swift-wasm-support-v2"), ], targets: [ .target( name: "SQLiteKit", dependencies: [ .product(name: "NIOFoundationCompat", package: "swift-nio"), + .product(name: "NIOAsyncRuntime", package: "nio-async-runtime", condition: .when(platforms: wasiPlatform)), + .product(name: "NIOPosix", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)), .product(name: "AsyncKit", package: "async-kit"), .product(name: "SQLiteNIO", package: "sqlite-nio"), .product(name: "SQLKit", package: "sql-kit"), diff --git a/Sources/SQLiteKit/SQLiteConnectionSource.swift b/Sources/SQLiteKit/SQLiteConnectionSource.swift index e327a50..c15eb43 100644 --- a/Sources/SQLiteKit/SQLiteConnectionSource.swift +++ b/Sources/SQLiteKit/SQLiteConnectionSource.swift @@ -5,7 +5,11 @@ import Foundation #endif import Logging import AsyncKit +#if canImport(NIOAsyncRuntime) +import NIOAsyncRuntime +#elseif canImport(NIOPosix) import NIOPosix +#endif import SQLiteNIO import NIOCore @@ -16,7 +20,13 @@ public struct SQLiteConnectionSource: ConnectionPoolSource, Sendable { private let threadPool: NIOThreadPool private var connectionStorage: SQLiteConnection.Storage { + #if os(WASI) + // NOTE: File urls and paths cause runtime errors currently. Currently using + // in-memory connection for WASI targets. + .memory + #else .file(path: self.actualURL.absoluteString) + #endif } /// Create a new ``SQLiteConnectionSource``.