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
6 changes: 3 additions & 3 deletions IntegrationTests/PluginTests/Resources/Sources/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ let package = Package(
dependencies: [
// Dependency on grpc-swift-protobuf to be added by setup-plugin-tests.sh script
.package(
url: "https://github.com/grpc/grpc-swift.git",
url: "https://github.com/grpc/grpc-swift-2.git",
from: "2.0.0"
)
],
targets: [
.executableTarget(
name: "grpc-adopter",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCCore", package: "grpc-swift-2"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift-2"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
],
plugins: [
Expand Down
38 changes: 19 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let products: [Product] = [
targets: ["GRPCProtobuf"]
),
.executable(
name: "protoc-gen-grpc-swift",
targets: ["protoc-gen-grpc-swift"]
name: "protoc-gen-grpc-swift-2",
targets: ["protoc-gen-grpc-swift-2"]
),
.plugin(
name: "GRPCProtobufGenerator",
Expand All @@ -38,8 +38,8 @@ let products: [Product] = [

let dependencies: [Package.Dependency] = [
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "2.2.1"
url: "https://github.com/grpc/grpc-swift-2.git",
from: "2.0.0"
),
.package(
url: "https://github.com/apple/swift-protobuf.git",
Expand All @@ -49,12 +49,12 @@ let dependencies: [Package.Dependency] = [

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

// This adds some build settings which allow us to map "@available(gRPCSwiftProtobuf 1.x, *)" to
// This adds some build settings which allow us to map "@available(gRPCSwiftProtobuf 2.x, *)" to
// the appropriate OS platforms.
let nextMinorVersion = 3
let nextMinorVersion = 1
let availabilitySettings: [SwiftSetting] = (0 ... nextMinorVersion).map { minor in
let name = "gRPCSwiftProtobuf"
let version = "1.\(minor)"
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)
Expand All @@ -71,12 +71,12 @@ let defaultSwiftSettings: [SwiftSetting] =
// -------------------------------------------------------------------------------------------------

var targets: [Target] = [
// protoc plugin for grpc-swift
// protoc plugin for grpc-swift-2
.executableTarget(
name: "protoc-gen-grpc-swift",
name: "protoc-gen-grpc-swift-2",
dependencies: [
.target(name: "GRPCProtobufCodeGen"),
.product(name: "GRPCCodeGen", package: "grpc-swift"),
.product(name: "GRPCCodeGen", package: "grpc-swift-2"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
],
Expand All @@ -87,7 +87,7 @@ var targets: [Target] = [
.target(
name: "GRPCProtobuf",
dependencies: [
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCCore", package: "grpc-swift-2"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
],
swiftSettings: defaultSwiftSettings
Expand All @@ -96,18 +96,18 @@ var targets: [Target] = [
name: "GRPCProtobufTests",
dependencies: [
.target(name: "GRPCProtobuf"),
.product(name: "GRPCCore", package: "grpc-swift"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
.product(name: "GRPCCore", package: "grpc-swift-2"),
.product(name: "GRPCInProcessTransport", package: "grpc-swift-2"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
],
swiftSettings: defaultSwiftSettings
),

// Code generator library for protoc-gen-grpc-swift
// Code generator library for protoc-gen-grpc-swift-2
.target(
name: "GRPCProtobufCodeGen",
dependencies: [
.product(name: "GRPCCodeGen", package: "grpc-swift"),
.product(name: "GRPCCodeGen", package: "grpc-swift-2"),
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
],
swiftSettings: defaultSwiftSettings
Expand All @@ -116,7 +116,7 @@ var targets: [Target] = [
name: "GRPCProtobufCodeGenTests",
dependencies: [
.target(name: "GRPCProtobufCodeGen"),
.product(name: "GRPCCodeGen", package: "grpc-swift"),
.product(name: "GRPCCodeGen", package: "grpc-swift-2"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
],
Expand All @@ -131,7 +131,7 @@ var targets: [Target] = [
name: "GRPCProtobufGenerator",
capability: .buildTool(),
dependencies: [
.target(name: "protoc-gen-grpc-swift"),
.target(name: "protoc-gen-grpc-swift-2"),
.product(name: "protoc-gen-swift", package: "swift-protobuf"),
]
),
Expand All @@ -152,7 +152,7 @@ var targets: [Target] = [
]
),
dependencies: [
.target(name: "protoc-gen-grpc-swift"),
.target(name: "protoc-gen-grpc-swift-2"),
.product(name: "protoc-gen-swift", package: "swift-protobuf"),
],
path: "Plugins/GRPCProtobufGeneratorCommand"
Expand Down Expand Up @@ -196,7 +196,7 @@ if Context.buildCGRPCProtobuf {
)

for target in targets {
if target.name == "protoc-gen-grpc-swift" {
if target.name == "protoc-gen-grpc-swift-2" {
target.dependencies.append(.target(name: "CGRPCProtobuf"))
}
}
Expand Down
12 changes: 6 additions & 6 deletions Plugins/GRPCProtobufGenerator/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct GRPCProtobufGenerator {
) throws -> [Command] {
let configs = try readConfigFiles(configFiles, pluginWorkDirectory: pluginWorkDirectory)

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

var commands: [Command] = []
Expand Down Expand Up @@ -165,16 +165,16 @@ extension [URL: GenerationConfig] {
}
}

/// Construct the command to invoke `protoc` with the `protoc-gen-grpc-swift` plugin.
/// Construct the command to invoke `protoc` with the `protoc-gen-grpc-swift-2` plugin.
/// - Parameters:
/// - inputFile: The input `.proto` file.
/// - config: The config for this operation.
/// - baseDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
/// - protoDirectoryPaths: The paths passed to `protoc` in which to look for imported proto files.
/// - protocPath: The path to `protoc`
/// - protocGenGRPCSwiftPath: The path to `protoc-gen-grpc-swift`.
/// - protocGenGRPCSwiftPath: The path to `protoc-gen-grpc-swift-2`.
/// - configFilePath: The path to the config file in use.
/// - Returns: The command to invoke `protoc` with the `protoc-gen-grpc-swift` plugin.
/// - Returns: The command to invoke `protoc` with the `protoc-gen-grpc-swift-2` plugin.
func protocGenGRPCSwiftCommand(
inputFile: URL,
config: GenerationConfig,
Expand Down Expand Up @@ -222,7 +222,7 @@ func protocGenGRPCSwiftCommand(
/// - baseDirectoryPath: The root path to the source `.proto` files used as the reference for relative path naming schemes.
/// - protoDirectoryPaths: The paths passed to `protoc` in which to look for imported proto files.
/// - protocPath: The path to `protoc`
/// - protocGenSwiftPath: The path to `protoc-gen-grpc-swift`.
/// - protocGenSwiftPath: The path to `protoc-gen-grpc-swift-2`.
/// - configFilePath: The path to the config file in use.
/// - Returns: The command to invoke `protoc` with the `protoc-gen-swift` plugin.
func protocGenSwiftCommand(
Expand Down Expand Up @@ -266,7 +266,7 @@ func protocGenSwiftCommand(
}

/// Derive the expected output file path to match the behavior of the `protoc-gen-swift`
/// and `protoc-gen-grpc-swift` `protoc` plugins using the `PathToUnderscores` naming scheme.
/// and `protoc-gen-grpc-swift-2` `protoc` plugins using the `PathToUnderscores` naming scheme.
///
/// This means the generated file for an input proto file called "foo/bar/baz.proto" will
/// have the name "foo\_bar\_baz.proto".
Expand Down
4 changes: 2 additions & 2 deletions Plugins/GRPCProtobufGeneratorCommand/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct GRPCProtobufGeneratorCommandPlugin {

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

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

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

// MARK: protoc-gen-grpc-swift
// MARK: protoc-gen-grpc-swift-2
if config.clients || config.servers {
let arguments = constructProtocGenGRPCSwiftArguments(
config: config,
Expand Down
6 changes: 3 additions & 3 deletions Plugins/PluginsShared/PluginUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func constructProtocGenSwiftArguments(
return protocArgs
}

/// Construct the arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift` `protoc` plugin.
/// Construct the arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift-2` `protoc` plugin.
/// - Parameters:
/// - config: The config for this operation.
/// - fileNaming: The file naming scheme to be used.
/// - inputFiles: The input `.proto` files.
/// - protoDirectoryPaths: The directories in which `protoc` will look for imports.
/// - protocGenGRPCSwiftPath: The path to the `protoc-gen-grpc-swift` `protoc` plugin.
/// - protocGenGRPCSwiftPath: The path to the `protoc-gen-grpc-swift-2` `protoc` plugin.
/// - outputDirectory: The directory in which generated source files are created.
/// - Returns: The constructed arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift` `protoc` plugin.
/// - Returns: The constructed arguments to be passed to `protoc` when invoking the `protoc-gen-grpc-swift-2` `protoc` plugin.
func constructProtocGenGRPCSwiftArguments(
config: GenerationConfig,
fileNaming: GenerationConfig.FileNaming?,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ for [gRPC Swift][gh-grpc-swift-protobuf].

[gh-swift-protobuf]: https://github.com/apple/swift-protobuf
[gh-grpc-swift-protobuf]: https://github.com/grpc/grpc-swift-protobuf
[spi-grpc-swift]: https://swiftpackageindex.com/grpc/grpc-swift/documentation
[spi-grpc-swift]: https://swiftpackageindex.com/grpc/grpc-swift-2/documentation
Copy link
Collaborator

Choose a reason for hiding this comment

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

This currently 404's - is that expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it takes a little while for SPI to pick up new packages. I've just done a manual submission now so it should become live soon(ish).

[spi-grpc-swift-protobuf]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation
4 changes: 2 additions & 2 deletions Sources/GRPCProtobuf/Coding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public import GRPCCore
public import SwiftProtobuf

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPCProtobuf/ContiguousBytesAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public import SwiftProtobuf // internal but @usableFromInline
/// it'd require a dependency on Protobuf in the core package), and `GRPCContiguousBytes` can't
/// refine `SwiftProtobufContiguousBytes` for the same reason.
@usableFromInline
@available(gRPCSwiftProtobuf 1.0, *)
@available(gRPCSwiftProtobuf 2.0, *)
struct ContiguousBytesAdapter<
Bytes: GRPCContiguousBytes
>: GRPCContiguousBytes, SwiftProtobufContiguousBytes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The API of the generated code depends on three factors:

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

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

As gRPC Swift is developed the generated code may need to rely on newer
functionality from its runtime counterparts (`GRPCCore` and `GRPCProtobuf`).
This means that you should use the versions of `protoc-gen-grpc-swift` and
This means that you should use the versions of `protoc-gen-grpc-swift-2` and
`protoc-gen-swift` resolved with your package rather than getting them from an
out-of-band (such as `homebrew`).
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The options do not need to be specified and each have default values.

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

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

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

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

```console
protoc --grpc-swift_out=. my-service.proto
```

> `protoc-gen-grpc-swift` only generates gRPC stubs, it doesn't generate messages. You must use
> `protoc-gen-grpc-swift-2` only generates gRPC stubs, it doesn't generate messages. You must use
> `protoc-gen-swift` to generate messages in addition to gRPC Stubs.

The presence of `--grpc-swift_out` tells `protoc` to use the `protoc-gen-grpc-swift` plugin. By
The presence of `--grpc-swift_out` tells `protoc` to use the `protoc-gen-grpc-swift-2` plugin. By
default it'll look for the plugin in your `PATH`. You can also specify the path to the plugin
explicitly:

```console
protoc --plugin=/path/to/protoc-gen-grpc-swift --grpc-swift_out=. my-service.proto
protoc --plugin=/path/to/protoc-gen-grpc-swift-2 --grpc-swift_out=. my-service.proto
```

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

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

#### Building the protoc plugin

> The version of `protoc-gen-grpc-swift` you use mustn't be newer than the version of
> The version of `protoc-gen-grpc-swift-2` you use mustn't be newer than the version of
> the `grpc-swift-protobuf` you're using.

If your package depends on `grpc-swift-protobuf` then you can get a copy of `protoc-gen-grpc-swift`
If your package depends on `grpc-swift-protobuf` then you can get a copy of `protoc-gen-grpc-swift-2`
by building it directly:

```console
swift build --product protoc-gen-grpc-swift
swift build --product protoc-gen-grpc-swift-2
```

This command will build the plugin into `.build/debug` directory. You can get the full path using
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Understanding the generated code

Understand what code is generated by `protoc-gen-grpc-swift` from a `.proto`
Understand what code is generated by `protoc-gen-grpc-swift-2` from a `.proto`
file and how to use it.

## Overview

The gRPC Swift Protobuf package provides a plugin to the Protocol Buffers
Compiler (`protoc`) called `protoc-gen-grpc-swift`. The plugin is responsible
Compiler (`protoc`) called `protoc-gen-grpc-swift-2`. The plugin is responsible
for generating the gRPC specific code for services defined in a `.proto` file.

### Package namespace
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPCProtobuf/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A package integrating Swift Protobuf with gRPC Swift.
This package provides three products:
- ``GRPCProtobuf``, a module providing runtime serialization and deserialization components for
[SwiftProtobuf](https://github.com/apple/swift-protobuf).
- `protoc-gen-grpc-swift`, an executable which is a plugin for `protoc`, the Protocol Buffers
- `protoc-gen-grpc-swift-2`, an executable which is a plugin for `protoc`, the Protocol Buffers
compiler. An article describing how to generate gRPC Swift stubs using it is available with the
`grpc-swift` documentation on the [Swift Package
Index](https://swiftpackageindex.com/grpc/grpc-swift/documentation).
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPCProtobuf/Errors/ErrorDetails+AnyPacking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension Google_Protobuf_Any {
}
}

@available(gRPCSwiftProtobuf 1.0, *)
@available(gRPCSwiftProtobuf 2.0, *)
extension ErrorDetails {
// Note: this type isn't packable into an 'Any' protobuf so doesn't conform
// to 'GoogleProtobufAnyPackable' despite holding types which are packable.
Expand Down
Loading
Loading