Skip to content

Commit 709a3fc

Browse files
authored
Merge branch 'main' into enable_static_sdk_ci
2 parents 35c6d61 + b799051 commit 709a3fc

File tree

9 files changed

+111
-24
lines changed

9 files changed

+111
-24
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,31 @@ jobs:
1111
name: Unit tests
1212
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1313
with:
14-
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
1514
# Disable strict concurrency checking as it intersects badly with
1615
# warnings-as-errors on 5.10 and later as SwiftPMs generated test manifest
1716
# has a non-sendable global property.
1817
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
1918
# TODO: Enable warnings-as-errors on 6.0.
2019
linux_6_0_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
20+
linux_6_1_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
2121
linux_nightly_next_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
2222
linux_nightly_main_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
23+
windows_6_0_enabled: true
24+
windows_6_1_enabled: true
25+
windows_nightly_6_1_enabled: true
26+
windows_nightly_main_enabled: true
27+
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
28+
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
29+
windows_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error"
30+
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
31+
32+
macos-tests:
33+
name: macOS tests
34+
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
35+
with:
36+
runner_pool: nightly
37+
build_scheme: swift-openapi-urlsession
2338

2439
static-sdk:
2540
name: Static SDK
26-
# Workaround https://github.com/nektos/act/issues/1875
2741
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main

.github/workflows/pull_request.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,35 @@ jobs:
1515
name: Unit tests
1616
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1717
with:
18-
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
1918
# Disable strict concurrency checking as it intersects badly with
2019
# warnings-as-errors on 5.10 and later as SwiftPMs generated test manifest
2120
# has a non-sendable global property.
2221
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
2322
# TODO: Enable warnings-as-errors on 6.0.
2423
linux_6_0_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
24+
linux_6_1_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
2525
linux_nightly_next_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
2626
linux_nightly_main_arguments_override: "-Xswiftc -strict-concurrency=complete --explicit-target-dependency-import-check error"
27+
windows_6_0_enabled: true
28+
windows_6_1_enabled: true
29+
windows_nightly_6_1_enabled: true
30+
windows_nightly_main_enabled: true
31+
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
32+
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
33+
windows_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error"
34+
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
2735

2836
cxx-interop:
2937
name: Cxx interop
3038
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
3139

40+
macos-tests:
41+
name: macOS tests
42+
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
43+
with:
44+
runner_pool: general
45+
build_scheme: swift-openapi-urlsession
46+
3247
static-sdk:
3348
name: Static SDK
34-
# Workaround https://github.com/nektos/act/issues/1875
3549
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main

Package.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project
@@ -34,7 +34,7 @@ let package = Package(
3434
platforms: [.macOS(.v10_15), .macCatalyst(.v13), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
3535
products: [.library(name: "OpenAPIURLSession", targets: ["OpenAPIURLSession"])],
3636
dependencies: [
37-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
37+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.8.2"),
3838
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
3939
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
4040
],
@@ -50,14 +50,21 @@ let package = Package(
5050
),
5151
.testTarget(
5252
name: "OpenAPIURLSessionTests",
53-
dependencies: ["OpenAPIURLSession", .product(name: "NIOTestUtils", package: "swift-nio")],
53+
dependencies: ["OpenAPIURLSession"],
5454
swiftSettings: swiftSettings
5555
),
5656
]
5757
)
5858

59+
#if !os(Windows) // NIO not yet supported on Windows
5960
// Test-only dependencies.
6061
package.dependencies += [.package(url: "https://github.com/apple/swift-nio", from: "2.62.0")]
62+
package.targets.forEach { target in
63+
if target.name == "OpenAPIURLSessionTests" {
64+
target.dependencies += [.product(name: "NIOTestUtils", package: "swift-nio")]
65+
}
66+
}
67+
#endif
6168

