Skip to content

Commit b0e710c

Browse files
authored
Lower availability/compiler guards (#1364)
Motivation: Concurrency support was backported to older OS versions in Swift 5.5.2; we should lower our availability guards accordingly. Modifications: - Update compiler guards and availability in GRPC - Update generated guards Result: Async gRPC is availabile on older OSs.
1 parent f7513ab commit b0e710c

28 files changed

+132
-132
lines changed

Sources/Examples/Echo/AsyncAwaitRuntime/ArgumentParser+AsyncAwait.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717
/// NOTE: This file should be removed when the `async` branch of `swift-argument-parser` has been
1818
/// released: https://github.com/apple/swift-argument-parser/tree/async
1919

20-
#if compiler(>=5.5) && canImport(_Concurrency)
20+
#if compiler(>=5.5.2) && canImport(_Concurrency)
2121

2222
import ArgumentParser
2323

24-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
24+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2525
protocol AsyncParsableCommand: ParsableCommand {
2626
mutating func runAsync() async throws
2727
}
2828

29-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
29+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3030
extension AsyncParsableCommand {
3131
public mutating func run() throws {
3232
throw CleanExit.helpRequest(self)
3333
}
3434
}
3535

36-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
36+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3737
extension ParsableCommand {
3838
static func main(_ arguments: [String]? = nil) async {
3939
do {

Sources/Examples/Echo/AsyncAwaitRuntime/main.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#if compiler(>=5.5) && canImport(_Concurrency)
17+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1818

1919
import ArgumentParser
2020
import EchoImplementation
@@ -36,7 +36,7 @@ enum RPC: String, ExpressibleByArgument {
3636
case update
3737
}
3838

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

116116
// MARK: - Server
117117

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

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

158158
// MARK: - Client
159159

160-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
160+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
161161
func makeClient(
162162
group: EventLoopGroup,
163163
port: Int,
@@ -196,7 +196,7 @@ func makeClient(
196196
)
197197
}
198198

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

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

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

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

239-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
239+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
240240
func echoUpdate(client: Echo_EchoAsyncClient, message: String) async throws {
241241
let requests = message.components(separatedBy: " ").map { word in
242242
Echo_EchoRequest.with { $0.text = word }
@@ -254,7 +254,7 @@ func echoUpdate(client: Echo_EchoAsyncClient, message: String) async throws {
254254
import Dispatch
255255
let dg = DispatchGroup()
256256
dg.enter()
257-
if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) {
257+
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
258258
Task {
259259
await Echo.main()
260260
dg.leave()

Sources/Examples/Echo/Implementation/EchoAsyncProvider.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#if compiler(>=5.5) && canImport(_Concurrency)
16+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1717
import EchoModel
1818
import GRPC
1919

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

@@ -69,4 +69,4 @@ public final class EchoAsyncProvider: Echo_EchoAsyncProvider {
6969
}
7070
}
7171

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

Sources/Examples/Echo/Model/echo.grpc.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
157157
}
158158
}
159159

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

185-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
185+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
186186
extension Echo_EchoAsyncClientProtocol {
187187
public static var serviceDescriptor: GRPCServiceDescriptor {
188188
return Echo_EchoClientMetadata.serviceDescriptor
@@ -237,7 +237,7 @@ extension Echo_EchoAsyncClientProtocol {
237237
}
238238
}
239239

240-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
240+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
241241
extension Echo_EchoAsyncClientProtocol {
242242
public func get(
243243
_ request: Echo_EchoRequest,
@@ -312,7 +312,7 @@ extension Echo_EchoAsyncClientProtocol {
312312
}
313313
}
314314

315-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
315+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
316316
public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
317317
public var channel: GRPCChannel
318318
public var defaultCallOptions: CallOptions
@@ -329,7 +329,7 @@ public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
329329
}
330330
}
331331

332-
#endif // compiler(>=5.5) && canImport(_Concurrency)
332+
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
333333

334334
public protocol Echo_EchoClientInterceptorFactoryProtocol {
335335

@@ -573,10 +573,10 @@ extension Echo_EchoProvider {
573573
}
574574
}
575575
}
576-
#if compiler(>=5.5) && canImport(_Concurrency)
576+
#if compiler(>=5.5.2) && canImport(_Concurrency)
577577

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

611-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
611+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
612612
extension Echo_EchoAsyncProvider {
613613
public static var serviceDescriptor: GRPCServiceDescriptor {
614614
return Echo_EchoServerMetadata.serviceDescriptor
@@ -669,7 +669,7 @@ extension Echo_EchoAsyncProvider {
669669
}
670670
}
671671

672-
#endif // compiler(>=5.5) && canImport(_Concurrency)
672+
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
673673

674674
public protocol Echo_EchoServerInterceptorFactoryProtocol {
675675

Sources/Examples/RouteGuide/Client/main.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#if compiler(>=5.5) && canImport(_Concurrency)
16+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1717
import ArgumentParser
1818
import Foundation
1919
import GRPC
@@ -33,7 +33,7 @@ func loadFeatures() throws -> [Routeguide_Feature] {
3333
}
3434

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

47-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
47+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
4848
internal struct RouteGuideExample: @unchecked Sendable {
4949
private let routeGuide: Routeguide_RouteGuideAsyncClient
5050
private let features: [Routeguide_Feature]
@@ -88,7 +88,7 @@ internal struct RouteGuideExample: @unchecked Sendable {
8888
}
8989
}
9090

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

232-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
232+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
233233
struct RouteGuide: ParsableCommand {
234234
@Option(help: "The port to connect to")
235235
var port: Int = 1234
@@ -274,4 +274,4 @@ if #available(macOS 12, *) {
274274
}
275275
#else
276276
fatalError("The RouteGuide example requires Swift concurrency features.")
277-
#endif // compiler(>=5.5) && canImport(_Concurrency)
277+
#endif // compiler(>=5.5.2) && canImport(_Concurrency)

Sources/Examples/RouteGuide/Model/route_guide.grpc.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ public final class Routeguide_RouteGuideClient: Routeguide_RouteGuideClientProto
175175
}
176176
}
177177

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

204-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
204+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
205205
extension Routeguide_RouteGuideAsyncClientProtocol {
206206
public static var serviceDescriptor: GRPCServiceDescriptor {
207207
return Routeguide_RouteGuideClientMetadata.serviceDescriptor
@@ -256,7 +256,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
256256
}
257257
}
258258

259-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
259+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
260260
extension Routeguide_RouteGuideAsyncClientProtocol {
261261
public func getFeature(
262262
_ request: Routeguide_Point,
@@ -331,7 +331,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
331331
}
332332
}
333333

334-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
334+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
335335
public struct Routeguide_RouteGuideAsyncClient: Routeguide_RouteGuideAsyncClientProtocol {
336336
public var channel: GRPCChannel
337337
public var defaultCallOptions: CallOptions
@@ -348,7 +348,7 @@ public struct Routeguide_RouteGuideAsyncClient: Routeguide_RouteGuideAsyncClient
348348
}
349349
}
350350

351-
#endif // compiler(>=5.5) && canImport(_Concurrency)
351+
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
352352

353353
public protocol Routeguide_RouteGuideClientInterceptorFactoryProtocol {
354354

@@ -492,12 +492,12 @@ extension Routeguide_RouteGuideProvider {
492492
}
493493
}
494494
}
495-
#if compiler(>=5.5) && canImport(_Concurrency)
495+
#if compiler(>=5.5.2) && canImport(_Concurrency)
496496

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

548-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
548+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
549549
extension Routeguide_RouteGuideAsyncProvider {
550550
public static var serviceDescriptor: GRPCServiceDescriptor {
551551
return Routeguide_RouteGuideServerMetadata.serviceDescriptor
@@ -606,7 +606,7 @@ extension Routeguide_RouteGuideAsyncProvider {
606606
}
607607
}
608608

609-
#endif // compiler(>=5.5) && canImport(_Concurrency)
609+
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
610610

611611
public protocol Routeguide_RouteGuideServerInterceptorFactoryProtocol {
612612

Sources/Examples/RouteGuide/Server/RouteGuideProvider.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import NIOConcurrencyHelpers
1919
import NIOCore
2020
import RouteGuideModel
2121

22-
#if compiler(>=5.5) && canImport(_Concurrency)
22+
#if compiler(>=5.5.2) && canImport(_Concurrency)
2323

24-
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
24+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2525
internal final class RouteGuideProvider: Routeguide_RouteGuideAsyncProvider {
2626
private let features: [Routeguide_Feature]
2727
private let notes: Notes
@@ -111,7 +111,7 @@ internal final class RouteGuideProvider: Routeguide_RouteGuideAsyncProvider {
111111
}
112112
}
113113

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

@@ -130,7 +130,7 @@ internal final actor Notes {
130130
}
131131
}
132132

133-
#endif // compiler(>=5.5) && canImport(_Concurrency)
133+
#endif // compiler(>=5.5.2) && canImport(_Concurrency)
134134

135135
private func degreesToRadians(_ degrees: Double) -> Double {
136136
return degrees * .pi / 180.0

Sources/Examples/RouteGuide/Server/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#if compiler(>=5.5) && canImport(_Concurrency)
16+
#if compiler(>=5.5.2) && canImport(_Concurrency)
1717
import ArgumentParser
1818
import struct Foundation.Data
1919
import struct Foundation.URL
@@ -33,7 +33,7 @@ func loadFeatures() throws -> [Routeguide_Feature] {
3333
return try Routeguide_Feature.array(fromJSONUTF8Data: data)
3434
}
3535

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

0 commit comments

Comments
 (0)