Skip to content

Commit 4bd354e

Browse files
Update available to fix build for non-macOS Apple platforms (#1746)
## Motivation The package currently doesn't build for non-macOS Apple platforms, e.g. iOS, because of missing `@available` annotations, mostly in tests. ## Modifications - Add missing `@available` annotations. - Use `#if os(macOS) || os(Linux)` in test utils that require `Foundation.Process`. Ideally we'd use `#if canImport(Foundation.Process)`, but the version of `swift-format` used by this project doesn't understand it. ## Result Code and tests can build for, and run on, other platforms, e.g. iOS.
1 parent 4570d0f commit 4bd354e

28 files changed

+55
-3
lines changed

Sources/Examples/PacketCapture/PacketCapture.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import NIOExtras
2121
import NIOPosix
2222

2323
@main
24-
@available(macOS 10.15, *)
24+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2525
struct PCAP: AsyncParsableCommand {
2626
@Option(help: "The port to connect to")
2727
var port = 1234

Tests/GRPCCodeGenTests/Internal/Translator/SnippetBasedTranslatorTests.swift

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

17+
#if os(macOS) || os(Linux) // swift-format doesn't like canImport(Foundation.Process)
18+
1719
import XCTest
1820

1921
@testable import GRPCCodeGen
@@ -517,3 +519,5 @@ extension SnippetBasedTranslatorTests {
517519
)
518520
}
519521
}
522+
523+
#endif // os(macOS) || os(Linux)

Tests/GRPCCodeGenTests/Internal/Translator/TestFunctions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
// SPDX-License-Identifier: Apache-2.0
2727
//
2828
//===----------------------------------------------------------------------===//
29+
30+
#if os(macOS) || os(Linux) // swift-format doesn't like canImport(Foundation.Process)
31+
2932
import XCTest
3033

3134
private func diff(expected: String, actual: String) throws -> String {
@@ -65,3 +68,5 @@ internal func XCTAssertEqualWithDiff(
6568
line: line
6669
)
6770
}
71+
72+
#endif // os(macOS) || os(Linux)

Tests/GRPCCoreTests/Call/Client/ClientResponseTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import XCTest
1818

1919
@testable import GRPCCore
2020

