From 8a117a1b757a455f8804afa94371cda8850f6d6c Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Sun, 28 Aug 2022 21:52:40 +0100 Subject: [PATCH] Update Swift Concurrency availability to include macOS 10.15, iOS 13.0 etc (#140) --- Package.swift | 2 +- .../AsyncAwaitSupport/AsyncMiddleware.swift | 8 ++++---- .../AsyncAwaitSupport/AsyncResponder.swift | 4 ++-- .../AsyncAwaitSupport/ConnectionPool+async.swift | 14 +++++++------- .../AsyncAwaitSupport/Request+Persist+async.swift | 4 ++-- .../AsyncAwaitSupport/RouteHandler+async.swift | 6 +++--- .../AsyncAwaitSupport/Router+async.swift | 8 ++++---- Sources/Hummingbird/Router/RouterMethods.swift | 4 ++-- .../AsyncAwaitSupport/FileIO+async.swift | 4 ++-- Sources/HummingbirdFoundation/Files/FileIO.swift | 7 +++++++ .../AsyncAwaitSupport/AsyncJob.swift | 6 +++--- .../AsyncAwaitSupport/JobQueue+async.swift | 4 ++-- .../FileTests+async.swift | 4 ++-- .../HummingbirdJobsTests.swift | 4 ++-- Tests/HummingbirdTests/AsyncAwaitTests.swift | 4 ++-- Tests/HummingbirdTests/PersistTests+async.swift | 4 ++-- 16 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Package.swift b/Package.swift index 24107add..704a70f5 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( .package(url: "https://github.com/apple/swift-metrics.git", "1.0.0"..<"3.0.0"), .package(url: "https://github.com/apple/swift-nio.git", from: "2.33.0"), .package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "1.0.0-alpha.9"), - .package(url: "https://github.com/hummingbird-project/hummingbird-core.git", .upToNextMinor(from: "0.13.5")), + .package(url: "https://github.com/hummingbird-project/hummingbird-core.git", .upToNextMinor(from: "0.14.0")), ], targets: [ .target(name: "Hummingbird", dependencies: [ diff --git a/Sources/Hummingbird/AsyncAwaitSupport/AsyncMiddleware.swift b/Sources/Hummingbird/AsyncAwaitSupport/AsyncMiddleware.swift index cec7d1c7..e8da794e 100644 --- a/Sources/Hummingbird/AsyncAwaitSupport/AsyncMiddleware.swift +++ b/Sources/Hummingbird/AsyncAwaitSupport/AsyncMiddleware.swift @@ -12,17 +12,17 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import NIOCore /// Middleware using async/await -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public protocol HBAsyncMiddleware: HBMiddleware { func apply(to request: HBRequest, next: HBResponder) async throws -> HBResponse } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBAsyncMiddleware { public func apply(to request: HBRequest, next: HBResponder) -> EventLoopFuture { let promise = request.eventLoop.makePromise(of: HBResponse.self) @@ -33,7 +33,7 @@ extension HBAsyncMiddleware { } } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBResponder { /// extend HBResponder to provide async/await version of respond public func respond(to request: HBRequest) async throws -> HBResponse { diff --git a/Sources/Hummingbird/AsyncAwaitSupport/AsyncResponder.swift b/Sources/Hummingbird/AsyncAwaitSupport/AsyncResponder.swift index 899b71bd..9ad3095b 100644 --- a/Sources/Hummingbird/AsyncAwaitSupport/AsyncResponder.swift +++ b/Sources/Hummingbird/AsyncAwaitSupport/AsyncResponder.swift @@ -12,12 +12,12 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import NIO /// Responder that calls supplied closure -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public struct HBAsyncCallbackResponder: HBResponder { let callback: (HBRequest) async throws -> HBResponse diff --git a/Sources/Hummingbird/AsyncAwaitSupport/ConnectionPool+async.swift b/Sources/Hummingbird/AsyncAwaitSupport/ConnectionPool+async.swift index 3b1eb132..597784b0 100644 --- a/Sources/Hummingbird/AsyncAwaitSupport/ConnectionPool+async.swift +++ b/Sources/Hummingbird/AsyncAwaitSupport/ConnectionPool+async.swift @@ -12,12 +12,12 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import Logging import NIO -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBConnectionPool { /// Request a connection, run a process and then release the connection /// - Parameters: @@ -48,7 +48,7 @@ extension HBConnectionPool { } } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBConnectionPoolGroup { /// Request a connection, run a process and then release the connection /// - Parameters: @@ -80,12 +80,12 @@ extension HBConnectionPoolGroup { } } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public protocol HBAsyncConnection: HBConnection { func close() async throws } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public extension HBAsyncConnection { func close(on eventLoop: EventLoop) -> EventLoopFuture { let promise = eventLoop.makePromise(of: Void.self) @@ -96,12 +96,12 @@ public extension HBAsyncConnection { } } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public protocol HBAsyncConnectionSource: HBConnectionSource where Connection: HBAsyncConnection { func makeConnection(on eventLoop: EventLoop, logger: Logger) async throws -> Connection } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public extension HBAsyncConnectionSource { func makeConnection(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture { let promise = eventLoop.makePromise(of: Connection.self) diff --git a/Sources/Hummingbird/AsyncAwaitSupport/Request+Persist+async.swift b/Sources/Hummingbird/AsyncAwaitSupport/Request+Persist+async.swift index 97d00e72..ce368d86 100644 --- a/Sources/Hummingbird/AsyncAwaitSupport/Request+Persist+async.swift +++ b/Sources/Hummingbird/AsyncAwaitSupport/Request+Persist+async.swift @@ -12,9 +12,9 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBRequest.Persist { /// Set value for key that will expire after a certain time. /// diff --git a/Sources/Hummingbird/AsyncAwaitSupport/RouteHandler+async.swift b/Sources/Hummingbird/AsyncAwaitSupport/RouteHandler+async.swift index 45c8d6af..a1bbc1d7 100644 --- a/Sources/Hummingbird/AsyncAwaitSupport/RouteHandler+async.swift +++ b/Sources/Hummingbird/AsyncAwaitSupport/RouteHandler+async.swift @@ -12,17 +12,17 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) /// Route Handler using async/await methods -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public protocol HBAsyncRouteHandler: HBRouteHandler where _Output == EventLoopFuture<_Output2> { associatedtype _Output2 init(from: HBRequest) throws func handle(request: HBRequest) async throws -> _Output2 } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBAsyncRouteHandler { public func handle(request: HBRequest) throws -> EventLoopFuture<_Output2> { let promise = request.eventLoop.makePromise(of: _Output2.self) diff --git a/Sources/Hummingbird/AsyncAwaitSupport/Router+async.swift b/Sources/Hummingbird/AsyncAwaitSupport/Router+async.swift index e8e5e256..d0f069c7 100644 --- a/Sources/Hummingbird/AsyncAwaitSupport/Router+async.swift +++ b/Sources/Hummingbird/AsyncAwaitSupport/Router+async.swift @@ -12,11 +12,11 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import NIOCore -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBRouterMethods { /// GET path for closure returning type conforming to ResponseFutureEncodable @discardableResult public func get( @@ -92,7 +92,7 @@ extension HBRouterMethods { } } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBRouter { /// Add path for closure returning type conforming to ResponseFutureEncodable @discardableResult public func on( @@ -107,7 +107,7 @@ extension HBRouter { } } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBRouterGroup { /// Add path for closure returning type conforming to ResponseFutureEncodable @discardableResult public func on( diff --git a/Sources/Hummingbird/Router/RouterMethods.swift b/Sources/Hummingbird/Router/RouterMethods.swift index 8f161c1a..eeaaedda 100644 --- a/Sources/Hummingbird/Router/RouterMethods.swift +++ b/Sources/Hummingbird/Router/RouterMethods.swift @@ -44,9 +44,9 @@ public protocol HBRouterMethods { use: @escaping (HBRequest) -> EventLoopFuture ) -> Self - #if compiler(>=5.5) && canImport(_Concurrency) + #if compiler(>=5.5.2) && canImport(_Concurrency) /// Add path for async closure - @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) @discardableResult func on( _ path: String, method: HTTPMethod, diff --git a/Sources/HummingbirdFoundation/AsyncAwaitSupport/FileIO+async.swift b/Sources/HummingbirdFoundation/AsyncAwaitSupport/FileIO+async.swift index 602162aa..99dc6f2c 100644 --- a/Sources/HummingbirdFoundation/AsyncAwaitSupport/FileIO+async.swift +++ b/Sources/HummingbirdFoundation/AsyncAwaitSupport/FileIO+async.swift @@ -12,12 +12,12 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import Logging /// Middleware using async/await -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBFileIO { /// Load file and return response body /// diff --git a/Sources/HummingbirdFoundation/Files/FileIO.swift b/Sources/HummingbirdFoundation/Files/FileIO.swift index 7e06b71a..cc78f933 100644 --- a/Sources/HummingbirdFoundation/Files/FileIO.swift +++ b/Sources/HummingbirdFoundation/Files/FileIO.swift @@ -198,3 +198,10 @@ public struct HBFileIO { } } } + +#if compiler(>=5.6) +// Can set this to @unchecked Sendable due to the way it is used. The `read` +// function that accesses the non-Sendable parts of the class is never +// called concurrently +extension HBFileIO.FileStreamer: @unchecked Sendable {} +#endif diff --git a/Sources/HummingbirdJobs/AsyncAwaitSupport/AsyncJob.swift b/Sources/HummingbirdJobs/AsyncAwaitSupport/AsyncJob.swift index d5f68add..164532b8 100644 --- a/Sources/HummingbirdJobs/AsyncAwaitSupport/AsyncJob.swift +++ b/Sources/HummingbirdJobs/AsyncAwaitSupport/AsyncJob.swift @@ -12,18 +12,18 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import NIOCore /// Job with asynchronous handler -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public protocol HBAsyncJob: HBJob { /// Execute job func execute(logger: Logger) async throws } -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBAsyncJob { func execute(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture { let promise = eventLoop.makePromise(of: Void.self) diff --git a/Sources/HummingbirdJobs/AsyncAwaitSupport/JobQueue+async.swift b/Sources/HummingbirdJobs/AsyncAwaitSupport/JobQueue+async.swift index e091c1c2..3c7a11e3 100644 --- a/Sources/HummingbirdJobs/AsyncAwaitSupport/JobQueue+async.swift +++ b/Sources/HummingbirdJobs/AsyncAwaitSupport/JobQueue+async.swift @@ -12,12 +12,12 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import NIOCore /// Job with asynchronous handler -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) extension HBJobQueue { /// Push job onto queue /// - Parameters: diff --git a/Tests/HummingbirdFoundationTests/FileTests+async.swift b/Tests/HummingbirdFoundationTests/FileTests+async.swift index ee7da76f..5e429092 100644 --- a/Tests/HummingbirdFoundationTests/FileTests+async.swift +++ b/Tests/HummingbirdFoundationTests/FileTests+async.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import Foundation import Hummingbird @@ -20,7 +20,7 @@ import HummingbirdFoundation import HummingbirdXCT import XCTest -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) class HummingbirdAsyncFilesTests: XCTestCase { func randomBuffer(size: Int) -> ByteBuffer { var data = [UInt8](repeating: 0, count: size) diff --git a/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift b/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift index 6fb52afb..14b90f50 100644 --- a/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift +++ b/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift @@ -266,9 +266,9 @@ final class HummingbirdJobsTests: XCTestCase { wait(for: [TestJob.expectation], timeout: 5) } - #if compiler(>=5.5) && canImport(_Concurrency) + #if compiler(>=5.5.2) && canImport(_Concurrency) - @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) func testAsyncJob() throws { #if os(macOS) // disable macOS tests in CI. GH Actions are currently running this when they shouldn't diff --git a/Tests/HummingbirdTests/AsyncAwaitTests.swift b/Tests/HummingbirdTests/AsyncAwaitTests.swift index 5eec8a8b..3d967f54 100644 --- a/Tests/HummingbirdTests/AsyncAwaitTests.swift +++ b/Tests/HummingbirdTests/AsyncAwaitTests.swift @@ -12,14 +12,14 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import Hummingbird import HummingbirdXCT import NIOHTTP1 import XCTest -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) final class AsyncAwaitTests: XCTestCase { func randomBuffer(size: Int) -> ByteBuffer { var data = [UInt8](repeating: 0, count: size) diff --git a/Tests/HummingbirdTests/PersistTests+async.swift b/Tests/HummingbirdTests/PersistTests+async.swift index 87fce158..597c93be 100644 --- a/Tests/HummingbirdTests/PersistTests+async.swift +++ b/Tests/HummingbirdTests/PersistTests+async.swift @@ -12,12 +12,12 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=5.5) && canImport(_Concurrency) +#if compiler(>=5.5.2) && canImport(_Concurrency) import Hummingbird import XCTest -@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) +@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) final class AsyncPersistTests: XCTestCase { func createApplication() throws -> HBApplication { let app = HBApplication(testing: .live)