-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -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 notice that the `swift` commands are all prefixed with `PROTOC_PATH=$(which protoc)`, | ||
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). | ||
|
||
@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") | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
.../Documentation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step09-plugin.swift
This file contains hidden or 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,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") | ||
] | ||
) | ||
] | ||
) |
7 changes: 7 additions & 0 deletions
7
...entation.docc/Tutorials/Route-Guide/Resources/route-guide-sec01-step10-plugin-config.json
This file contains hidden or 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,7 @@ | ||
{ | ||
"generate": { | ||
"clients": true, | ||
"servers": true, | ||
"messages": true | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.