Skip to content

Commit 84ba06c

Browse files
committed
Elide SwiftNIO on WASI
Motivation: SwiftNIO cannot be built for `wasm32-unknown-wasip1`, so SQLKit currently fails to configure for that platform at all — the failure is in dependency resolution, before any of the conditional sources in the previous commit get a chance to matter. Modifications: Gate the NIOCore product on `.when(platforms: nonWASIPlatforms)`. Target dependency conditions are evaluated per platform, so on WASI the product is simply not linked and the `canImport(NIOCore)` gates select the `async` API. `.when(platforms:)` can only include, never exclude, so excluding one platform means enumerating the others; the list is the set SPM 6.1 knows about, noted as such so it is not extended without also raising the manifest's tools version. The test target's NIOCore and NIOEmbedded dependencies are gated the same way; the suite exercises the `EventLoopFuture` API and is not run on WASI. Result: On every other platform the resolved dependency set is byte-identical to before. On WASI the build graph contains no SwiftNIO module — not NIOPosix, not NIOCore, not NIOConcurrencyHelpers.
1 parent fa5722b commit 84ba06c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Package.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// swift-tools-version:6.1
22
import PackageDescription
33

4+
/// This list matches the [supported platforms on the Swift 6.1 release of SPM](https://github.com/swiftlang/swift-package-manager/blob/release/6.1/Sources/PackageDescription/SupportedPlatforms.swift).
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+
49
let package = Package(
510
name: "sql-kit",
611
platforms: [
@@ -24,7 +29,11 @@ let package = Package(
2429
dependencies: [
2530
.product(name: "Collections", package: "swift-collections"),
2631
.product(name: "Logging", package: "swift-log"),
27-
.product(name: "NIOCore", package: "swift-nio"),
32+
// SwiftNIO does not support wasm32-unknown-wasip1. Target dependency conditions
33+
// are evaluated per platform, so on WASI NIOCore is simply not linked and the
34+
// `EventLoopFuture` surface drops out via `#if canImport(NIOCore)`; the async
35+
// surface is unaffected.
36+
.product(name: "NIOCore", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)),
2837
],
2938
swiftSettings: swiftSettings
3039
),
@@ -38,8 +47,9 @@ let package = Package(
3847
.testTarget(
3948
name: "SQLKitTests",
4049
dependencies: [
41-
.product(name: "NIOCore", package: "swift-nio"),
42-
.product(name: "NIOEmbedded", package: "swift-nio"),
50+
// The test suite exercises the SwiftNIO surface, so it is not built for WASI.
51+
.product(name: "NIOCore", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)),
52+
.product(name: "NIOEmbedded", package: "swift-nio", condition: .when(platforms: nonWASIPlatforms)),
4353
.target(name: "SQLKit"),
4454
.target(name: "SQLKitBenchmark"),
4555
],

0 commit comments

Comments
 (0)