6269
// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
6370
for target in package.targets {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Use the transport with client code generated by [Swift OpenAPI Generator](https:
1111

1212
## Supported platforms and minimum versions
1313

14-
| macOS | Linux | iOS | tvOS | watchOS | visionOS |
14+
| macOS | Linux, Windows | iOS | tvOS | watchOS | visionOS |
1515
| :-: | :-: | :-: | :-: | :-: | :-: |
1616
| ✅ 10.15+ || ✅ 13+ | ✅ 13+ | ✅ 6+ | ✅ 1+ |
1717

Sources/OpenAPIURLSession/BufferedStream/Lock.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@
3030
import Darwin
3131
#elseif canImport(Glibc)
3232
import Glibc
33+
#elseif os(Windows)
34+
import WinSDK
3335
#endif
3436

37+
#if os(Windows)
38+
@usableFromInline
39+
typealias LockPrimitive = SRWLOCK
40+
#else
3541
@usableFromInline
3642
typealias LockPrimitive = pthread_mutex_t
43+
#endif
3744

3845
@usableFromInline
3946
enum LockOperations {}
@@ -43,35 +50,51 @@ extension LockOperations {
4350
static func create(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
4451
mutex.assertValidAlignment()
4552

53+
#if os(Windows)
54+
InitializeSRWLock(mutex)
55+
#else
4656
var attr = pthread_mutexattr_t()
4757
pthread_mutexattr_init(&attr)
4858

4959
let err = pthread_mutex_init(mutex, &attr)
5060
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
61+
#endif
5162
}
5263

5364
@inlinable
5465
static func destroy(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
5566
mutex.assertValidAlignment()
5667

68+
#if os(Windows)
69+
// SRWLOCK does not need to be freed
70+
#else
5771
let err = pthread_mutex_destroy(mutex)
5872
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
73+
#endif
5974
}
6075

6176
@inlinable
6277
static func lock(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
6378
mutex.assertValidAlignment()
6479

80+
#if os(Windows)
81+
AcquireSRWLockExclusive(mutex)
82+
#else
6583
let err = pthread_mutex_lock(mutex)
6684
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
85+
#endif
6786
}
6887

6988
@inlinable
7089
static func unlock(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
7190
mutex.assertValidAlignment()
7291

92+
#if os(Windows)
93+
ReleaseSRWLockExclusive(mutex)
94+
#else
7395
let err = pthread_mutex_unlock(mutex)
7496
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
97+
#endif
7598
}
7699
}
77100

Sources/OpenAPIURLSession/URLSessionTransport.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,32 @@ public struct URLSessionTransport: ClientTransport {
6666
/// The URLSession used for performing HTTP operations.
6767
public var session: URLSession
6868

69+
/// Creates a new configuration with the provided session.
70+
/// - Parameters:
71+
/// - session: The URLSession used for performing HTTP operations.
72+
/// If none is provided, the system uses the shared URLSession.
73+
/// - httpBodyProcessingMode: The mode used to process HTTP request and response bodies.
74+
public init(session: URLSession = .shared, httpBodyProcessingMode: HTTPBodyProcessingMode = .platformDefault) {
75+
let implementation = httpBodyProcessingMode.implementation
76+
self.init(session: session, implementation: implementation)
77+
}
6978
/// Creates a new configuration with the provided session.
7079
/// - Parameter session: The URLSession used for performing HTTP operations.
7180
/// If none is provided, the system uses the shared URLSession.
7281
public init(session: URLSession = .shared) { self.init(session: session, implementation: .platformDefault) }
82+
/// Specifies the mode in which HTTP request and response bodies are processed.
83+
public struct HTTPBodyProcessingMode: Sendable {
84+
/// Exposing the internal implementation directly.
85+
fileprivate let implementation: Configuration.Implementation
86+
87+
private init(_ implementation: Configuration.Implementation) { self.implementation = implementation }
88+
89+
/// Use this mode to force URLSessionTransport to transfer data in a buffered mode, even if
90+
/// streaming would be available on the platform.
91+
public static let buffered = HTTPBodyProcessingMode(.buffering)
92+
/// Data is transfered via streaming if available on the platform, else it falls back to buffering.
93+
public static let platformDefault = HTTPBodyProcessingMode(.platformDefault)
94+
}
7395

7496
enum Implementation {
7597
case buffering

Tests/OpenAPIURLSessionTests/NIOAsyncHTTP1TestServer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14+
#if !os(Windows) // NIO not yet supported on Windows
1415
import NIOCore
1516
import NIOPosix
1617
import NIOHTTP1
@@ -93,3 +94,4 @@ extension AsyncTestHTTP1Server {
9394
}
9495

9596
}
97+
#endif

Tests/OpenAPIURLSessionTests/TaskCancellationTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import Foundation
1717
import HTTPTypes
1818
import NIO
19+
import NIOHTTP1
1920
import OpenAPIRuntime
2021
import XCTest
2122
@testable import OpenAPIURLSession

Tests/OpenAPIURLSessionTests/URLSessionTransportTests.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import Foundation
1616
import FoundationNetworking
1717
#endif
1818
import HTTPTypes
19+
#if !os(Windows) // NIO not yet supported on Windows
1920
import NIO
2021
import NIOHTTP1
22+
#endif
2123
import OpenAPIRuntime
2224
import XCTest
2325
@testable import OpenAPIURLSession
@@ -59,6 +61,7 @@ class URLSessionTransportConverterTests: XCTestCase {
5961
}
6062
}
6163

64+
#if !os(Windows) // NIO not yet supported on Windows
6265
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
6366
class URLSessionTransportBufferedTests: XCTestCase {
6467
var transport: URLSessionTransport!
@@ -133,22 +136,6 @@ class URLSessionTransportStreamingTests: XCTestCase {
133136
#endif
134137
}
135138

136-
class URLSessionTransportPlatformSupportTests: XCTestCase {
137-
func testDefaultsToStreamingIfSupported() {
138-
if URLSessionTransport.Configuration.Implementation.platformSupportsStreaming {
139-
guard case .streaming = URLSessionTransport.Configuration.Implementation.platformDefault else {
140-
XCTFail()
141-
return
142-
}
143-
} else {
144-
guard case .buffering = URLSessionTransport.Configuration.Implementation.platformDefault else {
145-
XCTFail()
146-
return
147-
}
148-
}
149-
}
150-
}
151-
152139
func testHTTPRedirect(
153140
transport: any ClientTransport,
154141
requestBodyIterationBehavior: IterationBehavior,
@@ -315,6 +302,23 @@ func testHTTPBasicPost(transport: any ClientTransport) async throws {
315302
group.cancelAll()
316303
}
317304
}
305+
#endif
306+
307+
class URLSessionTransportPlatformSupportTests: XCTestCase {
308+
func testDefaultsToStreamingIfSupported() {
309+
if URLSessionTransport.Configuration.Implementation.platformSupportsStreaming {
310+
guard case .streaming = URLSessionTransport.Configuration.Implementation.platformDefault else {
311+
XCTFail()
312+
return
313+
}
314+
} else {
315+
guard case .buffering = URLSessionTransport.Configuration.Implementation.platformDefault else {
316+
XCTFail()
317+
return
318+
}
319+
}
320+
}
321+
}
318322

319323
class URLSessionTransportDebugLoggingTests: XCTestCase {
320324
func testDebugLoggingEnabled() {

0 commit comments

Comments
 (0)