Skip to content

Commit df605cd

Browse files
authored
Move to grpc-swift-2 (grpc#70)
Motivation: To support incremental migration, v2 has moved to the 'grpc-swift-2' package. Modifications: - Update dependencies - Update generated code - Re-baseline availability - Rename 'protoc-gen-grpc-swift' to 'protoc-gen-grpc-swift-2' Result: Easier to migrate from gRPC Swift 1 to 2
1 parent f0f110a commit df605cd

30 files changed

+139
-139
lines changed

IntegrationTests/PluginTests/Resources/Sources/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ let package = Package(
2929
dependencies: [
3030
// Dependency on grpc-swift-protobuf to be added by setup-plugin-tests.sh script
3131
.package(
32-
url: "https://github.com/grpc/grpc-swift.git",
32+
url: "https://github.com/grpc/grpc-swift-2.git",
3333
from: "2.0.0"
3434
)
3535
],
3636
targets: [
3737
.executableTarget(
3838
name: "grpc-adopter",
3939
dependencies: [
40-
.product(name: "GRPCCore", package: "grpc-swift"),
41-
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
40+
.product(name: "GRPCCore", package: "grpc-swift-2"),
41+
.product(name: "GRPCInProcessTransport", package: "grpc-swift-2"),
4242
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
4343
],
4444
plugins: [

Package.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ let products: [Product] = [
2323
targets: ["GRPCProtobuf"]
2424
),
2525
.executable(
26-
name: "protoc-gen-grpc-swift",
27-
targets: ["protoc-gen-grpc-swift"]
26+
name: "protoc-gen-grpc-swift-2",
27+
targets: ["protoc-gen-grpc-swift-2"]
2828
),
2929
.plugin(
3030
name: "GRPCProtobufGenerator",
@@ -38,8 +38,8 @@ let products: [Product] = [
3838

3939
let dependencies: [Package.Dependency] = [
4040
.package(
41-
url: "https://github.com/grpc/grpc-swift.git",
42-
from: "2.2.1"
41+
url: "https://github.com/grpc/grpc-swift-2.git",
42+
from: "2.0.0"
4343
),
4444
.package(
4545
url: "https://github.com/apple/swift-protobuf.git",
@@ -49,12 +49,12 @@ let dependencies: [Package.Dependency] = [
4949

5050
// -------------------------------------------------------------------------------------------------
5151

52-
// This adds some build settings which allow us to map "@available(gRPCSwiftProtobuf 1.x, *)" to
52+
// This adds some build settings which allow us to map "@available(gRPCSwiftProtobuf 2.x, *)" to
5353
// the appropriate OS platforms.
54-
let nextMinorVersion = 3
54+
let nextMinorVersion = 1
5555
let availabilitySettings: [SwiftSetting] = (0 ... nextMinorVersion).map { minor in
5656
let name = "gRPCSwiftProtobuf"
57-
let version = "1.\(minor)"
57+
let version = "2.\(minor)"
5858
let platforms = "macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"
5959
let setting = "AvailabilityMacro=\(name) \(version):\(platforms)"
6060
return .enableExperimentalFeature(setting)
@@ -71,12 +71,12 @@ let defaultSwiftSettings: [SwiftSetting] =
7171
// -------------------------------------------------------------------------------------------------
7272

7373
var targets: [Target] = [
74-
// protoc plugin for grpc-swift
74+
// protoc plugin for grpc-swift-2
7575
.executableTarget(
76-
name: "protoc-gen-grpc-swift",
76+
name: "protoc-gen-grpc-swift-2",
7777
dependencies: [
7878
.target(name: "GRPCProtobufCodeGen"),
79-
.product(name: "GRPCCodeGen", package: "grpc-swift"),
79+
.product(name: "GRPCCodeGen", package: "grpc-swift-2"),
8080
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
8181
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
8282
],
@@ -87,7 +87,7 @@ var targets: [Target] = [
8787
.target(
8888
name: "GRPCProtobuf",
8989
dependencies: [
90-
.product(name: "GRPCCore", package: "grpc-swift"),
90+
.product(name: "GRPCCore", package: "grpc-swift-2"),
9191
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
9292
],
9393
swiftSettings: defaultSwiftSettings
@@ -96,18 +96,18 @@ var targets: [Target] = [
9696
name: "GRPCProtobufTests",
9797
dependencies: [
9898
.target(name: "GRPCProtobuf"),
99-
.product(name: "GRPCCore", package: "grpc-swift"),
100-
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
99+
.product(name: "GRPCCore", package: "grpc-swift-2"),
100+
.product(name: "GRPCInProcessTransport", package: "grpc-swift-2"),
101101
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
102102
],
103103
swiftSettings: defaultSwiftSettings
104104
),
105105

106-
// Code generator library for protoc-gen-grpc-swift
106+
// Code generator library for protoc-gen-grpc-swift-2
107107
.target(
108108
name: "GRPCProtobufCodeGen",
109109
dependencies: [
110-
.product(name: "GRPCCodeGen", package: "grpc-swift"),
110+
.product(name: "GRPCCodeGen", package: "grpc-swift-2"),
111111
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
112112
],
113113
swiftSettings: defaultSwiftSettings
@@ -116,7 +116,7 @@ var targets: [Target] = [
116116
name: "GRPCProtobufCodeGenTests",
117117
dependencies: [
118118
.target(name: "GRPCProtobufCodeGen"),
119-
.product(name: "GRPCCodeGen", package: "grpc-swift"),
119+
.product(name: "GRPCCodeGen", package: "grpc-swift-2"),
120120
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
121121
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
122122
],
@@ -131,7 +131,7 @@ var targets: [Target] = [
131131
name: "GRPCProtobufGenerator",
132132
capability: .buildTool(),
133133
dependencies: [
134-
.target(name: "protoc-gen-grpc-swift"),
134+
.target(name: "protoc-gen-grpc-swift-2"),
135135
.product(name: "protoc-gen-swift", package: "swift-protobuf"),
136136
]
137137
),
@@ -152,7 +152,7 @@ var targets: [Target] = [
152152
]
153153
),
154154
dependencies: [
155-
.target(name: "protoc-gen-grpc-swift"),
155+
.target(name: "protoc-gen-grpc-swift-2"),
156156
.product(name: "protoc-gen-swift", package: "swift-protobuf"),
157157
],
158158
path: "Plugins/GRPCProtobufGeneratorCommand"
@@ -196,7 +196,7 @@ if Context.buildCGRPCProtobuf {
196196
)
197197

198198
for target in targets {
199-
if target.name == "protoc-gen-grpc-swift" {
199+
if target.name == "protoc-gen-grpc-swift-2" {
200200
target.dependencies.append(.target(name: "CGRPCProtobuf"))
201201
}
202202
}

Plugins/GRPCProtobufGenerator/Plugin.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct GRPCProtobufGenerator {
7070
) throws -> [Command] {
7171
let configs = try readConfigFiles(configFiles, pluginWorkDirectory: pluginWorkDirectory)
7272

73-
let protocGenGRPCSwiftPath = try tool("protoc-gen-grpc-swift").url
73+
let protocGenGRPCSwiftPath = try tool("protoc-gen-grpc-swift-2").url
7474
let protocGenSwiftPath = try tool("protoc-gen-swift").url
7575

7676
var commands: [Command] = []
@@ -165,16 +165,16 @@ extension [URL: GenerationConfig] {
165165
}
166166
}
167167

168-
/// Construct the command to invoke `protoc` with the `protoc-gen-grpc-swift` plugin.
168+
/// Construct the command to invoke `protoc` with the `protoc-gen-grpc-swift-2` plugin.
169169
/// - Parameters:
170170
/// - inputFile: The input `.proto` file.
171171
/// - config: The config for this operation.
172172
/// - baseDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
173173
/// - protoDirectoryPaths: The paths passed to `protoc` in which to look for imported proto files.
174174
/// - protocPath: The path to `protoc`
175-
/// - protocGenGRPCSwiftPath: The path to `protoc-gen-grpc-swift`.
175+
/// - protocGenGRPCSwiftPath: The path to `protoc-gen-grpc-swift-2`.
176176
/// - configFilePath: The path to the config file in use.
177-
/// - Returns: The command to invoke `protoc` with the `protoc-gen-grpc-swift` plugin.
177+
/// - Returns: The command to invoke `protoc` with the `protoc-gen-grpc-swift-2` plugin.
178178
func protocGenGRPCSwiftCommand(
179179
inputFile: URL,
180180
config: GenerationConfig,
@@ -222,7 +222,7 @@ func protocGenGRPCSwiftCommand(
222222
/// - baseDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
223223
/// - protoDirectoryPaths: The paths passed to `protoc` in which to look for imported proto files.
224224
/// - protocPath: The path to `protoc`
225-
/// - protocGenSwiftPath: The path to `protoc-gen-grpc-swift`.
225+
/// - protocGenSwiftPath: The path to `protoc-gen-grpc-swift-2`.
226226
/// - configFilePath: The path to the config file in use.
227227
/// - Returns: The command to invoke `protoc` with the `protoc-gen-swift` plugin.
228228
func protocGenSwiftCommand(
@@ -266,7 +266,7 @@ func protocGenSwiftCommand(
266266
}
267267

268268
/// Derive the expected output file path to match the behavior of the `protoc-gen-swift`
269-
/// and `protoc-gen-grpc-swift` `protoc` plugins using the `PathToUnderscores` naming scheme.
269+
/// and `protoc-gen-grpc-swift-2` `protoc` plugins using the `PathToUnderscores` naming scheme.
270270
///
271271
/// This means the generated file for an input proto file called "foo/bar/baz.proto" will
272272
/// have the name "foo\_bar\_baz.proto".

Plugins/GRPCProtobufGeneratorCommand/Plugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct GRPCProtobufGeneratorCommandPlugin {
9999

100100
let config = commandConfig.common
101101
let protocPath = try deriveProtocPath(using: config, tool: tool)
102-
let protocGenGRPCSwiftPath = try tool("protoc-gen-grpc-swift").url
102+
let protocGenGRPCSwiftPath = try tool("protoc-gen-grpc-swift-2").url
103103
let protocGenSwiftPath = try tool("protoc-gen-swift").url
104104

105105
let outputDirectory = URL(fileURLWithPath: config.outputPath)
@@ -111,7 +111,7 @@ struct GRPCProtobufGeneratorCommandPlugin {
111111

112112
let inputFileURLs = inputFiles.map { URL(fileURLWithPath: $0) }
113113

114-
// MARK: protoc-gen-grpc-swift
114+
// MARK: protoc-gen-grpc-swift-2
115115
if config.clients || config.servers {
116116
let arguments = constructProtocGenGRPCSwiftArguments(
117117
config: config,

Plugins/PluginsShared/PluginUtils.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ func constructProtocGenSwiftArguments(
7373
return protocArgs
7474
}
7575

76-
/// Construct the arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift` `protoc` plugin.
76+
/// Construct the arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift-2` `protoc` plugin.
7777
/// - Parameters:
7878
/// - config: The config for this operation.
7979
/// - fileNaming: The file naming scheme to be used.
8080
/// - inputFiles: The input `.proto` files.
8181
/// - protoDirectoryPaths: The directories in which `protoc` will look for imports.
82-
/// - protocGenGRPCSwiftPath: The path to the `protoc-gen-grpc-swift` `protoc` plugin.
82+
/// - protocGenGRPCSwiftPath: The path to the `protoc-gen-grpc-swift-2` `protoc` plugin.
8383
/// - outputDirectory: The directory in which generated source files are created.
84-
/// - Returns: The constructed arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift` `protoc` plugin.
84+
/// - Returns: The constructed arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift-2` `protoc` plugin.
8585
func constructProtocGenGRPCSwiftArguments(
8686
config: GenerationConfig,
8787
fileNaming: GenerationConfig.FileNaming?,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ for [gRPC Swift][gh-grpc-swift-protobuf].
1414

1515
[gh-swift-protobuf]: https://github.com/apple/swift-protobuf
1616
[gh-grpc-swift-protobuf]: https://github.com/grpc/grpc-swift-protobuf
17-
[spi-grpc-swift]: https://swiftpackageindex.com/grpc/grpc-swift/documentation
17+
[spi-grpc-swift]: https://swiftpackageindex.com/grpc/grpc-swift-2/documentation
1818
[spi-grpc-swift-protobuf]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation

Sources/GRPCProtobuf/Coding.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +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, *)
21+
@available(gRPCSwiftProtobuf 2.0, *)
2222
public struct ProtobufSerializer<Message: SwiftProtobuf.Message>: GRPCCore.MessageSerializer {
2323
public init() {}
2424

@@ -42,7 +42,7 @@ public struct ProtobufSerializer<Message: SwiftProtobuf.Message>: GRPCCore.Messa
4242
}
4343

4444
/// Deserializes a sequence of bytes into a Protobuf message.
45-
@available(gRPCSwiftProtobuf 1.0, *)
45+
@available(gRPCSwiftProtobuf 2.0, *)
4646
public struct ProtobufDeserializer<Message: SwiftProtobuf.Message>: GRPCCore.MessageDeserializer {
4747
public init() {}
4848

Sources/GRPCProtobuf/ContiguousBytesAdapter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +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, *)
27+
@available(gRPCSwiftProtobuf 2.0, *)
2828
struct ContiguousBytesAdapter<
2929
Bytes: GRPCContiguousBytes
3030
>: GRPCContiguousBytes, SwiftProtobufContiguousBytes {

Sources/GRPCProtobuf/Documentation.docc/Articles/API-stability-of-generated-code.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The API of the generated code depends on three factors:
99

1010
- The contents of the source `.proto` file.
1111
- The options you use when generating the code.
12-
- The code generator (the `protoc-gen-grpc-swift` plugin for `protoc`).
12+
- The code generator (the `protoc-gen-grpc-swift-2` plugin for `protoc`).
1313

1414
While this document applies specifically to the gRPC code generated and *not*
1515
code for messages used as inputs and outputs of each method, the concepts still
@@ -73,6 +73,6 @@ option.
7373

7474
As gRPC Swift is developed the generated code may need to rely on newer
7575
functionality from its runtime counterparts (`GRPCCore` and `GRPCProtobuf`).
76-
This means that you should use the versions of `protoc-gen-grpc-swift` and
76+
This means that you should use the versions of `protoc-gen-grpc-swift-2` and
7777
`protoc-gen-swift` resolved with your package rather than getting them from an
7878
out-of-band (such as `homebrew`).

Sources/GRPCProtobuf/Documentation.docc/Articles/Generating-stubs.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The options do not need to be specified and each have default values.
8787

8888
‡ If you don't provide any import paths then the path to the configuration file will be used on a per-source-file basis.
8989

90-
Many of these options map to `protoc-gen-grpc-swift` and `protoc-gen-swift` options.
90+
Many of these options map to `protoc-gen-grpc-swift-2` and `protoc-gen-swift` options.
9191

9292
If you require greater flexibility you may specify more than one configuration file.
9393
Configuration files apply to all `.proto` files equal to or below it in the file hierarchy. A configuration file
@@ -96,26 +96,26 @@ lower in the file hierarchy supersedes one above it.
9696
### Using protoc
9797

9898
The [`grpc-swift-protobuf`](https://github.com/grpc/grpc-swift-protobuf) package provides
99-
`protoc-gen-grpc-swift`, a program which is a plugin for the Protocol Buffers compiler, `protoc`.
99+
`protoc-gen-grpc-swift-2`, a program which is a plugin for the Protocol Buffers compiler, `protoc`.
100100
To generate gRPC stubs for your `.proto` files directly you must run the `protoc` command with
101101
the `--grpc-swift_out=<DIRECTORY>` option:
102102

103103
```console
104104
protoc --grpc-swift_out=. my-service.proto
105105
```
106106

107-
> `protoc-gen-grpc-swift` only generates gRPC stubs, it doesn't generate messages. You must use
107+
> `protoc-gen-grpc-swift-2` only generates gRPC stubs, it doesn't generate messages. You must use
108108
> `protoc-gen-swift` to generate messages in addition to gRPC Stubs.
109109
110-
The presence of `--grpc-swift_out` tells `protoc` to use the `protoc-gen-grpc-swift` plugin. By
110+
The presence of `--grpc-swift_out` tells `protoc` to use the `protoc-gen-grpc-swift-2` plugin. By
111111
default it'll look for the plugin in your `PATH`. You can also specify the path to the plugin
112112
explicitly:
113113

114114
```console
115-
protoc --plugin=/path/to/protoc-gen-grpc-swift --grpc-swift_out=. my-service.proto
115+
protoc --plugin=/path/to/protoc-gen-grpc-swift-2 --grpc-swift_out=. my-service.proto
116116
```
117117

118-
You can also specify various option the `protoc-gen-grpc-swift` via `protoc` using
118+
You can also specify various option the `protoc-gen-grpc-swift-2` via `protoc` using
119119
the `--grpc-swift_opt` argument:
120120

121121
```console
@@ -164,14 +164,14 @@ times, where each value is a space delimited pair of platform and version, e.g.
164164

165165
#### Building the protoc plugin
166166

167-
> The version of `protoc-gen-grpc-swift` you use mustn't be newer than the version of
167+
> The version of `protoc-gen-grpc-swift-2` you use mustn't be newer than the version of
168168
> the `grpc-swift-protobuf` you're using.
169169
170-
If your package depends on `grpc-swift-protobuf` then you can get a copy of `protoc-gen-grpc-swift`
170+
If your package depends on `grpc-swift-protobuf` then you can get a copy of `protoc-gen-grpc-swift-2`
171171
by building it directly:
172172

173173
```console
174-
swift build --product protoc-gen-grpc-swift
174+
swift build --product protoc-gen-grpc-swift-2
175175
```
176176

177177
This command will build the plugin into `.build/debug` directory. You can get the full path using

0 commit comments

Comments
 (0)