Skip to content

Commit 9639fe9

Browse files
authored
Use the protoc build plugin in examples (#2171)
Motivation: We now have a SwiftPM build plugin to generate code as part of the build process, the examples should make use of it. Modifications: - Remove generated code for examples and update the generate script to stop genearting example code. - Symlink protos from examples to the checked out location in the repo; this avoids some duplication and makes it easier to keep things up-to-date. - Add a basic config to each example. - Update CI to install protoc before building examples. Result: Better examples, less code.
1 parent 12b2ee2 commit 9639fe9

28 files changed

+70
-4810
lines changed

.github/workflows/pull_request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
MATRIX_LINUX_5_9_ENABLED: false
4343
MATRIX_LINUX_5_10_ENABLED: false
4444
MATRIX_LINUX_COMMAND: "./dev/build-examples.sh"
45-
MATRIX_LINUX_SETUP_COMMAND: ""
45+
MATRIX_LINUX_SETUP_COMMAND: "apt update && apt install -y protobuf-compiler && ./dev/build-examples.sh"
4646

4747
examples-matrix:
4848
name: Examples

Examples/echo/Package.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ let package = Package(
2121
name: "echo",
2222
platforms: [.macOS("15.0")],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"),
26-
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.3"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"),
26+
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "main"),
2727
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
2828
],
2929
targets: [
@@ -34,6 +34,9 @@ let package = Package(
3434
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
3535
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
3636
.product(name: "ArgumentParser", package: "swift-argument-parser"),
37+
],
38+
plugins: [
39+
.plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf")
3740
]
3841
)
3942
]

Examples/echo/Sources/Generated/echo.grpc.swift

-994
This file was deleted.

Examples/echo/Sources/Generated/echo.pb.swift

-129
This file was deleted.

Examples/echo/Sources/Protos/echo

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../dev/protos/examples/echo/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"generate": {
3+
"clients": true,
4+
"servers": true,
5+
"messages": true
6+
}
7+
}

Examples/error-details/Package.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ let package = Package(
2121
name: "error-details",
2222
platforms: [.macOS(.v15)],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.3"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.3"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", branch: "main"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", branch: "main"),
2626
],
2727
targets: [
2828
.executableTarget(
@@ -31,6 +31,9 @@ let package = Package(
3131
.product(name: "GRPCCore", package: "grpc-swift"),
3232
.product(name: "GRPCInProcessTransport", package: "grpc-swift"),
3333
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
34+
],
35+
plugins: [
36+
.plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf")
3437
]
3538
)
3639
]

0 commit comments

Comments
 (0)