Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
with:
linux_5_9_enabled: false
linux_5_10_enabled: false
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors"
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors"
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
with:
linux_5_9_enabled: false
linux_5_10_enabled: false
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors"
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors"
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors -Xswiftc -require-explicit-availability"
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

Expand Down
36 changes: 23 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import CompilerPluginSupport
import PackageDescription

let products: [Product] = [
Expand Down Expand Up @@ -45,12 +46,28 @@ let dependencies: [Package.Dependency] = [
),
]

let defaultSwiftSettings: [SwiftSetting] = [
.swiftLanguageMode(.v6),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
]
// -------------------------------------------------------------------------------------------------

// This adds some build settings which allow us to map "@available(gRPCSwift 2.x, *)" to
// the appropriate OS platforms.
let nextMinorVersion = 2
let availabilitySettings: [SwiftSetting] = (0 ... nextMinorVersion).map { minor in
let name = "gRPCSwift"
let version = "2.\(minor)"
let platforms = "macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"
let setting = "AvailabilityMacro=\(name) \(version):\(platforms)"
return .enableExperimentalFeature(setting)
}
Comment on lines +53 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we handling each minor separately (instead of just having a gRPCSwift 2 macro) in case we eventually add new APIs that have higher platform requirements?

With this logic, we tie each whole minor to a set of platforms. What if we ever decide to add some new API that requires higher platform requirements, alongside other new API which could keep the previous platform requirements? Would we just bump all of the new APIs to use the new platforms?


let defaultSwiftSettings: [SwiftSetting] =
availabilitySettings + [
.swiftLanguageMode(.v6),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
]

// -------------------------------------------------------------------------------------------------

