mirror of
https://github.com/apple/swift-nio
synced 2026-11-22 04:30:41 +00:00
## Motivation Follow-up to #3663 (which got the "low-hanging" test targets compiling on Windows). This finishes the job by getting the **last two** test targets — `NIOPosixTests` and `NIOFoundationCompatTests` — compiling on Windows, so **all 16 test targets now build**, and switches Windows CI to `swift build --build-tests`. These are **compile-only** changes: the goal is compilation, not runtime pass. Verified by building on a Windows ARM64 VM with `swift build --build-tests`. ## What's here 1. **Compile `NIOFoundationCompatTests`** — the target imports the `NIO` umbrella (in `WaitSpinningRunLoopTests`, for `MultiThreadedEventLoopGroup`) but only declared `NIOCore`/`NIOFoundationCompat` as dependencies. `NIO` re-exports `NIOPosix`, which imports the `CNIOPosix` **C module**; Linux/macOS resolve that transitively, but on Windows the C-module map isn't in the target's search path unless declared, giving the opaque `<unknown>:0: error: missing required module 'CNIOPosix'`. Fix: declare the `NIO` dependency it actually uses. 2. **Compile `NIOPosixTests`** — the deeply-POSIX target. Gate-out-plus-minimal-shim: - `import WinSDK` where only `sockaddr`/`timeval`/`in_addr` field or type access was missing (`MemberImportVisibility`) — this alone cleared the two largest files (`SocketAddressTest`, `HappyEyeballsTest`). - Real fixes where cheap: `pipe` → `_pipe` (via `ucrt`), an `STDOUT_FILENO` shim, `Thread.sleep` instead of `sleep`, and letting `IOResult` type inference pick `ssize_t`. - `#if !os(Windows)` gating (per-method where possible, to preserve Windows-compilable coverage) for genuinely-unavailable APIs: `fcntl`/`O_NONBLOCK`/`O_ASYNC`/`F_GETFL`/`F_SETFL`, `Posix.fcntl`, `Posix.socketpair`, the integer socket-option API (`ChannelOptions.socket`, `SOL_SOCKET`, `SO_REUSEADDR`, `so_timestamp`), `poll`/`pollfd`, `cmsg`/`msghdr` construction, `NonBlockingFileIO.lstat`/`symlink`/`listDirectory`/`createDirectory`, vsock CID/connect tests, `/dev/null` syscall-wrapper perf tests, and socket-handle (`NIOBSDSocket.Handle` `UInt64` vs `CInt`) mismatches. - Whole-file gating only where a file is pervasively unsupported: the SAL mock harness and its dependents (`SyscallAbstractionLayer[Context]`, `SALChannelTests`, `SALEventLoopTests`) — it's built on `CInt` fds and can't compile against Windows's `UInt64` socket handles without a larger rework; `ControlMessageTests` (POSIX `msghdr`/control-message throughout); and `MulticastTest` (deprecated `enumerateInterfaces`/`NIONetworkInterface`). 3. **Build the test targets in CI** — change the Windows matrix command from `swift build` to `swift build --build-tests` in `main.yml` and `pull_request.yml`. ## Notes for reviewers - No behavior change off Windows: every edit is behind `#if os(Windows)` / `#if !os(Windows)`; the few shared-line changes (`Thread.sleep`, `IOResult` inference, an IUO force-unwrap of `msg_name`) are identical on POSIX. - The tests are **compiled, not run** on Windows yet. Running them needs real Winsock work (socket handle types, etc.) and is the natural next step. --------- Co-authored-by: George Barnett <gbarnett@apple.com>