Skip to content

Commit f0f110a

Browse files
authored
Move availability inline (grpc#68)
Motivation: It's hard for packages to incrementally adopt gRPC with platforms in the package manifest as it requires packages to include platforms in their manifest or mint a new major version. Modifications: - Move platform availability onto source code - Check annotations in CI Result: Easier to adopt
1 parent c96dec7 commit f0f110a

22 files changed

+205
-123
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
with:
1414
linux_5_9_enabled: false
1515
linux_5_10_enabled: false
16-
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors"
17-
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors"
18-
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
19-
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
16+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
17+
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
18+
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-availability"
19+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-availability"
2020

2121
construct-plugin-tests-matrix:
2222
name: Construct plugin tests matrix

.github/workflows/pull_request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
with:
2626
linux_5_9_enabled: false
2727
linux_5_10_enabled: false
28-
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors"
29-
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors"
30-
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
31-
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
28+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
29+
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
30+
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-availability"
31+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-availability"
3232

3333
construct-plugin-tests-matrix:
3434
name: Construct plugin tests matrix

Package.swift

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,36 @@ let products: [Product] = [
3939
let dependencies: [Package.Dependency] = [
4040
.package(
4141
url: "https://github.com/grpc/grpc-swift.git",
42-
from: "2.2.0"
42+
from: "2.2.1"
4343
),
4444
.package(
4545
url: "https://github.com/apple/swift-protobuf.git",
4646
from: "1.28.1"
4747
),
4848
]
4949

50-
let defaultSwiftSettings: [SwiftSetting] = [
51-
.swiftLanguageMode(.v6),
52-
.enableUpcomingFeature("ExistentialAny"),
53-
.enableUpcomingFeature("InternalImportsByDefault"),
54-
.enableUpcomingFeature("MemberImportVisibility"),
55-
]
50+
// -------------------------------------------------------------------------------------------------
51+
52+
// This adds some build settings which allow us to map "@available(gRPCSwiftProtobuf 1.x, *)" to
53+
// the appropriate OS platforms.
54+
let nextMinorVersion = 3
55+
let availabilitySettings: [SwiftSetting] = (0 ... nextMinorVersion).map { minor in
56+
let name = "gRPCSwiftProtobuf"
57+
let version = "1.\(minor)"
58+
let platforms = "macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"
59+
let setting = "AvailabilityMacro=\(name) \(version):\(platforms)"
60+
return .enableExperimentalFeature(setting)
61+
}
62+
63+
let defaultSwiftSettings: [SwiftSetting] =
64+
availabilitySettings + [
65+
.swiftLanguageMode(.v6),
66+
.enableUpcomingFeature("ExistentialAny"),
67+
.enableUpcomingFeature("InternalImportsByDefault"),
68+
.enableUpcomingFeature("MemberImportVisibility"),
69+
]
70+
71+
// -------------------------------------------------------------------------------------------------
5672

5773
var targets: [Target] = [
5874
// protoc plugin for grpc-swift
@@ -190,13 +206,6 @@ if Context.buildCGRPCProtobuf {
190206

191207
let package = Package(
192208
name: "grpc-swift-protobuf",
193-
platforms: [
194-
.macOS(.v15),
195-
.iOS(.v18),
196-
.tvOS(.v18),
197-
.watchOS(.v11),
198-
.visionOS(.v2),
199-
],
200209
products: products,
201210
dependencies: dependencies,
202211
targets: targets

Sources/GRPCProtobuf/Coding.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public import GRPCCore
1818
public import SwiftProtobuf
1919

2020
/// Serializes a Protobuf message into a sequence of bytes.
21+
@available(gRPCSwiftProtobuf 1.0, *)
2122
public struct ProtobufSerializer<Message: SwiftProtobuf.Message>: GRPCCore.MessageSerializer {
2223
public init() {}
2324

@@ -41,6 +42,7 @@ public struct ProtobufSerializer<Message: SwiftProtobuf.Message>: GRPCCore.Messa
4142
}
4243

4344
/// Deserializes a sequence of bytes into a Protobuf message.
45+
@available(gRPCSwiftProtobuf 1.0, *)
4446
public struct ProtobufDeserializer<Message: SwiftProtobuf.Message>: GRPCCore.MessageDeserializer {
4547
public init() {}
4648

Sources/GRPCProtobuf/ContiguousBytesAdapter.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public import SwiftProtobuf // internal but @usableFromInline
2424
/// it'd require a dependency on Protobuf in the core package), and `GRPCContiguousBytes` can't
2525
/// refine `SwiftProtobufContiguousBytes` for the same reason.
2626
@usableFromInline
27+
@available(gRPCSwiftProtobuf 1.0, *)
2728
struct ContiguousBytesAdapter<
2829
Bytes: GRPCContiguousBytes
2930
>: GRPCContiguousBytes, SwiftProtobufContiguousBytes {

Sources/GRPCProtobuf/Errors/ErrorDetails+AnyPacking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extension Google_Protobuf_Any {
6161
}
6262
}
6363

64+
@available(gRPCSwiftProtobuf 1.0, *)
6465
extension ErrorDetails {
6566
// Note: this type isn't packable into an 'Any' protobuf so doesn't conform
6667
// to 'GoogleProtobufAnyPackable' despite holding types which are packable.

Sources/GRPCProtobuf/Errors/ErrorDetails+CustomStringConvertible.swift

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

17+
@available(gRPCSwiftProtobuf 1.0, *)
1718
extension ErrorDetails: CustomStringConvertible {
1819
public var description: String {
1920
switch self.wrapped {
@@ -46,54 +47,63 @@ extension ErrorDetails: CustomStringConvertible {
4647
// Some errors use protobuf messages as their storage so the default description isn't
4748
// representative
4849

50+
@available(gRPCSwiftProtobuf 1.0, *)
4951
extension ErrorDetails.ErrorInfo: CustomStringConvertible {
5052
public var description: String {
5153
"\(Self.self)(reason: \"\(self.reason)\", domain: \"\(self.domain)\", metadata: \(self.metadata))"
5254
}
5355
}
5456

57+
@available(gRPCSwiftProtobuf 1.0, *)
5558
extension ErrorDetails.DebugInfo: CustomStringConvertible {
5659
public var description: String {
5760
"\(Self.self)(stack: \(self.stack), detail: \"\(self.detail)\")"
5861
}
5962
}
6063

64+
@available(gRPCSwiftProtobuf 1.0, *)
6165
extension ErrorDetails.QuotaFailure.Violation: CustomStringConvertible {
6266
public var description: String {
6367
"\(Self.self)(subject: \"\(self.subject)\", violationDescription: \"\(self.violationDescription)\")"
6468
}
6569
}
6670

71+
@available(gRPCSwiftProtobuf 1.0, *)
6772
extension ErrorDetails.PreconditionFailure.Violation: CustomStringConvertible {
6873
public var description: String {
6974
"\(Self.self)(subject: \"\(self.subject)\", type: \"\(self.type)\", violationDescription: \"\(self.violationDescription)\")"
7075
}
7176
}
7277

78+
@available(gRPCSwiftProtobuf 1.0, *)
7379
extension ErrorDetails.BadRequest.FieldViolation: CustomStringConvertible {
7480
public var description: String {
7581
"\(Self.self)(field: \"\(self.field)\", violationDescription: \"\(self.violationDescription)\")"
7682
}
7783
}
7884

85+
@available(gRPCSwiftProtobuf 1.0, *)
7986
extension ErrorDetails.RequestInfo: CustomStringConvertible {
8087
public var description: String {
8188
"\(Self.self)(requestID: \"\(self.requestID)\", servingData: \"\(self.servingData)\")"
8289
}
8390
}
8491

92+
@available(gRPCSwiftProtobuf 1.0, *)
8593
extension ErrorDetails.ResourceInfo: CustomStringConvertible {
8694
public var description: String {
8795
"\(Self.self)(name: \"\(self.name)\", owner: \"\(self.owner)\", type: \"\(self.type)\", errorDescription: \"\(self.errorDescription)\")"
8896
}
8997
}
9098

99+
@available(gRPCSwiftProtobuf 1.0, *)
91100
extension ErrorDetails.Help.Link: CustomStringConvertible {
92101
public var description: String {
93102
"\(Self.self)(url: \"\(self.url)\", linkDescription: \"\(self.linkDescription)\")"
94103
}
95104
}
96105

106+
@available(gRPCSwiftProtobuf 1.0, *)
97107
extension ErrorDetails.LocalizedMessage: CustomStringConvertible {
98108
public var description: String {
99109
"\(Self.self)(locale: \"\(self.locale)\", message: \"\(self.message)\")"

Sources/GRPCProtobuf/Errors/ErrorDetails+Types.swift

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

1717
internal import SwiftProtobuf
1818

19+
@available(gRPCSwiftProtobuf 1.0, *)
1920
extension ErrorDetails {
2021
/// Describes the cause of the error with structured details.
2122
///

Sources/GRPCProtobuf/Errors/ErrorDetails.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public import SwiftProtobuf
2424
///
2525
/// This type also allows you to provide wrap your own error details up as an "Any"
2626
/// protobuf (`Google_Protobuf_Any`).
27+
@available(gRPCSwiftProtobuf 1.0, *)
2728
public struct ErrorDetails: Sendable, Hashable {
2829
enum Wrapped: Sendable, Hashable {
2930
case errorInfo(ErrorInfo)
@@ -198,6 +199,7 @@ public struct ErrorDetails: Sendable, Hashable {
198199
}
199200
}
200201

202+
@available(gRPCSwiftProtobuf 1.0, *)
201203
extension ErrorDetails {
202204
/// Returns error info if set.
203205
public var errorInfo: ErrorInfo? {

Sources/GRPCProtobuf/Errors/GoogleRPCStatus.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public import SwiftProtobuf
3535
/// > inserted into the metadata keyed by "grpc-status-details-bin". The value of the metadata is
3636
/// > the serialized bytes of a "google.rpc.Status" protocol buffers message containing the status
3737
/// > code, message, and details.
38+
@available(gRPCSwiftProtobuf 1.0, *)
3839
public struct GoogleRPCStatus: Error, Hashable {
3940
/// A code representing the high-level domain of the error.
4041
public var code: RPCError.Code
@@ -73,6 +74,7 @@ public struct GoogleRPCStatus: Error, Hashable {
7374
}
7475
}
7576

77+
@available(gRPCSwiftProtobuf 1.0, *)
7678
extension GoogleRPCStatus {
7779
/// Creates a new message by decoding the given `SwiftProtobufContiguousBytes` value
7880
/// containing a serialized message in Protocol Buffer binary format.
@@ -133,6 +135,7 @@ extension GoogleRPCStatus {
133135
}
134136
}
135137

138+
@available(gRPCSwiftProtobuf 1.0, *)
136139
extension GoogleRPCStatus: RPCErrorConvertible {
137140
public var rpcErrorCode: RPCError.Code { self.code }
138141
public var rpcErrorMessage: String { self.message }

0 commit comments

Comments
 (0)