21+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2122
final class ClientResponseTests: XCTestCase {
2223
func testAcceptedSingleResponseConvenienceMethods() {
2324
let response = ClientResponse.Single(

Tests/GRPCCoreTests/Call/Server/ServerRequestTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@_spi(Testing) import GRPCCore
1717
import XCTest
1818

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1920
final class ServerRequestTests: XCTestCase {
2021
func testSingleToStreamConversion() async throws {
2122
let single = ServerRequest.Single(metadata: ["bar": "baz"], message: "foo")

Tests/GRPCCoreTests/Call/Server/ServerResponseTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@_spi(Testing) import GRPCCore
1717
import XCTest
1818

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1920
final class ServerResponseTests: XCTestCase {
2021
func testSingleConvenienceInit() {
2122
var response = ServerResponse.Single(

Tests/GRPCCoreTests/ServerErrorTests.swift

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

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1920
final class ServerErrorTests: XCTestCase {
2021
func testCopyOnWrite() {
2122
// ServerError has a heap based storage, so check CoW semantics are correctly implemented.

Tests/GRPCCoreTests/Streaming/Internal/AsyncSequenceOfOne.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import XCTest
1818

1919
@testable import GRPCCore
2020

21+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2122
internal final class AsyncSequenceOfOneTests: XCTestCase {
2223
func testSuccessPath() async throws {
2324
let sequence = RPCAsyncSequence.one("foo")

Tests/GRPCCoreTests/Streaming/Internal/BufferedStreamTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ final class BufferedStreamTests: XCTestCase {
10801080
}
10811081
}
10821082

1083+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
10831084
extension BufferedStream.Source.WriteResult {
10841085
func assertIsProducerMore() {
10851086
switch self {

Tests/GRPCCoreTests/Test Utilities/AsyncSequence+Utilities.swift

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

17+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1718
extension AsyncSequence {
1819
func collect() async throws -> [Element] {
1920
return try await self.reduce(into: []) { $0.append($1) }
2021
}
2122
}
2223

2324
#if swift(<5.9)
25+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2426
extension AsyncStream {
2527
static func makeStream(
2628
of elementType: Element.Type = Element.self,
@@ -34,6 +36,7 @@ extension AsyncStream {
3436
}
3537
}
3638

39+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3740
extension AsyncThrowingStream {
3841
static func makeStream(
3942
of elementType: Element.Type = Element.self,

Tests/GRPCCoreTests/Test Utilities/Call/Client/ClientInterceptors.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import Atomics
1717
import GRPCCore
1818

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1920
extension ClientInterceptor where Self == RejectAllClientInterceptor {
2021
static func rejectAll(with error: RPCError) -> Self {
2122
return RejectAllClientInterceptor(error: error, throw: false)
@@ -27,13 +28,15 @@ extension ClientInterceptor where Self == RejectAllClientInterceptor {
2728

2829
}
2930

31+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3032
extension ClientInterceptor where Self == RequestCountingClientInterceptor {
3133
static func requestCounter(_ counter: ManagedAtomic<Int>) -> Self {
3234
return RequestCountingClientInterceptor(counter: counter)
3335
}
3436
}
3537

3638
/// Rejects all RPCs with the provided error.
39+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3740
struct RejectAllClientInterceptor: ClientInterceptor {
3841
/// The error to reject all RPCs with.
3942
let error: RPCError
@@ -62,6 +65,7 @@ struct RejectAllClientInterceptor: ClientInterceptor {
6265
}
6366
}
6467

68+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
6569
struct RequestCountingClientInterceptor: ClientInterceptor {
6670
/// The number of requests made.
6771
let counter: ManagedAtomic<Int>

Tests/GRPCCoreTests/Test Utilities/Call/Server/ServerInterceptors.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import Atomics
1717
import GRPCCore
1818

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1920
extension ServerInterceptor where Self == RejectAllServerInterceptor {
2021
static func rejectAll(with error: RPCError) -> Self {
2122
return RejectAllServerInterceptor(error: error, throw: false)
@@ -26,13 +27,15 @@ extension ServerInterceptor where Self == RejectAllServerInterceptor {
2627
}
2728
}
2829

30+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2931
extension ServerInterceptor where Self == RequestCountingServerInterceptor {
3032
static func requestCounter(_ counter: ManagedAtomic<Int>) -> Self {
3133
return RequestCountingServerInterceptor(counter: counter)
3234
}
3335
}
3436

3537
/// Rejects all RPCs with the provided error.
38+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3639
struct RejectAllServerInterceptor: ServerInterceptor {
3740
/// The error to reject all RPCs with.
3841
let error: RPCError
@@ -61,6 +64,7 @@ struct RejectAllServerInterceptor: ServerInterceptor {
6164
}
6265
}
6366

67+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
6468
struct RequestCountingServerInterceptor: ServerInterceptor {
6569
/// The number of requests made.
6670
let counter: ManagedAtomic<Int>

Tests/GRPCCoreTests/Test Utilities/RPCAsyncSequence+Utilities.swift

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

18+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1819
extension RPCAsyncSequence {
1920
static func elements(_ elements: Element...) -> Self {
2021
return .elements(elements)

Tests/GRPCCoreTests/Test Utilities/RPCWriter+Utilities.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import GRPCCore
1717
import XCTest
1818

19+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1920
extension RPCWriter {
2021
/// Returns a writer which calls `XCTFail(_:)` on every write.
2122
static func failTestOnWrite(elementType: Element.Type = Element.self) -> Self {
@@ -28,12 +29,14 @@ extension RPCWriter {
2829
}
2930
}
3031

32+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3133
private struct FailOnWrite<Element>: RPCWriterProtocol {
3234
func write(contentsOf elements: some Sequence<Element>) async throws {
3335
XCTFail("Unexpected write")
3436
}
3537
}
3638

39+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3740
private struct AsyncStreamGatheringWriter<Element>: RPCWriterProtocol {
3841
let continuation: AsyncStream<Element>.Continuation
3942

Tests/GRPCCoreTests/Test Utilities/Services/BinaryEcho.swift

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

19+
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
1920
struct BinaryEcho: RegistrableRPCService {
2021
func get(
2122
_ request: ServerRequest.Single<[UInt8]>

Tests/GRPCCoreTests/Test Utilities/Transport/ThrowingTransport.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct ThrowOnStreamCreationTransport: ClientTransport {
5050
}
5151
}
5252

53+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
5354
struct ThrowOnRunServerTransport: ServerTransport {
5455
func listen() async throws -> RPCAsyncSequence<RPCStream<Inbound, Outbound>> {
5556
throw RPCError(
@@ -63,6 +64,7 @@ struct ThrowOnRunServerTransport: ServerTransport {
6364
}
6465
}
6566

67+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
6668
struct ThrowOnSignalServerTransport: ServerTransport {
6769
let signal: AsyncStream<Void>
6870

Tests/GRPCCoreTests/Test Utilities/XCTest+Utilities.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func XCTAssertDescription(
2525
XCTAssertEqual(String(describing: subject), expected, file: file, line: line)
2626
}
2727

28+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2829
func XCTAssertThrowsErrorAsync<T>(
2930
_ expression: () async throws -> T,
3031
errorHandler: (Error) -> Void
@@ -50,6 +51,7 @@ func XCTAssertThrowsError<T, E: Error>(
5051
}
5152
}
5253

54+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
5355
func XCTAssertThrowsErrorAsync<T, E: Error>(
5456
ofType: E.Type = E.self,
5557
_ expression: () async throws -> T,
@@ -78,6 +80,7 @@ func XCTAssertThrowsRPCError<T>(
7880
}
7981
}
8082

83+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
8184
func XCTAssertThrowsRPCErrorAsync<T>(
8285
_ expression: () async throws -> T,
8386
errorHandler: (RPCError) -> Void
@@ -92,6 +95,7 @@ func XCTAssertThrowsRPCErrorAsync<T>(
9295
}
9396
}
9497

98+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
9599
func XCTAssertRejected<T>(
96100
_ response: ClientResponse.Stream<T>,
97101
errorHandler: (RPCError) -> Void
@@ -128,6 +132,7 @@ func XCTAssertMetadata(
128132
}
129133
}
130134

135+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
131136
func XCTAssertMetadata(
132137
_ part: RPCRequestPart?,
133138
metadataHandler: (Metadata) async throws -> Void = { _ in }
@@ -152,6 +157,7 @@ func XCTAssertMessage(
152157
}
153158
}
154159

160+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
155161
func XCTAssertMessage(
156162
_ part: RPCRequestPart?,
157163
messageHandler: ([UInt8]) async throws -> Void = { _ in }

Tests/GRPCCoreTests/TimeoutTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import XCTest
1717

1818
@testable import GRPCCore
1919

20+
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
2021
final class TimeoutTests: XCTestCase {
2122
func testDecodeInvalidTimeout_Empty() {
2223
let timeoutHeader = ""

Tests/GRPCInProcessTransportTests/InProcessServerTransportTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import XCTest
1919
@testable import GRPCCore
2020
@testable import GRPCInProcessTransport
2121

22+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2223
final class InProcessServerTransportTests: XCTestCase {
2324
func testStartListening() async throws {
2425
let transport = InProcessServerTransport()

Tests/GRPCInProcessTransportTests/Test Utilities/XCTest+Utilities.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func XCTAssertThrowsError<T, E: Error>(
2828
}
2929
}
3030

31+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3132
func XCTAssertThrowsErrorAsync<T, E: Error>(
3233
ofType: E.Type = E.self,
3334
_ expression: () async throws -> T,

Tests/GRPCTests/AsyncAwaitSupport/AsyncServerHandler/ServerHandlerStateMachine/ServerHandlerStateMachineTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ internal final class ServerHandlerStateMachineTests: GRPCTestCase {
265265

266266
// MARK: - Action Assertions
267267

268+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
268269
extension ServerHandlerStateMachine.HandleMetadataAction {
269270
func assertInvokeHandler() {
270271
XCTAssertEqual(self, .invokeHandler)
@@ -275,6 +276,7 @@ extension ServerHandlerStateMachine.HandleMetadataAction {
275276
}
276277
}
277278

279+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
278280
extension ServerHandlerStateMachine.HandleMessageAction {
279281
func assertForward() {
280282
XCTAssertEqual(self, .forward)
@@ -285,6 +287,7 @@ extension ServerHandlerStateMachine.HandleMessageAction {
285287
}
286288
}
287289

290+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
288291
extension ServerHandlerStateMachine.SendMessageAction {
289292
func assertInterceptHeadersThenMessage(_ verify: (HPACKHeaders) -> Void = { _ in }) {
290293
switch self {
@@ -304,6 +307,7 @@ extension ServerHandlerStateMachine.SendMessageAction {
304307
}
305308
}
306309

310+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
307311
extension ServerHandlerStateMachine.SendStatusAction {
308312
func assertIntercept(_ verify: (HPACKHeaders) -> Void = { _ in }) {
309313
switch self {
@@ -319,6 +323,7 @@ extension ServerHandlerStateMachine.SendStatusAction {
319323
}
320324
}
321325

326+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
322327
extension ServerHandlerStateMachine.CancelAction {
323328
func assertNone() {
324329
XCTAssertEqual(self, .none)

Tests/GRPCTests/EchoMetadataTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal final class EchoMetadataTests: GRPCTestCase {
8181
self.testServiceDescriptor(Echo_EchoClientMetadata.serviceDescriptor)
8282
self.testServiceDescriptor(Echo_EchoServerMetadata.serviceDescriptor)
8383

84-
if #available(macOS 12, *) {
84+
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
8585
self.testServiceDescriptor(Echo_EchoAsyncClient.serviceDescriptor)
8686
}
8787
}

Tests/GRPCTests/GRPCAsyncClientCallTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ private actor RequestResponseCounter {
334334
}
335335
}
336336

337+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
337338
private final class AsyncEchoProvider: Echo_EchoAsyncProvider {
338339
let headers: HPACKHeaders
339340
let sendTwice: Bool

Tests/GRPCTests/GRPCAsyncServerHandlerTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ class AsyncServerHandlerTests: GRPCTestCase {
522522
}
523523
}
524524

525+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
525526
internal final class AsyncResponseStream: GRPCServerResponseWriter {
526527
private let source:
527528
NIOAsyncSequenceProducer<

Tests/GRPCTests/GRPCNetworkFrameworkTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import NIOTransportServices
2727
import Security
2828
import XCTest
2929

30-
@available(macOS 10.14, iOS 12.0, watchOS 6.0, tvOS 12.0, *)
30+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
3131
final class GRPCNetworkFrameworkTests: GRPCTestCase {
3232
private var server: Server!
3333
private var client: ClientConnection!

Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceIntegrationTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import XCTest
2323

2424
@testable import GRPCReflectionService
2525

26+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2627
final class ReflectionServiceIntegrationTests: GRPCTestCase {
2728
private var server: Server?
2829
private var channel: GRPCChannel?

Tests/GRPCTests/GRPCReflectionServiceTests/ReflectionServiceUnitTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import XCTest
2222

2323
@testable import GRPCReflectionService
2424

25+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
2526
final class ReflectionServiceUnitTests: GRPCTestCase {
2627
/// Testing the fileDescriptorDataByFilename dictionary of the ReflectionServiceData object.
2728
func testFileDescriptorDataByFilename() throws {

0 commit comments

Comments
 (0)