Skip to content

Commit f057ebd

Browse files
authored
Merge branch 'main' into main
2 parents b117fa9 + 1079229 commit f057ebd

File tree

9 files changed

+123
-22
lines changed

9 files changed

+123
-22
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,36 @@ 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"
2331

2432
macos-tests:
2533
name: macOS tests
2634
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
2735
with:
36+
runner_pool: nightly
2837
build_scheme: swift-openapi-urlsession
38+
39+
release-builds:
40+
name: Release builds
41+
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
42+
with:
43+
windows_6_0_enabled: true
44+
windows_6_1_enabled: true
45+
windows_nightly_next_enabled: true
46+
windows_nightly_main_enabled: true

.github/workflows/pull_request.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,40 @@ 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
39+
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+
47+
release-builds:
48+
name: Release builds
49+
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
50+
with:
51+
windows_6_0_enabled: true
52+
windows_6_1_enabled: true
53+
windows_nightly_next_enabled: true
54+
windows_nightly_main_enabled: true

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
@@ -32,10 +32,17 @@ import Darwin
3232
import Android
3333
#elseif canImport(Glibc)
3434
import Glibc
35+
#elseif os(Windows)
36+
import WinSDK
3537
#endif
3638

39+
#if os(Windows)
40+
@usableFromInline
41+
typealias LockPrimitive = SRWLOCK
42+
#else
3743
@usableFromInline
3844
typealias LockPrimitive = pthread_mutex_t
45+
#endif
3946

4047
@usableFromInline
4148
enum LockOperations {}
@@ -45,35 +52,51 @@ extension LockOperations {
4552
static func create(_ mutex: UnsafeMutablePointer<LockPrimitive>) {
4653
mutex.assertValidAlignment()
4754

55+
#if os(Windows)
56+
InitializeSRWLock(mutex)
57+
#else
4858
var attr = pthread_mutexattr_t()
4959
pthread_mutexattr_init(&attr)
5060

5161
let err = pthread_mutex_init(mutex, &attr)
5262
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
63+
#endif
5364
}
5465

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

70+
#if os(Windows)
71+
// SRWLOCK does not need to be freed
72+
#else
5973
let err = pthread_mutex_destroy(mutex)
6074
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
75+
#endif
6176
}
6277

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

82+
#if os(Windows)
83+
AcquireSRWLockExclusive(mutex)
84+
#else
6785
let err = pthread_mutex_lock(mutex)
6886
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
87+
#endif
6988
}
7089

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

94+
#if os(Windows)
95+
ReleaseSRWLockExclusive(mutex)
96+
#else
7597
let err = pthread_mutex_unlock(mutex)
7698
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
99+
#endif
77100
}
78101
}
79102

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)