let targets: [Target] = [
// Runtime serialization components
Expand Down Expand Up @@ -107,13 +124,6 @@ let targets: [Target] = [

let package = Package(
name: "grpc-swift",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
products: products,
dependencies: dependencies,
targets: targets
Expand Down
3 changes: 3 additions & 0 deletions Sources/GRPCCodeGen/CodeGenError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

/// A error thrown by the ``SourceGenerator`` to signal errors in the ``CodeGenerationRequest`` object.
@available(gRPCSwift 2.0, *)
public struct CodeGenError: Error, Hashable, Sendable {
/// The code indicating the domain of the error.
public var code: Code
Expand All @@ -33,6 +34,7 @@ public struct CodeGenError: Error, Hashable, Sendable {
}
}

@available(gRPCSwift 2.0, *)
extension CodeGenError {
public struct Code: Hashable, Sendable {
private enum Value {
Expand Down Expand Up @@ -63,6 +65,7 @@ extension CodeGenError {
}
}

@available(gRPCSwift 2.0, *)
extension CodeGenError: CustomStringConvertible {
public var description: String {
return "\(self.code): \"\(self.message)\""
Expand Down
11 changes: 11 additions & 0 deletions Sources/GRPCCodeGen/CodeGenerationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/// Describes the services, dependencies and trivia from an IDL file,
/// and the IDL itself through its specific serializer and deserializer.
@available(gRPCSwift 2.0, *)
public struct CodeGenerationRequest {
/// The name of the source file containing the IDL, including the extension if applicable.
public var fileName: String
Expand Down Expand Up @@ -81,6 +82,7 @@ public struct CodeGenerationRequest {
}
}

@available(gRPCSwift 2.0, *)
extension CodeGenerationRequest {
@available(*, deprecated, renamed: "makeSerializerSnippet")
public var lookupSerializer: (_ messageType: String) -> String {
Expand Down Expand Up @@ -120,6 +122,7 @@ extension CodeGenerationRequest {
}

/// Represents an import: a module or a specific item from a module.
@available(gRPCSwift 2.0, *)
public struct Dependency: Equatable {
/// If the dependency is an item, the property's value is the item representation.
/// If the dependency is a module, this property is nil.
Expand Down Expand Up @@ -261,6 +264,7 @@ public struct Dependency: Equatable {
}

/// Represents a service described in an IDL file.
@available(gRPCSwift 2.0, *)
public struct ServiceDescriptor: Hashable {
/// Documentation from comments above the IDL service description.
/// It is already formatted, meaning it contains "///" and new lines.
Expand All @@ -285,6 +289,7 @@ public struct ServiceDescriptor: Hashable {
}
}

@available(gRPCSwift 2.0, *)
extension ServiceDescriptor {
@available(*, deprecated, renamed: "init(documentation:name:methods:)")
public init(
Expand Down Expand Up @@ -317,6 +322,7 @@ extension ServiceDescriptor {
}

/// Represents a method described in an IDL file.
@available(gRPCSwift 2.0, *)
public struct MethodDescriptor: Hashable {
/// Documentation from comments above the IDL method description.
/// It is already formatted, meaning it contains "///" and new lines.
Expand Down Expand Up @@ -357,6 +363,7 @@ public struct MethodDescriptor: Hashable {
}
}

@available(gRPCSwift 2.0, *)
extension MethodDescriptor {
@available(*, deprecated, message: "Use MethodName instead of Name")
public init(
Expand All @@ -380,6 +387,7 @@ extension MethodDescriptor {
}
}

@available(gRPCSwift 2.0, *)
public struct ServiceName: Hashable {
/// The identifying name as used in the service/method descriptors including any namespace.
///
Expand Down Expand Up @@ -414,6 +422,7 @@ public struct ServiceName: Hashable {
}
}

@available(gRPCSwift 2.0, *)
public struct MethodName: Hashable {
/// The identifying name as used in the service/method descriptors.
///
Expand Down Expand Up @@ -445,6 +454,7 @@ public struct MethodName: Hashable {

/// Represents the name associated with a namespace, service or a method, in three different formats.
@available(*, deprecated, message: "Use ServiceName/MethodName instead.")
@available(gRPCSwift 2.0, *)
public struct Name: Hashable {
/// The base name is the name used for the namespace/service/method in the IDL file, so it should follow
/// the specific casing of the IDL.
Expand Down Expand Up @@ -473,6 +483,7 @@ public struct Name: Hashable {
}

@available(*, deprecated, message: "Use ServiceName/MethodName instead.")
@available(gRPCSwift 2.0, *)
extension Name {
/// The base name replacing occurrences of "." with "_".
///
Expand Down
6 changes: 6 additions & 0 deletions Sources/GRPCCodeGen/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/

@available(*, deprecated, renamed: "CodeGenerator")
@available(gRPCSwift 2.0, *)
public typealias SourceGenerator = CodeGenerator

/// Generates ``SourceFile`` objects containing generated code for the RPCs represented
/// in a ``CodeGenerationRequest`` object.
@available(gRPCSwift 2.0, *)
public struct CodeGenerator: Sendable {
/// The options regarding the access level, indentation for the generated code
/// and whether to generate server and client code.
Expand All @@ -41,8 +43,10 @@ public struct CodeGenerator: Sendable {
/// Whether or not server code should be generated.
public var server: Bool
/// The name of the core gRPC module.
@available(gRPCSwift 2.1, *)
public var grpcCoreModuleName: String
/// The availability annotations to use on the generated code.
@available(gRPCSwift 2.2, *)
public var availability: AvailabilityAnnotations = .default

/// Creates a new configuration.
Expand Down Expand Up @@ -88,6 +92,7 @@ public struct CodeGenerator: Sendable {
}

// The availability that generated code is annotated with.
@available(gRPCSwift 2.2, *)
public struct AvailabilityAnnotations: Sendable, Hashable {
public struct Platform: Sendable, Hashable {
/// The name of the OS, e.g. 'macOS'.
Expand Down Expand Up @@ -156,6 +161,7 @@ public struct CodeGenerator: Sendable {
}
}

@available(gRPCSwift 2.0, *)
extension AvailabilityDescription {
init(_ availability: CodeGenerator.Config.AvailabilityAnnotations) throws {
switch availability.wrapped {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/// into Swift files.
///
/// Rendering is the last phase of the generator pipeline.
@available(gRPCSwift 2.0, *)
protocol RendererProtocol {

/// Renders the specified structured code into a raw Swift file.
Expand Down
2 changes: 2 additions & 0 deletions Sources/GRPCCodeGen/Internal/Renderer/TextBasedRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ extension TextBasedRenderer: Sendable {}

/// A renderer that uses string interpolation and concatenation
/// to convert the provided structure code into raw string form.
@available(gRPCSwift 2.0, *)
struct TextBasedRenderer: RendererProtocol {

func render(
Expand Down Expand Up @@ -1207,6 +1208,7 @@ extension String {
}
}

@available(gRPCSwift 2.0, *)
extension TextBasedRenderer {

/// Returns the provided expression rendered as a string.
Expand Down
6 changes: 6 additions & 0 deletions Sources/GRPCCodeGen/Internal/StructuredSwift+Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ extension FunctionDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ProtocolDescription {
/// ```
/// protocol <Name>: Sendable {
Expand Down Expand Up @@ -233,6 +234,7 @@ extension ProtocolDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ExtensionDescription {
/// ```
/// extension <Name> {
Expand Down Expand Up @@ -503,6 +505,7 @@ extension FunctionDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ExtensionDescription {
/// ```
/// extension <Name> {
Expand Down Expand Up @@ -662,6 +665,7 @@ extension FunctionDescription {
}
}

@available(gRPCSwift 2.0, *)
extension StructDescription {
/// ```
/// struct <Name><Transport>: <ClientProtocol> where Transport: GRPCCore.ClientTransport {
Expand Down Expand Up @@ -752,6 +756,7 @@ extension StructDescription {
}
}

@available(gRPCSwift 2.0, *)
private func docs(
for method: MethodDescriptor,
serializers includeSerializers: Bool = true
Expand Down Expand Up @@ -793,6 +798,7 @@ private func docs(
return Docs.interposeDocs(method.documentation, between: summary, and: allParameters)
}

@available(gRPCSwift 2.0, *)
private func explodedDocs(for method: MethodDescriptor) -> String {
let summary = "/// Call the \"\(method.name.identifyingName)\" method."
var parameters = """
Expand Down
7 changes: 7 additions & 0 deletions Sources/GRPCCodeGen/Internal/StructuredSwift+Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extension FunctionSignatureDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ProtocolDescription {
/// ```
/// protocol <Name>: GRPCCore.RegistrableRPCService {
Expand Down Expand Up @@ -101,6 +102,7 @@ extension ProtocolDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ExtensionDescription {
/// ```
/// extension <ExtensionName> {
Expand Down Expand Up @@ -136,6 +138,7 @@ extension ExtensionDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ProtocolDescription {
/// ```
/// protocol <Name>: <StreamingProtocol> {
Expand Down Expand Up @@ -304,6 +307,7 @@ extension FunctionCallDescription {
}
}

@available(gRPCSwift 2.0, *)
extension FunctionDescription {
/// ```
/// func registerMethods(with router: inout GRPCCore.RPCRouter) {
Expand Down Expand Up @@ -451,6 +455,7 @@ extension FunctionDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ExtensionDescription {
/// ```
/// extension <ExtensionName> {
Expand Down Expand Up @@ -548,6 +553,7 @@ extension FunctionSignatureDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ProtocolDescription {
/// ```
/// protocol SimpleServiceProtocol: <ServiceProtocol> {
Expand Down Expand Up @@ -763,6 +769,7 @@ extension FunctionDescription {
}
}

@available(gRPCSwift 2.0, *)
extension ExtensionDescription {
/// ```
/// extension ServiceProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ extension VariableDescription {
}
}

@available(gRPCSwift 2.0, *)
extension EnumDescription {
/// ```
/// enum <Method> {
Expand Down Expand Up @@ -340,6 +341,7 @@ extension EnumDescription {
}
}

@available(gRPCSwift 2.0, *)
extension [CodeBlock] {
/// ```
/// enum <Service> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
/// }
/// }
///```
@available(gRPCSwift 2.0, *)
struct ClientCodeTranslator {
init() {}

Expand Down
1 change: 1 addition & 0 deletions Sources/GRPCCodeGen/Internal/Translator/Docs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

@available(gRPCSwift 2.0, *)
package enum Docs {
package static func suffix(_ header: String, withDocs footer: String) -> String {
if footer.isEmpty {
Expand Down
Loading