-
Notifications
You must be signed in to change notification settings - Fork 434
Update tutorials to use the build plugin #2178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,17 +28,28 @@ | |
@Section(title: "Run a gRPC application") { | ||
Let's start by running the existing Greeter application. | ||
|
||
As a prerequisite you must have the Protocol Buffers compiler (`protoc`) installed. You can | ||
find the instructions for doing this in the [gRPC Swift Protobuf | ||
documentation](https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/installing-protoc). | ||
The remainder of this tutorial assumes you installed `protoc` and it's available in | ||
your `$PATH`. | ||
|
||
You may notices that the `swift` commands are all prefixed with `PROTOC_PATH=$(which protoc)`, | ||
gjcairo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
this is to let the build system know where `protoc` is located so that it can generate stubs | ||
for you. You can read more about it in the [gRPC Swift Protobuf | ||
documentation](https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/generating-stubs). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this is a pre-emptive change: I think we should move the generating stubs doc to the protobuf package and then link to it from the core package docs. |
||
|
||
@Steps { | ||
@Step { | ||
In a terminal run `swift run hello-world serve` to start the server. By default it'll start | ||
listening on port 31415. | ||
In a terminal run `PROTOC_PATH=$(which protoc) swift run hello-world serve` to start the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we explain why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's a great point, I'll do that. |
||
server. By default it'll start listening on port 31415. | ||
|
||
@Code(name: "Console.txt", file: "hello-world-sec02-step01.txt") | ||
} | ||
|
||
@Step { | ||
In another terminal run `swift run hello-world greet` to create a client, connect | ||
to the server you started and send it a request and print the response. | ||
In another terminal run `PROTOC_PATH=$(which protoc) swift run hello-world greet` to create | ||
a client, connect to the server you started and send it a request and print the response. | ||
|
||
@Code(name: "Console.txt", file: "hello-world-sec02-step02.txt") | ||
} | ||
|
@@ -75,19 +86,19 @@ | |
} | ||
|
||
@Section(title: "Update and run the application") { | ||
You need to regenerate the stubs as the service definition has changed. To do this run the | ||
following command from the _root of the checked out repository_: | ||
|
||
```console | ||
dev/protos/generate.sh | ||
``` | ||
You need to regenerate the stubs as the service definition has changed. As you're using | ||
the Swift Package Manager Build Plugin for gRPC Swift the gRPC code is automatically | ||
generated if necessary when you build the example. You can learn more about generating stubs in | ||
the <doc:Generating-stubs> article. | ||
|
||
To learn how to generate stubs check out the <doc:Generating-stubs> article. | ||
|
||
Now that the stubs have been updated you need to implement and call the new method in the | ||
human-written parts of your application. | ||
|
||
@Steps { | ||
@Step { | ||
Run `PROTOC_PATH=$(which protoc) swift build` to build the example. This will fail | ||
because the service no longer implements all of the methods declared in the `.proto` file. | ||
Let's fix that! | ||
} | ||
|
||
@Step { | ||
Open `Serve.swift` in the `Subcommands` directory. | ||
|
||
|
@@ -114,13 +125,14 @@ | |
|
||
@Step { | ||
Just like we did before, open a terminal and start the server by | ||
running `swift run hello-world serve` | ||
running `PROTOC_PATH=$(which protoc) swift run hello-world serve` | ||
|
||
@Code(name: "Console.txt", file: "hello-world-sec04-step05.txt") | ||
} | ||
|
||
@Step { | ||
In a separate terminal run `swift run hello-world greet` to call the server. | ||
In a separate terminal run `PROTOC_PATH=$(which protoc) swift run hello-world greet` to | ||
call the server. | ||
|
||
@Code(name: "Console.txt", file: "hello-world-sec04-step06.txt") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// swift-tools-version: 6.0 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "RouteGuide", | ||
platforms: [.macOS(.v15)], | ||
dependencies: [ | ||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "2.0.0-beta.3"), | ||
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "1.0.0-beta.3"), | ||
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "1.0.0-beta.3"), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "RouteGuide", | ||
dependencies: [ | ||
.product(name: "GRPCCore", package: "grpc-swift"), | ||
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"), | ||
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), | ||
], | ||
plugins: [ | ||
.plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") | ||
] | ||
) | ||
] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"generate": { | ||
"clients": true, | ||
"servers": true, | ||
"messages": true | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.