Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

If this change is intended for tonic `v0.14.x` please make this PR against that branch
otherwise, it may not get included in a relase for a long time.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/hyperium/tonic/blob/master/CONTRIBUTING.md
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ jobs:
- uses: hecrj/setup-rust-action@v2
with:
components: clippy
- uses: taiki-e/install-action@protoc
- uses: taiki-e/install-action@v2
with:
tool: protoc@3.32.0
- name: Restore protoc plugin from cache
id: cache-plugin
uses: actions/cache@v4
Expand Down Expand Up @@ -115,7 +117,9 @@ jobs:
toolchain: nightly-2025-03-27
- uses: taiki-e/install-action@cargo-hack
- uses: taiki-e/install-action@cargo-udeps
- uses: taiki-e/install-action@protoc
- uses: taiki-e/install-action@v2
with:
tool: protoc@3.32.0
- name: Restore protoc plugin from cache
id: cache-plugin
uses: actions/cache@v4
Expand Down Expand Up @@ -147,7 +151,9 @@ jobs:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
- uses: taiki-e/install-action@cargo-hack
- uses: taiki-e/install-action@protoc
- uses: taiki-e/install-action@v2
with:
tool: protoc@3.32.0
- name: Restore protoc plugin from cache
id: cache-plugin
uses: actions/cache@v4
Expand Down Expand Up @@ -198,7 +204,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
- uses: taiki-e/install-action@protoc
- uses: taiki-e/install-action@v2
with:
tool: protoc@3.32.0
- name: Restore protoc plugin from cache
id: cache-plugin
uses: actions/cache@v4
Expand Down Expand Up @@ -235,7 +243,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
- uses: taiki-e/install-action@protoc
- uses: taiki-e/install-action@v2
with:
tool: protoc@3.32.0
- name: Restore protoc plugin from cache
id: cache-plugin
uses: actions/cache@v4
Expand Down Expand Up @@ -268,11 +278,11 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2025-05-04
toolchain: nightly-2025-08-06
- name: Install cargo-check-external-types
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-check-external-types@0.2.0
tool: cargo-check-external-types@0.3.0
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
- run: cargo hack --no-private check-external-types --all-features
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
![](https://github.com/hyperium/tonic/raw/master/.github/assets/tonic-banner.svg?sanitize=true)


A rust implementation of [gRPC], a high performance, open source, general
RPC framework that puts mobile and HTTP/2 first.

> **Note**: tonic's [master](https://github.com/hyperium/tonic) branch is
> currently preparing breaking changes. For the most recently *released* code,
> look to the [0.14.x branch](https://github.com/hyperium/tonic/tree/v0.14.x).

[`tonic`] is a gRPC over HTTP/2 implementation focused on high performance, interoperability, and flexibility. This library was created to have first class support of async/await and to act as a core building block for production systems written in Rust.

[![Crates.io](https://img.shields.io/crates/v/tonic)](https://crates.io/crates/tonic)
Expand Down
13 changes: 13 additions & 0 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ fn main() {
false,
);

// grpc
codegen(
&PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("grpc"),
&["proto/echo/echo.proto"],
&["proto"],
&PathBuf::from("src/generated"),
&PathBuf::from("src/generated/echo_fds.rs"),
true,
true,
);
println!("Codgen completed: {}ms", start.elapsed().as_millis());
}

Expand Down
3 changes: 1 addition & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ tracing = ["dep:tracing", "dep:tracing-subscriber"]
uds = ["dep:tokio-stream", "tokio-stream?/net", "dep:tower", "dep:hyper", "dep:hyper-util"]
streaming = ["dep:tokio-stream", "dep:h2"]
mock = ["dep:tokio-stream", "dep:tower", "dep:hyper-util"]
tower = ["dep:tower", "dep:http"]
json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"]
compression = ["tonic/gzip"]
tls = ["tonic/tls-ring"]
Expand All @@ -273,7 +272,7 @@ types = ["dep:tonic-types"]
h2c = ["dep:hyper", "dep:tower", "dep:http", "dep:hyper-util"]
cancellation = ["dep:tokio-util"]

full = ["gcp", "routeguide", "reflection", "autoreload", "health", "grpc-web", "tracing", "uds", "streaming", "mock", "tower", "json-codec", "compression", "tls", "tls-rustls", "tls-client-auth", "types", "cancellation", "h2c"]
full = ["gcp", "routeguide", "reflection", "autoreload", "health", "grpc-web", "tracing", "uds", "streaming", "mock", "json-codec", "compression", "tls", "tls-rustls", "tls-client-auth", "types", "cancellation", "h2c"]
default = ["full"]

[dependencies]
Expand Down
9 changes: 5 additions & 4 deletions examples/helloworld-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ path = "src/client.rs"
[dependencies]
tonic = "*"
prost = "0.14"
tonic-prost = "*"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

[build-dependencies]
tonic-build = "*"
tonic-prost-build = "*"
```

We include `tonic-build` as a useful way to incorporate the generation of our client and server gRPC code into the build process of our application. We will setup this build process now:
Expand All @@ -128,7 +129,7 @@ At the root of your project (not /src), create a `build.rs` file and add the fol

```rust
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/helloworld.proto")?;
tonic_prost_build::compile_protos("proto/helloworld.proto")?;
Ok(())
}
```
Expand Down Expand Up @@ -239,7 +240,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

You should now be able to run your HelloWorld gRPC server using the command `cargo run --bin helloworld-server`. This uses the [[bin]] we defined earlier in our `Cargo.toml` to run specifically the server.

If you have a gRPC GUI client such as [Bloom RPC] you should be able to send requests to the server and get back greetings!
If you have a gRPC GUI client such as [Postman] you should be able to send requests to the server and get back greetings!

Or if you use [grpcurl] then you can simply try send requests like this:
```
Expand All @@ -252,7 +253,7 @@ And receiving responses like this:
}
```

[bloom rpc]: https://github.com/uw-labs/bloomrpc
[postman]: https://www.postman.com/
[grpcurl]: https://github.com/fullstorydev/grpcurl

## Writing our Client
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@
"rustfmt"
"rust-analyzer"
])
protobuf
# protobuf
];

hardeningDisable = [ "fortify" ];

shellHook = ''
export PATH="$PWD/protoc-gen-rust-grpc/bazel-bin/src:$PATH"
export PATH="$PWD/protoc-gen-rust-grpc/bazel-bin/src:$HOME/code/install/bin:$PATH"

${config.pre-commit.installationScript}
'';
Expand Down
60 changes: 40 additions & 20 deletions grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,59 @@ authors = ["gRPC Authors"]
license = "MIT"
rust-version = "1.86"

[package.metadata.cargo_check_external_types]
allowed_external_types = [
"tonic::*",
"futures_core::stream::Stream",
"tokio::sync::oneshot::Sender",
]

[features]
default = ["dns", "_runtime-tokio"]
dns = ["dep:hickory-resolver", "_runtime-tokio"]
# The following feature is used to ensure all modules use the runtime
# abstraction instead of using tokio directly.
# Using tower/buffer enables tokio's rt feature even though it's possible to
# create Buffers with a user provided executor.
_runtime-tokio = [
"tokio/rt",
"tokio/net",
"tokio/time",
"dep:socket2",
"dep:tower",
]

[dependencies]
bytes = "1.10.1"
hickory-resolver = { version = "0.25.1", optional = true }
http = "1.1.0"
http-body = "1.0.1"
hyper = { version = "1.6.0", features = ["client", "http2"] }
hyper-util = "0.1.14"
parking_lot = "0.12.4"
pin-project-lite = "0.2.16"
rand = "0.9"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
socket2 = "0.5.10"
tokio = { version = "1.37.0", features = ["sync", "rt", "net", "time", "macros"] }
tokio-stream = "0.1.17"
tonic = { version = "0.14.0", path = "../tonic", default-features = false, features = ["codegen", "transport"] }
tower = "0.5.2"
socket2 = { version = "0.5.10", optional = true }
tokio = { version = "1.37.0", features = ["sync", "macros"] }
tokio-stream = { version = "0.1.17", default-features = false }
tonic = { version = "0.14.0", path = "../tonic", default-features = false, features = [
"codegen",
] }
tower = { version = "0.5.2", features = [
"limit",
"util",
"buffer",
], optional = true }
tower-service = "0.3.3"
url = "2.5.0"

[dev-dependencies]
async-stream = "0.3.6"
tonic = { version = "0.14.0", path = "../tonic", default-features = false, features = ["server", "router"] }
hickory-server = "0.25.2"
prost = "0.14"

[features]
default = ["dns"]
dns = ["dep:hickory-resolver"]

[package.metadata.cargo_check_external_types]
allowed_external_types = [
"tonic::*",
"futures_core::stream::Stream",
"tokio::sync::oneshot::Sender",
]
hickory-server = "0.25.2"
prost = "0.14.0"
tonic = { version = "0.14.0", path = "../tonic", default-features = false, features = [
"server",
"router",
] }
tonic-prost = { version = "0.14.0", path = "../tonic-prost" }
3 changes: 0 additions & 3 deletions grpc/examples/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ struct Handler {}
#[derive(Debug)]
struct MyReqMessage(String);

impl Message for MyReqMessage {}

#[derive(Debug)]
struct MyResMessage(String);
impl Message for MyResMessage {}

#[async_trait]
impl Service for Handler {
Expand Down
3 changes: 0 additions & 3 deletions grpc/examples/multiaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ struct Handler {
#[derive(Debug)]
struct MyReqMessage(String);

impl Message for MyReqMessage {}

#[derive(Debug)]
struct MyResMessage(String);
impl Message for MyResMessage {}

#[async_trait]
impl Service for Handler {
Expand Down
43 changes: 43 additions & 0 deletions grpc/proto/echo/echo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright 2018 gRPC authors.
*
* 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";

package grpc.examples.echo;

// EchoRequest is the request for echo.
message EchoRequest {
string message = 1;
}

// EchoResponse is the response for echo.
message EchoResponse {
string message = 1;
}

// Echo is the echo service.
service Echo {
// UnaryEcho is unary echo.
rpc UnaryEcho(EchoRequest) returns (EchoResponse) {}
// ServerStreamingEcho is server side streaming.
rpc ServerStreamingEcho(EchoRequest) returns (stream EchoResponse) {}
// ClientStreamingEcho is client side streaming.
rpc ClientStreamingEcho(stream EchoRequest) returns (EchoResponse) {}
// BidirectionalStreamingEcho is bidi streaming.
rpc BidirectionalStreamingEcho(stream EchoRequest) returns (stream EchoResponse) {}
}
Loading
Loading