Commit Graph
2949 Commits
Author SHA1 Message Date
Cory Benfield f2ebedb36a The formatter changed its mind (#3379) 2025-09-23 14:58:24 +01:00
Rick Newton-Rogers 154706efd3 Matrix custom env vars (#3376)
Allow the specification of custom environment variables in our matrix
workflow and those which use it.

### Motivation:

It can be useful to supply custom environment variables to control build
and runtime options.

### Modifications:

Allow users to supply a string of custom environment variable key-value
pairs which are supplied to the docker container running the matrix
commands.

To attempt to avoid issues with this string concatenation the change
also allows the user to specify custom list entry and key-value-pair
separators.

To avoid parameter bloat the env vars are set for all Swift versions,
hopefully that's sufficient for now.

### Result:

Adopters can 

Examples of this working on Linux and Windows, note the presence of the
test environment variables I injected:
-
https://github.com/apple/swift-nio/actions/runs/17917619451/job/50943847555?pr=3376
- https://github.com/apple/swift-crypto/pull/413/checks

e.g. 
```
Executing Docker command: docker run -v /home/runner/work/swift-nio/swift-nio:/swift-nio -w /swift-nio -e CI=true -e GITHUB_ACTIONS=true -e SWIFT_VERSION=6.0 -e workspace=/swift-nio -e TEST_DEBUG=1 -e TEST_LOG_LEVEL=info swift:6.0-jammy bash -c swift --version && swift test -Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error
```
2.86.1
2025-09-22 16:06:47 +01:00
Fabian Fett 6c114e3c62 Update CI scripts for 6.2 (#3374)
Replaces: #3373
2025-09-19 13:55:48 +01:00
Rick Newton-Rogers 325c3231cf Add Xcode 26.0, 16.4 CI, remove 16.2 (#3375)
### Motivation:

New Xcodes are out so we should test with them.

### Modifications:

Update the macOS matrix generation script

### Result:

Add Xcode 26.0, 16.4 CI, remove 16.2 jobs by default.

CI with the new Xcodes working (except 26.0 which will come online as
nodes recycle
https://github.com/apple/swift-nio/actions/runs/17834807139/job/50709176060?pr=3375)
2025-09-19 09:30:08 +01:00
George Barnett 2550c9ed48 Remove NIOFileSystem from products (#3370)
Motivation:

NIOFileSystem has a few APIs which expose swift-system. We'll need to
replace those before making this API stable.

Modifications:

- Remove NIOFileSystem product
- Modify snippet so that it still builds

Result:

NIOFileSystem isn't yet public API
2025-09-08 15:31:15 +01:00
Fabian Fett 5679824930 [Windows] Ensure WSAStartup is correctly called. (#3366)
### Motivation

- `WSAStartup` isn't called

### Changes

- Change stuff that I have very little idea about until it works

### Result

WSAStartup is now emitted at the correct location for the linker to be
picked up.
2025-09-03 16:16:21 +00:00
George Barnett 66a85ba0e2 Add back _NIOFileSystem (#3367)
Motivation:

In #3363 we converted `_NIOFileSystem` to `NIOFileSystem` and removed
the (unreleased) overloads for FilePath/NIOFilePath. This change adds
back `_NIOFileSystem` such that it matches the API it had at 2.86.0.

Modifications:

- Add back `_NIOFileSystem` and `_NIOFileSystemFoundationCompat` such
that their API is at 2.86.0

Result:

- `NIOFileSystem` uses `NIOFilePath`
- `_NIOFileSystem` uses `FilePath`
2025-09-02 14:56:58 +01:00
Fabian Fett e95d742160 [Windows] Reimplement pwrite (#3364)
Very much like #3361. Just for writing.

Result: NIOPosix compiles on Windows.
2025-09-01 16:12:41 +02:00
Fabian Fett db4d4c2566 [Windows] Sleep instead of WSAPoll, if no outstanding IO (#3365) 2025-09-01 10:55:18 +00:00
George Barnett 7290551b7f Add a NIOFilePath based NIOFileSystem (#3363)
Motivation:

We changed the file path type in `_NIOFileSystem` to use `NIOFilePath`
instead of `FilePath`. Originally we planned to use API shims to avoid
breaking API, however in some cases this was inevitable (i.e. where a
file path is returned to the caller).

To roll over to the new API we will instead introduce the
`NIOFileSystem` module using `NIOFilePath` and have `_NIOFileSystem` use
`FilePath`. Users can then opt-in to the new stable API rather than
having it forced upon them.

The first wave of these changes turns `_NIOFileSystem` into
`NIOFileSystem` and uses `NIOFilePath` for its APIs.

Modifications:

- Remove disfavoured overloads (i.e. `FilePath` APIs)
- Update the `DirectoryEntry` API to use `NIOFilePath`.
- Update tests to use `NIOFilePath` since many were relying on the newly
removed shims
- Remove the underscore from the module names and products
- Remove deprecated methods

A follow up change will re-instate the `_NIOFileSystem` (and compat)
module and products using `FilePath`.

Result:

`NIOFileSystem` has a stable API.
2025-09-01 08:11:14 +01:00
Fabian Fett 5bf5054a83 [Windows] Reimplement pread (#3361)
- pread does not exist in ucrt. We need to reimplement it using read and
lseek.
- `FileDescriptor.setNonBlocking` is currently not needed in Windows to
compile. Let's not compile it.
- Set up correct sys calls for lseek and ftruncate
2025-08-29 13:39:04 +01:00
Fabian Fett c26397c5b4 [Windows] Make SelectorGeneric compile on Windows (#3359)
This is very half implemented, but it makes SelectorGeneric compile on
Windows. So that's a step forward, isn't it?
2025-08-28 16:44:55 +00:00
Fabian Fett 663b627102 [Windows] Return false from concurrency takeover (#3362)
Follow up to #3347. comment:
https://github.com/apple/swift-nio/pull/3347/files#r2307432411
2025-08-28 14:09:36 +00:00
Johannes Weiss f656af6b79 SelectableEventLoop.debugDescription: fix debugDescription deadlock (#3360)
### Motivation:

In #3297, I introduced a deadlock involving `SelectableEventLoop`'s
`debugDescription`. I was under the impression that it's not possible to
call this from outside the `NIO` module so I deemed it safe. That was a
mistake :).

### Modifications:

- Make it impossible to deadlock around
`SelectableEventLoop.debugDescription`.

### Result:

- Fewer deadlocks
2025-08-28 13:08:45 +01:00
Fabian Fett e8c1d6e09b [Windows] Disable Pipelines for now (fatalError) (#3358)
### Motivation

In Linux we can use `epoll` to observe sockets and pipes. WSAPoll sadly
only works for sockets. To observe pipes in Windows we can use
`WaitForMultipleObjects`. However we should try to get to a place where
we can start to fix tests first.

### Changes

- fatalError all pipe functions that do not compile right now.
2025-08-26 12:08:14 +00:00
Fabian Fett aff71b37f5 [Windows] Use recv instead of read (#3357) 2025-08-26 10:30:46 +00:00
Fabian Fett 0878179234 [Windows] Allow _SelectorBackendProtocol to work with Windows Handles (#3356)
`_SelectorBackendProtocol` currently requires the file descriptors to be
of `CInt` (aka Int32). However Windows HANDLES are pointers therefore
`UInt64`s. Let's use the typealias that we already have
`NIOBSDSocket.Handle`.
2025-08-26 12:06:59 +02:00
George Barnett 9b2642c21b Use path based deps in the alloc counter framework (#3355)
The alloc counter framework uses `url` based deps for local
dependencies. They should use `path` instead.
2025-08-22 11:14:33 +01:00
Fabian Fett 148589720a [Windows] Add shims to make string from GetLastError using FormatMessage (#3353)
If we receive a functions error via `GetLastError`, we can stringify it
via `FormatMessage`. Sadly `FormatMessage` isn't auto imported into
Swift, which is why we need to use the shim layer.
2025-08-19 14:31:06 +00:00
Fabian Fett 9cde8e3a00 [Windows] dup is deprecated on Windows, use _dup instead (#3352) 2025-08-19 13:21:59 +00:00
Fabian Fett 456921a854 [Windows] Fix getenv warnings in NIOPosix and NIOEmbedded (#3351)
Less yellow code.
2025-08-19 12:48:46 +00:00
Fabian FettandGeorge Barnett 806a7276b1 [Windows] Use WSASend as writev equivalent (#3350)
See title. `writev` does not exist in Windows land.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-08-19 12:20:43 +00:00
Fabian Fett 54b0dc09ca [Windows] Make SocketChannel.swift compile (#3348)
- vsock isn't supported on windows.
- creating `in_addr` needs conditional compiling
2025-08-19 10:37:12 +00:00
Fabian Fett 3bf9c1bd2c [Windows] fatalError concurrency takeover (#3347)
To make further progress, let's disable the concurrency takeover feature
for now.
2025-08-18 10:50:40 +00:00
Fabian Fett 93102a85ee [Windows] Fix deprecation warnings in NIOCore (#3345)
- `getenv` and `strerror` are deprecated in Windows land
- replace with undeprecated alternatives
- result: less yellow in the build log
2025-08-14 14:04:40 +01:00
Fabian Fett 5dca91e191 [Windows] Make SelectableEventLoop compile (#3344)
- Add overwrite for `write` method that calls undeprecated `_write`
- Add errno global readonly variable
2025-08-13 09:18:50 +00:00
Fabian Fett 357ff9f16e [Windows] Map naming conventions Windows -> Posix (ssize_t) (#3343)
`ssize_t` doesn't exist in Windows land. Windows loves uppercase naming.
Therefore we need a typealias.
2025-08-12 17:37:00 +00:00
Fabian FettandCory Benfield d21f56b4bd [Windows] Make ControlMessage.swift compile (#3342)
See title.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-08-12 15:36:19 +00:00
Fabian Fett a8b744cb61 [Windows] Make Thread.swift compile (#3341)
See title.
2025-08-12 16:11:18 +01:00
George BarnettandCory Benfield a65e9735ac Drop all server response parts after an invalid header (#3339)
Motivation:

NIOHTTPResponseHeadersValidator drops head/end response parts if they
contain invalid header fields. If a head part is dropped and the server
allows pipelining then the subsequent body/end part will reach the
pipelining handler and result in an assertion failure in debug builds.
In release builds, some parts may be incorrectly written out leading to
protocol violations.

Modifications:

- Drop all response parts after an invalid response part

Result:

- Fewer bugs
- Resolves #3326

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-08-12 09:33:24 +00:00
Fabian FettandCory Benfield 2c9b7c6061 [Windows] Ensure NIOHTTP1 compiles (#3338)
This only needs one `numericCast`.

Previous error:
```
C:\Users\fat\Developer\apple\swift-nio\Sources\NIOHTTP1\HTTPDecoder.swift:113:49: error: cannot convert value of type 'CUnsignedInt' (aka 'UInt32') to expected argument type 'Int32'
 111 |                 statusCode: Int(opaque!.pointee.status_code),
 112 |                 isUpgrade: opaque!.pointee.upgrade != 0,
 113 |                 method: llhttp_method(rawValue: CUnsignedInt(opaque!.pointee.method)),
     |                                                 `- error: cannot convert value of type 'CUnsignedInt' (aka 'UInt32') to expected argument type 'Int32'
 114 |                 keepAliveState: opaque!.keepAliveState
 115 |             ) {
```

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-08-11 17:20:12 +00:00
aryan-25andGeorge Barnett 8997a24524 Update FilePath references to NIOFilePath (#3333)
Motivation:

Currently, file paths are represented by the `SystemPackage.FilePath`
type in `NIOFileSystem`. Following from #3322, we want to use
`NIOFilePath` instead.

Modifications:

This change provides `NIOFilePath` accepting/returning variants to all
existing public methods that accept/return `SystemPackage.FilePath`.

The bulk of the changes are in `FileSystemProtocol` and
`FileHandleProtocol`, and their conforming types. The protocols have
been modified to require `NIOFilePath` accepting/returning methods.
Default implementations are provided for `SystemPackage.FilePath`
accepting/returning methods---these call through to the `NIOFilePath`
variants.

Result:

`NIOFilePath` path representations can now be used with the methods for
interacting with the file system.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-08-11 17:29:02 +01:00
Fabian Fett b881f6ec60 [Windows] Add msghdr extension for Windows (#3336)
To be able to compile on Windows eventually, we need to bridge msghdr
and WSAMSG. This PR tries to accomplish this by using extensions on
those types.
2025-08-11 15:49:00 +01:00
Fabian Fett 1944fd3721 [Windows] Ensure ssize_t and socklen_t are available (#3337)
See title.
2025-08-11 15:11:27 +01:00
Yuta Saito f92485e959 [wasm][2/2] Include WebAssembly SDK checks in PR and main workflows (#3332)
Add build check CI for WebAssembly SDK

### Motivation:

Add build check CI for WebAssembly SDK

### Modifications:

Add Wasm build checks in `main.yml` and `pull_request.yml` based on
https://github.com/apple/swift-nio/pull/3331

Extracted from https://github.com/apple/swift-nio/pull/3159

### Result:

Setting up the CI job makes it easier to detect such incompatibility
before merging.
2025-08-11 13:06:50 +01:00
George Barnett 6b484ecafc Make testMetricsDelegateTickInfo less flaky (#3335)
Motivation:

testMetricsDelegateTickInfo fails occasionally because there are more
event loop ticks than it expects. This is because the expectation in the
test was incorrect.

Modifications:

- Update the test expectation and an explanation of how we got to that
number.
- Shutdown the ELG while we're at it.

Result:

Tests are less flaky
2025-08-07 14:40:57 +00:00
finagolfin 4151adfff5 Add Android imports for some new tests in #3308 that require it (#3334)
My Android CI [just broke because it couldn't find these newly used C
symbols in the NIO
tests](https://github.com/finagolfin/swift-android-sdk/actions/runs/16768316992/job/47477878652#step:19:242),
this patch [fixed it
again](https://github.com/finagolfin/swift-android-sdk/actions/runs/16787226279/job/47540691932).
Unsure why this only affects Android, likely the module leaks postulated
before.
2025-08-07 10:40:51 +01:00
Klaas Pieter AnnemaandCory Benfield 1c30f0f205 Support options on AsyncTestingChannel and EmbeddedChannel (#3308)
Support options on AsyncTestingChannel and EmbeddedChannel

Fixes #3305 

### Motivation:

The channels are intended for testing purposes so while most options
have no practical use setting and getting them can be useful for
testing.

For example a traceroute implementation will set TTL to the current hop
number. Testing such an implementation requires the channels to pretend
to support the TTL option.

### Modifications:

Added option storage to AsyncTestingChannel and EmbedededChannel and
made `getOptionSync` and `setOptionSync` read and write from that
storage.

### Result:

EmbeddedChannel and AsyncTestingChannel support changing their options.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2.86.0
2025-08-05 11:37:04 +01:00
Yuta Saito a114cfb471 [wasm][1/2] Add reusable WebAssembly workflow (#3331)
Add build check CI for WebAssembly SDK

### Motivation:

Add build check CI for WebAssembly SDK

### Modifications:

Add only reusable GHA workflow from
https://github.com/apple/swift-nio/pull/3159 to gracefully merge changes
without breaking CI.

After this change being merged into main branch, we can merge the actual
PR checks: https://github.com/apple/swift-nio/pull/3331

### Result:

Setting up the CI job makes it easier to detect such incompatibility
before merging.
2025-08-04 14:10:02 +00:00
Cory Benfield 41b126283c Don't double-initialize Pipe Bootstraps (#3330)
Motivation:

In #3309 I fixed an issue where the channel initializer would not be
called in some PipeBootstrap paths. Unfortunately, that introduced a new
bug where the initializer was now called twice on some other paths.

Modifications:

Get the number of calls back to 1 on the non-async paths. Add some tests

Result:

Better pipe bootstrap behaviour.
2025-08-01 10:11:41 +00:00
Cory Benfield 6719917e49 Add bpftrace support to stackdiff (#3329)
Motivation:

I had need of it, so I did it.

Modifications:

bpftrace output parses now

Result:

Better support
2025-08-01 09:45:59 +00:00
aryan-25andGeorge Barnett 96fbe40aae Add a new file path type, NIOFilePath, backed by SystemPackage's FilePath type (#3322)
Motivation:

Two separate types for representing file paths currently exist:
[`SystemPackage`'s
`FilePath`](https://swiftpackageindex.com/apple/swift-system/1.6.0/documentation/systempackage/filepath)
type and [`System`'s
`FilePath`](https://developer.apple.com/documentation/system/filepath)
type.

`NIOFileSystem` currently uses `SystemPackage`'s `FilePath`. However,
the lack of an API for converting between the two representations means
that users whose application also uses `System.FilePath` may find
interacting with `NIOFileSystem` difficult.

Modifications:

- Added `NIOFilePath`, and its subcomponents `NIOFilePath.Root`,
`NIOFilePath.Component`, and `NIOFilePath.ComponentView`.
- These types mirror the API of `SystemPackage`'s `FilePath` and are
internally backed by it.
- `NIOFilePath` can be initialized from either an instance of
`SystemPackage.FilePath` or `System.FilePath`.

Result:

Reduces the friction of interacting with `NIOFileSystem` by providing a
bridge between `SystemPackage.FilePath` and `System.FilePath`.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-07-30 15:13:50 +01:00
Rafael Cepeda 02be63c7f4 Fixes all warnings when -require-explicit-sendable flag is enabled (#3320)
Fixes all warnings when `-require-explicit-sendable` flag is enabled and
enables the flag on macOS CI.

### Motivation:

We want to ensure our public API is either explicitly marked as
`Sendable` or not.

### Modifications:

Marked appropriate public types as `Sendable`, or explicitly defined
their conformance to the `Sendable` protocol as unavailable.

### Result:

We can now enable `-require-explicit-sendable` compiler flag in our
codebase.
2025-07-30 11:50:28 +01:00
Raphael 95c91a42a9 Enable release mode builds (#3327)
### Motivation:

Some errors do not show up in debug builds. Enabling release mode builds
improves the CI coverage.

### Modifications:

Enable release mode builds for pull requests and scheduled builds on
main.

### Result:

Improved CI coverage.
2025-07-30 08:59:02 +01:00
Raphael e0ef60bb98 Do not run windows nightly CI by default (#3325)
### Motivation:

Not everything that relies on these workflows builds on windows. Unit
tests and release builds should be explicitly enabled for windows
builds.

### Modifications:

Change default of windows nightly to false. Fix flag checks that enable
nightly builds.

### Result:

Easier to use CI workflows.
2025-07-29 14:49:04 +01:00
Raphael 6b48b36c7e Add workflow for release mode builds(#3321)
Add a new workflow file for release mode builds

### Motivation:

Some errors do not show up in debug builds. Running release mode builds
improves the CI coverage.

### Modifications:

Add a new workflow for release mode builds.

### Result:

Projects can build on this workflow to enable release mode builds.
2025-07-29 10:35:10 +01:00
Fabian Fett 4205ccaf1c [Windows] IOVector is WSABUF on Windows (#3324)
On Windows there is no iovec, because of this we need to make sure,
that:

1. We use the typealias `IOVector` as much as possible
2. We add platform specific code to `IOVector` extensions

Also adds some more Windows imports to fix some compiler errors.
2025-07-28 18:52:00 +02:00
Max Desiatov 175417d85c Fix typo in HTTPServerClientTest.swift comments (#3323)
`we read faster then we can write` -> `we read faster than we can write`
2025-07-28 12:46:19 +00:00
Fabian Fett 1d72f49390 [Windows] Ensure NIOEmbedded compiles (#3319)
Make NIOEmbedded compile.
2025-07-24 16:02:00 +00:00
Fabian Fett 06f236d37a [Windows] Windows has endianess too (#3317)
TIL there is an `endian.h` on Linux and macOS that is imported through
`<sys/types.h>` on Linux and Apple platforms. Apparently such a header
file does not exist in Windows land. For this reason we need to define
the macros that we need here ourselves.
2025-07-23 17:06:18 +01:00