Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower availability/compiler guards #1364

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
/// NOTE: This file should be removed when the `async` branch of `swift-argument-parser` has been
/// released: https://github.com/apple/swift-argument-parser/tree/async

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import ArgumentParser

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
protocol AsyncParsableCommand: ParsableCommand {
mutating func runAsync() async throws
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension AsyncParsableCommand {
public mutating func run() throws {
throw CleanExit.helpRequest(self)
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension ParsableCommand {
static func main(_ arguments: [String]? = nil) async {
do {
Expand Down
20 changes: 10 additions & 10 deletions Sources/Examples/Echo/AsyncAwaitRuntime/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

import ArgumentParser
import EchoImplementation
Expand All @@ -36,7 +36,7 @@ enum RPC: String, ExpressibleByArgument {
case update
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
struct Echo: ParsableCommand {
static var configuration = CommandConfiguration(
abstract: "An example to run and call a simple gRPC service for echoing messages.",
Expand Down Expand Up @@ -115,7 +115,7 @@ struct Echo: ParsableCommand {

// MARK: - Server

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func startEchoServer(group: EventLoopGroup, port: Int, useTLS: Bool) async throws {
let builder: Server.Builder

Expand Down Expand Up @@ -157,7 +157,7 @@ func startEchoServer(group: EventLoopGroup, port: Int, useTLS: Bool) async throw

// MARK: - Client

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func makeClient(
group: EventLoopGroup,
port: Int,
Expand Down Expand Up @@ -196,7 +196,7 @@ func makeClient(
)
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func callRPC(_ rpc: RPC, using client: Echo_EchoAsyncClient, message: String) async {
do {
switch rpc {
Expand All @@ -214,13 +214,13 @@ func callRPC(_ rpc: RPC, using client: Echo_EchoAsyncClient, message: String) as
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func echoGet(client: Echo_EchoAsyncClient, message: String) async throws {
let response = try await client.get(.with { $0.text = message })
print("get received: \(response.text)")
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func echoCollect(client: Echo_EchoAsyncClient, message: String) async throws {
let messages = message.components(separatedBy: " ").map { part in
Echo_EchoRequest.with { $0.text = part }
Expand All @@ -229,14 +229,14 @@ func echoCollect(client: Echo_EchoAsyncClient, message: String) async throws {
print("collect received: \(response.text)")
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func echoExpand(client: Echo_EchoAsyncClient, message: String) async throws {
for try await response in client.expand((.with { $0.text = message })) {
print("expand received: \(response.text)")
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func echoUpdate(client: Echo_EchoAsyncClient, message: String) async throws {
let requests = message.components(separatedBy: " ").map { word in
Echo_EchoRequest.with { $0.text = word }
Expand All @@ -254,7 +254,7 @@ func echoUpdate(client: Echo_EchoAsyncClient, message: String) async throws {
import Dispatch
let dg = DispatchGroup()
dg.enter()
if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) {
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
Task {
await Echo.main()
dg.leave()
Expand Down
6 changes: 3 additions & 3 deletions Sources/Examples/Echo/Implementation/EchoAsyncProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)
import EchoModel
import GRPC

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public final class EchoAsyncProvider: Echo_EchoAsyncProvider {
public let interceptors: Echo_EchoServerInterceptorFactoryProtocol?

Expand Down Expand Up @@ -69,4 +69,4 @@ public final class EchoAsyncProvider: Echo_EchoAsyncProvider {
}
}

#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
20 changes: 10 additions & 10 deletions Sources/Examples/Echo/Model/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public protocol Echo_EchoAsyncClientProtocol: GRPCClient {
static var serviceDescriptor: GRPCServiceDescriptor { get }
var interceptors: Echo_EchoClientInterceptorFactoryProtocol? { get }
Expand All @@ -182,7 +182,7 @@ public protocol Echo_EchoAsyncClientProtocol: GRPCClient {
) -> GRPCAsyncBidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Echo_EchoAsyncClientProtocol {
public static var serviceDescriptor: GRPCServiceDescriptor {
return Echo_EchoClientMetadata.serviceDescriptor
Expand Down Expand Up @@ -237,7 +237,7 @@ extension Echo_EchoAsyncClientProtocol {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Echo_EchoAsyncClientProtocol {
public func get(
_ request: Echo_EchoRequest,
Expand Down Expand Up @@ -312,7 +312,7 @@ extension Echo_EchoAsyncClientProtocol {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
public var channel: GRPCChannel
public var defaultCallOptions: CallOptions
Expand All @@ -329,7 +329,7 @@ public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
}
}

#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)

public protocol Echo_EchoClientInterceptorFactoryProtocol {

Expand Down Expand Up @@ -573,10 +573,10 @@ extension Echo_EchoProvider {
}
}
}
#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

/// To implement a server, implement an object which conforms to this protocol.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public protocol Echo_EchoAsyncProvider: CallHandlerProvider {
static var serviceDescriptor: GRPCServiceDescriptor { get }
var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
Expand Down Expand Up @@ -608,7 +608,7 @@ public protocol Echo_EchoAsyncProvider: CallHandlerProvider {
) async throws
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Echo_EchoAsyncProvider {
public static var serviceDescriptor: GRPCServiceDescriptor {
return Echo_EchoServerMetadata.serviceDescriptor
Expand Down Expand Up @@ -669,7 +669,7 @@ extension Echo_EchoAsyncProvider {
}
}

#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)

public protocol Echo_EchoServerInterceptorFactoryProtocol {

Expand Down
12 changes: 6 additions & 6 deletions Sources/Examples/RouteGuide/Client/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)
import ArgumentParser
import Foundation
import GRPC
Expand All @@ -33,7 +33,7 @@ func loadFeatures() throws -> [Routeguide_Feature] {
}

/// Makes a `RouteGuide` client for a service hosted on "localhost" and listening on the given port.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func makeClient(port: Int, group: EventLoopGroup) throws -> Routeguide_RouteGuideAsyncClient {
let channel = try GRPCChannelPool.with(
target: .host("localhost", port: port),
Expand All @@ -44,7 +44,7 @@ func makeClient(port: Int, group: EventLoopGroup) throws -> Routeguide_RouteGuid
return Routeguide_RouteGuideAsyncClient(channel: channel)
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
internal struct RouteGuideExample: @unchecked Sendable {
private let routeGuide: Routeguide_RouteGuideAsyncClient
private let features: [Routeguide_Feature]
Expand Down Expand Up @@ -88,7 +88,7 @@ internal struct RouteGuideExample: @unchecked Sendable {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension RouteGuideExample {
/// Get the feature at the given latitude and longitude, if one exists.
private func getFeature(latitude: Int, longitude: Int) async {
Expand Down Expand Up @@ -229,7 +229,7 @@ extension RouteGuideExample {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
struct RouteGuide: ParsableCommand {
@Option(help: "The port to connect to")
var port: Int = 1234
Expand Down Expand Up @@ -274,4 +274,4 @@ if #available(macOS 12, *) {
}
#else
fatalError("The RouteGuide example requires Swift concurrency features.")
#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
20 changes: 10 additions & 10 deletions Sources/Examples/RouteGuide/Model/route_guide.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public final class Routeguide_RouteGuideClient: Routeguide_RouteGuideClientProto
}
}

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)
/// Interface exported by the server.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public protocol Routeguide_RouteGuideAsyncClientProtocol: GRPCClient {
static var serviceDescriptor: GRPCServiceDescriptor { get }
var interceptors: Routeguide_RouteGuideClientInterceptorFactoryProtocol? { get }
Expand All @@ -201,7 +201,7 @@ public protocol Routeguide_RouteGuideAsyncClientProtocol: GRPCClient {
) -> GRPCAsyncBidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote>
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Routeguide_RouteGuideAsyncClientProtocol {
public static var serviceDescriptor: GRPCServiceDescriptor {
return Routeguide_RouteGuideClientMetadata.serviceDescriptor
Expand Down Expand Up @@ -256,7 +256,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Routeguide_RouteGuideAsyncClientProtocol {
public func getFeature(
_ request: Routeguide_Point,
Expand Down Expand Up @@ -331,7 +331,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public struct Routeguide_RouteGuideAsyncClient: Routeguide_RouteGuideAsyncClientProtocol {
public var channel: GRPCChannel
public var defaultCallOptions: CallOptions
Expand All @@ -348,7 +348,7 @@ public struct Routeguide_RouteGuideAsyncClient: Routeguide_RouteGuideAsyncClient
}
}

#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)

public protocol Routeguide_RouteGuideClientInterceptorFactoryProtocol {

Expand Down Expand Up @@ -492,12 +492,12 @@ extension Routeguide_RouteGuideProvider {
}
}
}
#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

/// Interface exported by the server.
///
/// To implement a server, implement an object which conforms to this protocol.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public protocol Routeguide_RouteGuideAsyncProvider: CallHandlerProvider {
static var serviceDescriptor: GRPCServiceDescriptor { get }
var interceptors: Routeguide_RouteGuideServerInterceptorFactoryProtocol? { get }
Expand Down Expand Up @@ -545,7 +545,7 @@ public protocol Routeguide_RouteGuideAsyncProvider: CallHandlerProvider {
) async throws
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Routeguide_RouteGuideAsyncProvider {
public static var serviceDescriptor: GRPCServiceDescriptor {
return Routeguide_RouteGuideServerMetadata.serviceDescriptor
Expand Down Expand Up @@ -606,7 +606,7 @@ extension Routeguide_RouteGuideAsyncProvider {
}
}

#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)

public protocol Routeguide_RouteGuideServerInterceptorFactoryProtocol {

Expand Down
8 changes: 4 additions & 4 deletions Sources/Examples/RouteGuide/Server/RouteGuideProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import NIOConcurrencyHelpers
import NIOCore
import RouteGuideModel

#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
internal final class RouteGuideProvider: Routeguide_RouteGuideAsyncProvider {
private let features: [Routeguide_Feature]
private let notes: Notes
Expand Down Expand Up @@ -111,7 +111,7 @@ internal final class RouteGuideProvider: Routeguide_RouteGuideAsyncProvider {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
internal final actor Notes {
private var recordedNotes: [Routeguide_Point: [Routeguide_RouteNote]]

Expand All @@ -130,7 +130,7 @@ internal final actor Notes {
}
}

#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)

private func degreesToRadians(_ degrees: Double) -> Double {
return degrees * .pi / 180.0
Expand Down
6 changes: 3 additions & 3 deletions Sources/Examples/RouteGuide/Server/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5) && canImport(_Concurrency)
#if compiler(>=5.5.2) && canImport(_Concurrency)
import ArgumentParser
import struct Foundation.Data
import struct Foundation.URL
Expand All @@ -33,7 +33,7 @@ func loadFeatures() throws -> [Routeguide_Feature] {
return try Routeguide_Feature.array(fromJSONUTF8Data: data)
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
struct RouteGuide: ParsableCommand {
@Option(help: "The port to listen on for new connections")
var port = 1234
Expand Down Expand Up @@ -76,4 +76,4 @@ if #available(macOS 12, *) {
}
#else
fatalError("The RouteGuide example requires Swift concurrency support.")
#endif // compiler(>=5.5) && canImport(_Concurrency)
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
Loading