Skip to content

Commit de27489

Browse files
authored
Allow building on iOS 12 (#100)
The necessary async/await APIs are only available on iOS 13+, so code generated using the `GenerateAsyncMethods=true` option will be unavailable on iOS 12.
1 parent 44d6f12 commit de27489

File tree

15 files changed

+109
-2
lines changed

15 files changed

+109
-2
lines changed

.swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ modifier_order:
105105
- dynamic
106106
- convenience
107107
deployment_target:
108-
iOS_deployment_target: 13.0
108+
iOS_deployment_target: 12.0
109109

110110
custom_rules:
111111
newline_after_brace:

Examples/ElizaSharedSources/GeneratedSources/eliza.connect.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ internal protocol Buf_Connect_Demo_Eliza_V1_ElizaServiceClientInterface {
1717

1818
/// Say is a unary request demo. This method should allow for a one sentence
1919
/// response given a one sentence request.
20+
@available(iOS 13, *)
2021
func `say`(request: Buf_Connect_Demo_Eliza_V1_SayRequest, headers: Connect.Headers) async -> ResponseMessage<Buf_Connect_Demo_Eliza_V1_SayResponse>
2122

2223
/// Converse is a bi-directional streaming request demo. This method should allow for
2324
/// many requests and many responses.
25+
@available(iOS 13, *)
2426
func `converse`(headers: Connect.Headers) -> any Connect.BidirectionalAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_ConverseRequest, Buf_Connect_Demo_Eliza_V1_ConverseResponse>
2527

2628
/// Introduce is a server-streaming request demo. This method allows for a single request that will return a series
2729
/// of responses
30+
@available(iOS 13, *)
2831
func `introduce`(headers: Connect.Headers) -> any Connect.ServerOnlyAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_IntroduceRequest, Buf_Connect_Demo_Eliza_V1_IntroduceResponse>
2932
}
3033

@@ -36,14 +39,17 @@ internal final class Buf_Connect_Demo_Eliza_V1_ElizaServiceClient: Buf_Connect_D
3639
self.client = client
3740
}
3841

42+
@available(iOS 13, *)
3943
internal func `say`(request: Buf_Connect_Demo_Eliza_V1_SayRequest, headers: Connect.Headers = [:]) async -> ResponseMessage<Buf_Connect_Demo_Eliza_V1_SayResponse> {
4044
return await self.client.unary(path: "buf.connect.demo.eliza.v1.ElizaService/Say", request: request, headers: headers)
4145
}
4246

47+
@available(iOS 13, *)
4348
internal func `converse`(headers: Connect.Headers = [:]) -> any Connect.BidirectionalAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_ConverseRequest, Buf_Connect_Demo_Eliza_V1_ConverseResponse> {
4449
return self.client.bidirectionalStream(path: "buf.connect.demo.eliza.v1.ElizaService/Converse", headers: headers)
4550
}
4651

52+
@available(iOS 13, *)
4753
internal func `introduce`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_IntroduceRequest, Buf_Connect_Demo_Eliza_V1_IntroduceResponse> {
4854
return self.client.serverOnlyStream(path: "buf.connect.demo.eliza.v1.ElizaService/Introduce", headers: headers)
4955
}

