Skip to content

build: Elide NIOPosix for WASI platforms only#3485

Merged
Lukasa merged 1 commit intoapple:mainfrom
PassiveLogic:build/elideNIOPosixFromWasmBuilds
Jan 23, 2026
Merged

build: Elide NIOPosix for WASI platforms only#3485
Lukasa merged 1 commit intoapple:mainfrom
PassiveLogic:build/elideNIOPosixFromWasmBuilds

Conversation

@scottmarchant
Copy link
Copy Markdown
Contributor

Motivation:

Packages that consume NIOPosix should be able to compile to WASI platforms without special configurations. This change elides the NIOPosix source from WASI platforms to simplify configuration.

Without this change:

dependencies: [
    // Without this PR, downstream packages must maintain exhaustive platform list to exclude `.wasi`:
    .product(
        name: "NIOPosix",
        package: "swift-nio",
        condition: .when(platforms: [
            .macOS,
            .macCatalyst,
            .iOS,
            .tvOS,
            .watchOS,
            .visionOS,
            .driverKit,
            .linux,
            .windows,
            .android,
            .openbsd,
            // .wasi // <-- Need to exclude this, because there is no exclusion list api for SPM conditionals
        ])
    ),
]

With this change:

dependencies: [
    // Without this PR, downstream packages can consume NIOPosix simply:
    .product(name: "NIOPosix", package: "swift-nio"),
]

Modifications:

  • Add compiler directives (#if !os(WASI)) to all source files in NIOPosix

Result:

Downstream packages can compile to wasm without manually excluding the NIOPosix dependency.

Testing performed

  • Verified swift build --swift-sdk wasm32-unknown-wasip1 --target NIOPosix compiles, which demonstrates proper elision of source files in NIOPosix that aren't wasm-ready.
  • Confirmed GitHub checks pass.

@scottmarchant scottmarchant marked this pull request as ready for review January 20, 2026 00:27
@scottmarchant scottmarchant force-pushed the build/elideNIOPosixFromWasmBuilds branch from b42907b to 08cead2 Compare January 22, 2026 18:09
…only. This simplifies dependency chain consumption of NIOPosix and NIOAsyncRuntime side-by-side. Eliminates the need for downstream packages to use compilation conditions.
@scottmarchant scottmarchant force-pushed the build/elideNIOPosixFromWasmBuilds branch from 08cead2 to f9ffa9b Compare January 22, 2026 19:22
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Jan 23, 2026
@Lukasa Lukasa enabled auto-merge (squash) January 23, 2026 16:17
@Lukasa Lukasa merged commit 5bf0267 into apple:main Jan 23, 2026
55 checks passed
@scottmarchant scottmarchant deleted the build/elideNIOPosixFromWasmBuilds branch January 23, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants