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,

0 commit comments

Comments
 (0)