Libraries/Connect/Implementation/ProtocolClient.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ extension ProtocolClient: ProtocolClientInterface {
161161

162162
// MARK: - Async/await
163163

164+
@available(iOS 13, *)
164165
public func unary<
165166
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
166167
>(
@@ -173,6 +174,7 @@ extension ProtocolClient: ProtocolClientInterface {
173174
}.send()
174175
}
175176

177+
@available(iOS 13, *)
176178
public func bidirectionalStream<
177179
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
178180
>(
@@ -186,6 +188,7 @@ extension ProtocolClient: ProtocolClientInterface {
186188
return bidirectionalAsync.configureForSending(with: callbacks)
187189
}
188190

191+
@available(iOS 13, *)
189192
public func clientOnlyStream<
190193
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
191194
>(
@@ -199,6 +202,7 @@ extension ProtocolClient: ProtocolClientInterface {
199202
return bidirectionalAsync.configureForSending(with: callbacks)
200203
}
201204

205+
@available(iOS 13, *)
202206
public func serverOnlyStream<
203207
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
204208
>(

Libraries/Connect/Implementation/Streaming/BidirectionalAsyncStream.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import SwiftProtobuf
1717
/// Concrete implementation of `BidirectionalAsyncStreamInterface`.
1818
/// Provides the necessary wiring to bridge from closures/callbacks to Swift's `AsyncStream`
1919
/// to work with async/await.
20+
@available(iOS 13, *)
2021
final class BidirectionalAsyncStream<Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message> {
2122
/// The underlying async stream that will be exposed to the consumer.
2223
/// Force unwrapped because it captures `self` on `init`.
@@ -81,6 +82,7 @@ final class BidirectionalAsyncStream<Input: SwiftProtobuf.Message, Output: Swift
8182
}
8283
}
8384

85+
@available(iOS 13, *)
8486
extension BidirectionalAsyncStream: BidirectionalAsyncStreamInterface {
8587
@discardableResult
8688
func send(_ input: Input) throws -> Self {
@@ -102,4 +104,5 @@ extension BidirectionalAsyncStream: BidirectionalAsyncStreamInterface {
102104
}
103105

104106
// Conforms to the client-only interface since it matches exactly and the implementation is internal
107+
@available(iOS 13, *)
105108
extension BidirectionalAsyncStream: ClientOnlyAsyncStreamInterface {}

Libraries/Connect/Implementation/Streaming/ServerOnlyAsyncStream.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import SwiftProtobuf
1616

1717
/// Concrete implementation of `ServerOnlyAsyncStreamInterface`.
18+
@available(iOS 13, *)
1819
final class ServerOnlyAsyncStream<Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message> {
1920
private let bidirectionalStream: BidirectionalAsyncStream<Input, Output>
2021

@@ -23,6 +24,7 @@ final class ServerOnlyAsyncStream<Input: SwiftProtobuf.Message, Output: SwiftPro
2324
}
2425
}
2526

27+
@available(iOS 13, *)
2628
extension ServerOnlyAsyncStream: ServerOnlyAsyncStreamInterface {
2729
func send(_ input: Input) throws {
2830
try self.bidirectionalStream.send(input)

Libraries/Connect/Implementation/UnaryAsyncWrapper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import SwiftProtobuf
2020
/// For discussions on why this is necessary, see:
2121
/// https://forums.swift.org/t/how-to-use-withtaskcancellationhandler-properly/54341/37
2222
/// https://stackoverflow.com/q/71898080
23+
@available(iOS 13, *)
2324
actor UnaryAsyncWrapper<Output: SwiftProtobuf.Message> {
2425
private var cancelable: Cancelable?
2526
private let sendUnary: PerformClosure

Libraries/Connect/Interfaces/ProtocolClientInterface.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public protocol ProtocolClientInterface {
114114
/// - parameter headers: The outbound request headers to include.
115115
///
116116
/// - returns: The response which is returned asynchronously.
117+
@available(iOS 13, *)
117118
func unary<
118119
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
119120
>(
@@ -134,6 +135,7 @@ public protocol ProtocolClientInterface {
134135
/// - parameter headers: The outbound request headers to include.
135136
///
136137
/// - returns: An interface for sending and receiving data over the stream using async/await.
138+
@available(iOS 13, *)
137139
func bidirectionalStream<
138140
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
139141
>(
@@ -153,6 +155,7 @@ public protocol ProtocolClientInterface {
153155
/// - parameter headers: The outbound request headers to include.
154156
///
155157
/// - returns: An interface for sending and receiving data over the stream using async/await.
158+
@available(iOS 13, *)
156159
func clientOnlyStream<
157160
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
158161
>(
@@ -172,6 +175,7 @@ public protocol ProtocolClientInterface {
172175
/// - parameter headers: The outbound request headers to include.
173176
///
174177
/// - returns: An interface for sending and receiving data over the stream using async/await.
178+
@available(iOS 13, *)
175179
func serverOnlyStream<
176180
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
177181
>(

Libraries/Connect/Interfaces/Streams/BidirectionalAsyncStreamInterface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import SwiftProtobuf
1616

1717
/// Represents a bidirectional stream that can be interacted with using async/await.
18+
@available(iOS 13, *)
1819
public protocol BidirectionalAsyncStreamInterface<Input, Output> {
1920
/// The input (request) message type.
2021
associatedtype Input: SwiftProtobuf.Message

Libraries/Connect/Interfaces/Streams/ClientOnlyAsyncStreamInterface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import SwiftProtobuf
1616

1717
/// Represents a client-only stream (a stream where the client streams data to the server and
1818
/// eventually receives a response) that can be interacted with using async/await.
19+
@available(iOS 13, *)
1920
public protocol ClientOnlyAsyncStreamInterface<Input, Output> {
2021
/// The input (request) message type.
2122
associatedtype Input: SwiftProtobuf.Message

Libraries/Connect/Interfaces/Streams/ServerOnlyAsyncStreamInterface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import SwiftProtobuf
1616

1717
/// Represents a server-only stream (a stream where the server streams data to the client after
1818
/// receiving an initial request) that can be interacted with using async/await.
19+
@available(iOS 13, *)
1920
public protocol ServerOnlyAsyncStreamInterface<Input, Output> {
2021
/// The input (request) message type.
2122
associatedtype Input: SwiftProtobuf.Message

0 commit comments

Comments
 (0)