-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation: To make code generation more convenient for adopters. Modifications: * New build plugin to generate gRPC services and protobuf messages * New command plugin e.g. `swift package generate-grpc-code-from-protos Sources/Protos/HelloWorld.proto` * Integration tests (incomplete) This PR also includes a change to `protoc-gen-grpc-swift` itself: * Generate an empty file if no gRPC services are found in the protobuf definition file. This is required by the build plugin which needs deterministic outputs and matches the behavior of `protoc-gen-swift`. Result: * Users will be able to make use of the build and command plugins. * `protoc-gen-grpc-swift` will Generate an empty file if no gRPC services are found in the protobuf definition file.
- Loading branch information
Showing
43 changed files
with
1,887 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.0)","swift_version":"nightly-6.0","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
51 changes: 51 additions & 0 deletions
51
IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// swift-tools-version: 6.0 | ||
/* | ||
* Copyright 2024, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "grpc-adopter", | ||
platforms: [ | ||
.macOS(.v15), | ||
.iOS(.v18), | ||
.tvOS(.v18), | ||
.watchOS(.v11), | ||
.visionOS(.v2), | ||
], | ||
dependencies: [ | ||
.package( | ||
path: "../../../../grpc-swift-protobuf" | ||
), | ||
.package( | ||
url: "https://github.com/grpc/grpc-swift.git", | ||
exact: "2.0.0-beta.2" | ||
), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "grpc-adopter", | ||
dependencies: [ | ||
.product(name: "GRPCCore", package: "grpc-swift"), | ||
.product(name: "GRPCInProcessTransport", package: "grpc-swift"), | ||
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), | ||
], | ||
plugins: [ | ||
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf") | ||
] | ||
) | ||
] | ||
) |
37 changes: 37 additions & 0 deletions
37
IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2015, gRPC Authors All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.helloworld"; | ||
option java_outer_classname = "HelloWorldProto"; | ||
option objc_class_prefix = "HLW"; | ||
|
||
package helloworld; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings | ||
message HelloReply { | ||
string message = 1; | ||
} |
51 changes: 51 additions & 0 deletions
51
IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2024, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import GRPCCore | ||
import GRPCInProcessTransport | ||
import GRPCProtobuf | ||
|
||
@main | ||
struct PluginAdopter { | ||
static func main() async throws { | ||
let inProcess = InProcessTransport() | ||
try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in | ||
try await withGRPCClient(transport: inProcess.client) { client in | ||
try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) | ||
} | ||
} | ||
} | ||
|
||
static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { | ||
do { | ||
let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) | ||
print("Reply: \(reply.message)") | ||
} catch { | ||
print("Error: \(error)") | ||
} | ||
} | ||
} | ||
|
||
struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { | ||
func sayHello( | ||
request: Helloworld_HelloRequest, | ||
context: ServerContext | ||
) async throws -> Helloworld_HelloReply { | ||
return .with { reply in | ||
reply.message = "Hello, world!" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"visibility": "internal" | ||
} |
8 changes: 8 additions & 0 deletions
8
IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
51 changes: 51 additions & 0 deletions
51
IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// swift-tools-version: 6.0 | ||
/* | ||
* Copyright 2024, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "grpc-adopter", | ||
platforms: [ | ||
.macOS(.v15), | ||
.iOS(.v18), | ||
.tvOS(.v18), | ||
.watchOS(.v11), | ||
.visionOS(.v2), | ||
], | ||
dependencies: [ | ||
.package( | ||
path: "../../../../grpc-swift-protobuf" | ||
), | ||
.package( | ||
url: "https://github.com/grpc/grpc-swift.git", | ||
exact: "2.0.0-beta.2" | ||
), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "grpc-adopter", | ||
dependencies: [ | ||
.product(name: "GRPCCore", package: "grpc-swift"), | ||
.product(name: "GRPCInProcessTransport", package: "grpc-swift"), | ||
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), | ||
], | ||
plugins: [ | ||
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf") | ||
] | ||
) | ||
] | ||
) |
37 changes: 37 additions & 0 deletions
37
IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2015, gRPC Authors All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.helloworld"; | ||
option java_outer_classname = "HelloWorldProto"; | ||
option objc_class_prefix = "HLW"; | ||
|
||
package helloworld; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings | ||
message HelloReply { | ||
string message = 1; | ||
} |
3 changes: 3 additions & 0 deletions
3
IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"visibility": "internal" | ||
} |
51 changes: 51 additions & 0 deletions
51
IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2024, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import GRPCCore | ||
import GRPCInProcessTransport | ||
import GRPCProtobuf | ||
|
||
@main | ||
struct PluginAdopter { | ||
static func main() async throws { | ||
let inProcess = InProcessTransport() | ||
try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in | ||
try await withGRPCClient(transport: inProcess.client) { client in | ||
try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) | ||
} | ||
} | ||
} | ||
|
||
static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { | ||
do { | ||
let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) | ||
print("Reply: \(reply.message)") | ||
} catch { | ||
print("Error: \(error)") | ||
} | ||
} | ||
} | ||
|
||
struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { | ||
func sayHello( | ||
request: Helloworld_HelloRequest, | ||
context: ServerContext | ||
) async throws -> Helloworld_HelloReply { | ||
return .with { reply in | ||
reply.message = "Hello, world!" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
51 changes: 51 additions & 0 deletions
51
IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// swift-tools-version: 6.0 | ||
/* | ||
* Copyright 2024, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "grpc-adopter", | ||
platforms: [ | ||
.macOS(.v15), | ||
.iOS(.v18), | ||
.tvOS(.v18), | ||
.watchOS(.v11), | ||
.visionOS(.v2), | ||
], | ||
dependencies: [ | ||
.package( | ||
path: "../../../../grpc-swift-protobuf" | ||
), | ||
.package( | ||
url: "https://github.com/grpc/grpc-swift.git", | ||
exact: "2.0.0-beta.2" | ||
), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "grpc-adopter", | ||
dependencies: [ | ||
.product(name: "GRPCCore", package: "grpc-swift"), | ||
.product(name: "GRPCInProcessTransport", package: "grpc-swift"), | ||
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), | ||
], | ||
plugins: [ | ||
.plugin(name: "GRPCGeneratorPlugin", package: "grpc-swift-protobuf") | ||
] | ||
) | ||
] | ||
) |
Oops, something went wrong.