Skip to content

Fix the build without the ExperimentalIO trait - #103

Merged
FranzBusch merged 1 commit into
swiftlang:mainfrom
jakepetroules:fix-build-without-experimental-io
Nov 12, 2026
Merged

FranzBusch merged 1 commit into
swiftlang:mainfrom
jakepetroules:fix-build-without-experimental-io

Conversation

@jakepetroules

Copy link
Copy Markdown
Contributor

Since #91, the package no longer builds with its default traits on Linux. PThreadTaskExecutor.current() reads PThread.currentExecutor, which PThread.swift declares only under #if ExperimentalIO && !os(WASI), while current() itself is not gated:

Sources/PlatformExecutors/PThread/PThreadTaskExecutor.swift:246:37: error: type 'PThread' has no member 'currentExecutor'
244 |   /// one if the calling thread is not one of the pool.
245 |   internal func current() -> PThreadExecutor {
246 |     if let pointer = unsafe PThread.currentExecutor {
    |                                     `- error: type 'PThread' has no member 'currentExecutor'

Every caller of current() is in the ExperimentalIO-only PThreadTaskExecutor+*Operations.swift files, so this gates it the same way as PThread.currentExecutor.

CI didn't catch this because both Linux jobs build with --traits ExperimentalIO or --traits ExperimentalIOUring. A job that builds with the default traits would keep this configuration from regressing.

Tested on Linux (Swift 6.4, aarch64): swift build with no traits succeeds, and an executable with typealias DefaultExecutorFactory = PlatformExecutorFactory gets PThreadTaskExecutor as its global executor, sized to the cgroup's CPU limit.

`PThreadTaskExecutor.current()` reads `PThread.currentExecutor`, which
exists only with the `ExperimentalIO` trait, so the package failed to
build with its default traits. Every caller of `current()` is in the
`ExperimentalIO`-only operation extensions, so gate it the same way as
`PThread.currentExecutor`.
@FranzBusch
FranzBusch merged commit 7841c1e into swiftlang:main Nov 12, 2026
19 of 21 checks passed
@jakepetroules
jakepetroules deleted the fix-build-without-experimental-io branch November 12, 2026 10:15
FranzBusch pushed a commit that referenced this pull request Nov 12, 2026
On musl, such as with the Static Linux SDK, and on Android, the package
fails to build with its default traits:

```
Sources/PlatformExecutors/PThread/Internal/IO/PlatformIOBackend.swift:15:8: error: Unsupported platform
```

On Android the C shim and the C library imports fail before that.

**musl.** The epoll I/O backend, and the eventfd and timerfd wrappers it
uses, are selected with `canImport(Glibc)` alone, so on musl no backend
is available. The first commit selects them for `Musl` as well, the same
way most of the package already handles both C libraries, and gives
`SystemCoreCount`'s Musl import the `@unsafe` its Glibc import already
has, which strict memory safety otherwise rejects.

**Android.** The pthread executors are compiled for Android, but no C
library is imported there. The second commit:

- imports the `Android` module wherever `Glibc` and `Musl` are imported
outside the `ExperimentalIO` code, and selects the epoll backend and the
pthread `PlatformExecutorFactory` for Android;
- marks creating a `pthread_attr_t` `unsafe` on Android, since Bionic's
holds a pointer;
- coerces the thread function to whichever `pthread_create`
start-routine signature the NDK declares (NDK 28 made it nullable), the
way swift-nio's `ThreadPosix.swift` does;
- adds the headers the C shim's Android `pthread_getname_np` emulation
uses.

The io_uring backend stays Glibc-only, and the `ExperimentalIO`-only
files are unchanged.

Tested with the Swift 6.4.2 SDKs, together with #103, since `main` does
not currently build without `ExperimentalIO`:

- Static Linux SDK (aarch64-swift-linux-musl): the package builds with
its default traits, and a static executable with `typealias
DefaultExecutorFactory = PlatformExecutorFactory` gets
`PThreadTaskExecutor` as its global executor, sized to the cgroup's CPU
limit.
- Android SDK (aarch64-unknown-linux-android28,
x86_64-unknown-linux-android28, NDK 30): the package builds with its
default traits. I have not run it on a device.
- glibc (Linux, aarch64): unchanged; builds and runs as before.

I don't have the toolchain the `ExperimentalIO` trait needs, so the
`ExperimentalIO` paths in the changed files are not covered on musl or
Android.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants