From 133f502404fa0cd1d6caaa79789e094aba02d055 Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Mon, 5 May 2025 15:22:58 -0600 Subject: [PATCH 1/4] feat: Enable wasm compilation. --- .github/workflows/test.yml | 2 ++ Package.swift | 8 +++++--- .../ConnectionPool/EventLoopGroupConnectionPool.swift | 6 ++++++ Sources/AsyncKit/Exports.swift | 2 -- Tests/AsyncKitTests/ConnectionPoolTests.swift | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35fd90a..50cfcd1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,3 +14,5 @@ jobs: unit-tests: uses: vapor/ci/.github/workflows/run-unit-tests.yml@main secrets: inherit + with: + with_wasm: true diff --git a/Package.swift b/Package.swift index c6ef132..8d55345 100644 --- a/Package.swift +++ b/Package.swift @@ -13,10 +13,11 @@ let package = Package( .library(name: "AsyncKit", targets: ["AsyncKit"]), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio.git", from: "2.61.0"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.89.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.5.3"), .package(url: "https://github.com/apple/swift-collections.git", from: "1.0.5"), .package(url: "https://github.com/apple/swift-algorithms.git", from: "1.1.0"), + .package(url: "https://github.com/PassiveLogic/swift-dispatch-async.git", from: "0.0.1"), ], targets: [ .target( @@ -24,10 +25,9 @@ let package = Package( dependencies: [ .product(name: "Logging", package: "swift-log"), .product(name: "NIOCore", package: "swift-nio"), - .product(name: "NIOEmbedded", package: "swift-nio"), - .product(name: "NIOPosix", package: "swift-nio"), .product(name: "Collections", package: "swift-collections"), .product(name: "Algorithms", package: "swift-algorithms"), + .product(name: "DispatchAsync", package: "swift-dispatch-async", condition: .when(platforms: [.wasi])) ], swiftSettings: swiftSettings ), @@ -35,6 +35,8 @@ let package = Package( name: "AsyncKitTests", dependencies: [ .target(name: "AsyncKit"), + .product(name: "NIOEmbedded", package: "swift-nio"), + .product(name: "NIOPosix", package: "swift-nio"), ], swiftSettings: swiftSettings ), diff --git a/Sources/AsyncKit/ConnectionPool/EventLoopGroupConnectionPool.swift b/Sources/AsyncKit/ConnectionPool/EventLoopGroupConnectionPool.swift index 3c79b8f..7b626f8 100644 --- a/Sources/AsyncKit/ConnectionPool/EventLoopGroupConnectionPool.swift +++ b/Sources/AsyncKit/ConnectionPool/EventLoopGroupConnectionPool.swift @@ -1,4 +1,8 @@ +#if canImport(Dispatch) import Dispatch +#elseif canImport(DispatchAsync) +import DispatchAsync +#endif import NIOConcurrencyHelpers import NIOCore import struct Logging.Logger @@ -280,6 +284,7 @@ public final class EventLoopGroupConnectionPool where Source: Connection } } + #if !os(WASI) /// Closes the connection pool. /// /// All available connections will be closed immediately. Any connections still in use will be @@ -312,6 +317,7 @@ public final class EventLoopGroupConnectionPool where Source: Connection } } } + #endif // !os(WASI) /// Closes the connection pool. /// diff --git a/Sources/AsyncKit/Exports.swift b/Sources/AsyncKit/Exports.swift index ebee4eb..cd74a01 100644 --- a/Sources/AsyncKit/Exports.swift +++ b/Sources/AsyncKit/Exports.swift @@ -1,6 +1,4 @@ -@_documentation(visibility: internal) @_exported import class NIOEmbedded.EmbeddedEventLoop @_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoop @_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoopGroup @_documentation(visibility: internal) @_exported import class NIOCore.EventLoopFuture @_documentation(visibility: internal) @_exported import struct NIOCore.EventLoopPromise -@_documentation(visibility: internal) @_exported import class NIOPosix.MultiThreadedEventLoopGroup diff --git a/Tests/AsyncKitTests/ConnectionPoolTests.swift b/Tests/AsyncKitTests/ConnectionPoolTests.swift index 8f04016..339677f 100644 --- a/Tests/AsyncKitTests/ConnectionPoolTests.swift +++ b/Tests/AsyncKitTests/ConnectionPoolTests.swift @@ -4,6 +4,7 @@ import Logging import NIOConcurrencyHelpers import NIOCore import NIOEmbedded +import class NIOPosix.MultiThreadedEventLoopGroup import XCTest final class ConnectionPoolTests: AsyncKitTestCase { From b4ce751cfb3fc3477890782db4f5c7b7ed5bb0d1 Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Mon, 15 Dec 2025 15:09:08 -0700 Subject: [PATCH 2/4] build: Use canImports to conditionalize exporting of NIOEmbedded and NIOPosix, to avoid breaking changes while allowing wasm to compile. --- Sources/AsyncKit/Exports.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/AsyncKit/Exports.swift b/Sources/AsyncKit/Exports.swift index cd74a01..9af4c73 100644 --- a/Sources/AsyncKit/Exports.swift +++ b/Sources/AsyncKit/Exports.swift @@ -1,4 +1,10 @@ +#if canImport(NIOEmbedded) +@_documentation(visibility: internal) @_exported import class NIOEmbedded.EmbeddedEventLoop +#endif @_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoop @_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoopGroup @_documentation(visibility: internal) @_exported import class NIOCore.EventLoopFuture @_documentation(visibility: internal) @_exported import struct NIOCore.EventLoopPromise +#if canImport(NIOPosix) +@_documentation(visibility: internal) @_exported import class NIOPosix.MultiThreadedEventLoopGroup +#endif From 7d9f8fce64c35a7cb3777ec7cca1b2e5a51f277f Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Mon, 15 Dec 2025 15:15:08 -0700 Subject: [PATCH 3/4] build: Conditionalize inclusion of NIOPosix and NIOEmbedded in manifest to only be included for non-wasi platforms. --- Package.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 8d55345..03b3f8a 100644 --- a/Package.swift +++ b/Package.swift @@ -1,6 +1,12 @@ // swift-tools-version:5.10 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: "async-kit", platforms: [ @@ -25,9 +31,11 @@ let package = Package( dependencies: [ .product(name: "Logging", package: "swift-log"), .product(name: "NIOCore", package: "swift-nio"), + .product(name: "NIOEmbedded", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)), + .product(name: "NIOPosix", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)), .product(name: "Collections", package: "swift-collections"), .product(name: "Algorithms", package: "swift-algorithms"), - .product(name: "DispatchAsync", package: "swift-dispatch-async", condition: .when(platforms: [.wasi])) + .product(name: "DispatchAsync", package: "swift-dispatch-async", condition: .when(platforms: wasiPlatform)) ], swiftSettings: swiftSettings ), From f230f361a5a56223788efcbf2908172d6228843b Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Mon, 15 Dec 2025 18:00:51 -0700 Subject: [PATCH 4/4] build: Require at least the 1.0.0 version of nio-async-runtime --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 03b3f8a..51a9981 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( .package(url: "https://github.com/apple/swift-log.git", from: "1.5.3"), .package(url: "https://github.com/apple/swift-collections.git", from: "1.0.5"), .package(url: "https://github.com/apple/swift-algorithms.git", from: "1.1.0"), - .package(url: "https://github.com/PassiveLogic/swift-dispatch-async.git", from: "0.0.1"), + .package(url: "https://github.com/PassiveLogic/swift-dispatch-async.git", from: "1.0.0"), ], targets: [ .target(