Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hyperium/tonic
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.8.2
Choose a base ref
...
head repository: hyperium/tonic
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.8.3
Choose a head ref

Commits on Sep 28, 2022

  1. Update README.md (#1090)

    I believe that the reference to Rust Analyzer build script setting is incorrect. Please verify before accepting.
    CaliViking authored Sep 28, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3663faf View commit details

Commits on Oct 3, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    darinpope Darin Pope
    Copy the full SHA
    0b03b30 View commit details

Commits on Oct 11, 2022

  1. Create SECURITY.md (#1106)

    * Create SECURITY.md
    
    Fixes #1100
    
    * Update SECURITY.md
    howardjohn authored Oct 11, 2022
    Copy the full SHA
    675b3b2 View commit details

Commits on Oct 15, 2022

  1. Copy the full SHA
    be1fe02 View commit details

Commits on Oct 18, 2022

  1. Copy the full SHA
    64e29c6 View commit details

Commits on Oct 19, 2022

  1. feat: Expose Request#into_parts and Request#from_parts (#1118)

    Signed-off-by: slinkydeveloper <francescoguard@gmail.com>
    slinkydeveloper authored Oct 19, 2022
    Copy the full SHA
    b409ddd View commit details

Commits on Oct 28, 2022

  1. feat(web): Implement tower::Layer for tonic_web::Config (#1119)

    Signed-off-by: slinkydeveloper <francescoguard@gmail.com>
    slinkydeveloper authored Oct 28, 2022
    Copy the full SHA
    40536dc View commit details

Commits on Oct 31, 2022

  1. feat(web): Removed Cors impl and replaced with tower-http's CorsLayer (

    …#1123)
    
    Fix #1122, see the issue for more details.
    
    Signed-off-by: slinkydeveloper <francescoguard@gmail.com>
    slinkydeveloper authored Oct 31, 2022
    Copy the full SHA
    a98d719 View commit details

Commits on Nov 1, 2022

  1. Copy the full SHA
    6667ace View commit details

Commits on Nov 4, 2022

  1. Copy the full SHA
    1f5bc9b View commit details

Commits on Nov 7, 2022

  1. Copy the full SHA
    f82488c View commit details
  2. Copy the full SHA
    7153289 View commit details

Commits on Nov 8, 2022

  1. Copy the full SHA
    c9cadd4 View commit details
  2. Copy the full SHA
    e188521 View commit details

Commits on Nov 9, 2022

  1. Copy the full SHA
    3a54270 View commit details

Commits on Nov 10, 2022

  1. Copy the full SHA
    33e22bb View commit details

Commits on Nov 16, 2022

  1. Copy the full SHA
    933f560 View commit details

Commits on Nov 28, 2022

  1. Copy the full SHA
    b65b52b View commit details
  2. Copy the full SHA
    542c5b3 View commit details
  3. feat(build): Add CodeGenBuilder (#1154)

    This commit adds a new `CodeGenBuilder` that replaces the
    client/server generate fn with a builder stlye that allows
    adding config items in an non-breaking way. This also deprecates
    both of the client/server generate fn in favor of the builder ones.
    LucioFranco authored Nov 28, 2022
    Copy the full SHA
    c4525ba View commit details
  4. Copy the full SHA
    b53b387 View commit details
  5. Copy the full SHA
    dc079c1 View commit details
Showing with 1,257 additions and 1,080 deletions.
  1. +3 −3 .github/workflows/CI.yml
  2. +26 −0 CHANGELOG.md
  3. +1 −0 Cargo.toml
  4. +7 −1 README.md
  5. +9 −0 SECURITY.md
  6. +1 −1 examples/routeguide-tutorial.md
  7. +2 −3 examples/src/grpc-web/server.rs
  8. +1 −1 interop/Cargo.toml
  9. +4 −4 interop/src/bin/client.rs
  10. +17 −0 tests/disable_comments/Cargo.toml
  11. +11 −0 tests/disable_comments/build.rs
  12. +29 −0 tests/disable_comments/proto/test.proto
  13. +3 −0 tests/disable_comments/src/lib.rs
  14. +15 −0 tests/disable_comments/tests/disable_comments.rs
  15. +2 −2 tonic-build/Cargo.toml
  16. +57 −7 tonic-build/src/client.rs
  17. +102 −0 tonic-build/src/code_gen.rs
  18. +12 −1 tonic-build/src/lib.rs
  19. +24 −15 tonic-build/src/manual.rs
  20. +38 −15 tonic-build/src/prost.rs
  21. +56 −6 tonic-build/src/server.rs
  22. +4 −4 tonic-health/Cargo.toml
  23. +5 −1 tonic-health/README.md
  24. +45 −46 tonic-health/src/generated/grpc.health.v1.rs
  25. +1 −1 tonic-health/src/lib.rs
  26. +1 −1 tonic-health/src/server.rs
  27. +1 −0 tonic-health/tests/bootstrap.rs
  28. +5 −6 tonic-reflection/Cargo.toml
  29. +0 −19 tonic-reflection/build.rs
  30. +392 −0 tonic-reflection/src/generated/grpc.reflection.v1alpha.rs
  31. BIN tonic-reflection/src/generated/reflection_v1alpha1.bin
  32. +6 −5 tonic-reflection/src/lib.rs
  33. +31 −0 tonic-reflection/tests/bootstrap.rs
  34. +30 −38 tonic-reflection/tests/server.rs
  35. +2 −2 tonic-types/Cargo.toml
  36. +34 −31 tonic-types/src/generated/google.rpc.rs
  37. +1 −1 tonic-types/src/lib.rs
  38. +3 −1 tonic-web/Cargo.toml
  39. +0 −168 tonic-web/src/config.rs
  40. +0 −402 tonic-web/src/cors.rs
  41. +31 −0 tonic-web/src/layer.rs
  42. +41 −35 tonic-web/src/lib.rs
  43. +108 −215 tonic-web/src/service.rs
  44. +3 −5 tonic-web/tests/integration/tests/grpc.rs
  45. +6 −19 tonic-web/tests/integration/tests/grpc_web.rs
  46. +3 −3 tonic/Cargo.toml
  47. +11 −4 tonic/src/codec/encode.rs
  48. +33 −0 tonic/src/codec/prost.rs
  49. +1 −1 tonic/src/lib.rs
  50. +4 −2 tonic/src/request.rs
  51. +2 −2 tonic/src/transport/channel/mod.rs
  52. +16 −1 tonic/src/transport/server/incoming.rs
  53. +5 −5 tonic/src/transport/server/mod.rs
  54. +12 −3 tonic/src/transport/service/router.rs
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ jobs:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v1
- name: Check fmt
run: cargo fmt -- --check
@@ -66,7 +66,7 @@ jobs:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v1
- uses: actions/checkout@master
- name: Run tests
@@ -93,7 +93,7 @@ jobs:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v1
- name: Run interop tests
run: ./interop/test.sh
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# [v0.8.3](https://github.com/hyperium/tonic/compare/v0.8.2...v0.8.3) (2022-11-28)

Included in this release is also the sub-crate major version bumps:

* `tonic-health` has been bumped to `0.8.0`
* `tonic-reflection` has been bumped to `0.6.0`
* `tonic-web` has been bumped to `0.5.0`


### Bug Fixes

* do not panic while encoding oversized bodies ([#1142](https://github.com/hyperium/tonic/issues/1142)) ([33e22bb](https://github.com/hyperium/tonic/commit/33e22bbc5ef1b74de82394c3ebfea27382419620)), closes [#1141](https://github.com/hyperium/tonic/issues/1141)
* **reflection, health:** Remove transport feature ([#1112](https://github.com/hyperium/tonic/issues/1112)) ([7153289](https://github.com/hyperium/tonic/commit/7153289b51f7770cdd00cefeceddacc4cf36df97))


### Features

* **build:** Add `build_transport` builder option ([#1130](https://github.com/hyperium/tonic/issues/1130)) ([1f5bc9b](https://github.com/hyperium/tonic/commit/1f5bc9b9d55f814d1cb83de6f43239e275122265))
* **build:** Add `CodeGenBuilder` ([#1154](https://github.com/hyperium/tonic/issues/1154)) ([c4525ba](https://github.com/hyperium/tonic/commit/c4525ba6ad21cf9db8d1857931f430cbe924aeb5))
* **build:** Add disable_comments option ([#1127](https://github.com/hyperium/tonic/issues/1127)) ([e188521](https://github.com/hyperium/tonic/commit/e1885211495e63d962bc1d00f9be6eeaab2bb901))
* Expose `Request#into_parts` and `Request#from_parts` ([#1118](https://github.com/hyperium/tonic/issues/1118)) ([b409ddd](https://github.com/hyperium/tonic/commit/b409ddd478959e239aeef3cb8715cd3ace470a8f))
* **transport:** add `from_listener` for `TcpIncoming` ([#1093](https://github.com/hyperium/tonic/issues/1093)) ([0b03b30](https://github.com/hyperium/tonic/commit/0b03b30cccc67d517b05587614405d63d942b1bb))
* **web:** Implement tower::Layer for tonic_web::Config ([#1119](https://github.com/hyperium/tonic/issues/1119)) ([40536dc](https://github.com/hyperium/tonic/commit/40536dc13428f6338610d74f7b45a5f9c87d9335))
* **web:** Removed Cors impl and replaced with tower-http's CorsLayer ([#1123](https://github.com/hyperium/tonic/issues/1123)) ([a98d719](https://github.com/hyperium/tonic/commit/a98d719fb4b0a88127504a1ab3eb472e842c6b71)), closes [#1122](https://github.com/hyperium/tonic/issues/1122)


# [0.8.2](https://github.com/hyperium/tonic/compare/v0.8.1...v0.8.2) (2022-09-28)


1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ members = [
"tonic-web", # Non-published crates
"examples",
"interop", # Tests
"tests/disable_comments",
"tests/included_service",
"tests/same_name",
"tests/service_named_service",
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ contains the tools to build clients and servers from [`protobuf`] definitions.
Examples can be found in [`examples`] and for more complex scenarios [`interop`]
may be a good resource as it shows examples of many of the gRPC features.

If you're using [rust-analyzer] we recommend you set `"rust-analyzer.cargo.runBuildScripts": true` to correctly load
If you're using [rust-analyzer] we recommend you set `"rust-analyzer.cargo.buildScripts.enable": true` to correctly load
the generated code.

For IntelliJ IDEA users, please refer to [this](https://github.com/intellij-rust/intellij-rust/pull/8056) and enable
@@ -77,6 +77,12 @@ Assuming [Homebrew](https://brew.sh/) is already installed. (If not, see instruc
brew install protobuf
```

#### Windows

- Download the latest version of `protoc-xx.y-win64.zip` from [HERE](https://github.com/protocolbuffers/protobuf/releases/latest)
- Extract the file `bin\protoc.exe` and put it somewhere in the `PATH`
- Verify installation by opening a command prompt and enter `protoc --version`

### Tutorials

- The [`helloworld`][helloworld-tutorial] tutorial provides a basic example of using `tonic`, perfect for first time users!
9 changes: 9 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Security Policy

tonic (and related projects in hyperium) uses the same security policy as the [Tokio project][tokio-security].

## Report a security issue

The process for reporting an issue is the same as the [Tokio project][tokio-security]. This includes private reporting via security@tokio.rs.

[tokio-security]: https://github.com/tokio-rs/tokio/security/policy
2 changes: 1 addition & 1 deletion examples/routeguide-tutorial.md
Original file line number Diff line number Diff line change
@@ -825,7 +825,7 @@ fn main() {
}
```

On `cargo run`, this will generate code for the client only, and place the resulting file in
On `cargo run`, this will generate code for the server only, and place the resulting file in
`another_crate/src/pb`.

2) Similarly, we could also keep the `.proto` definitions in a separate crate and then use that
5 changes: 2 additions & 3 deletions examples/src/grpc-web/server.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use tonic::{transport::Server, Request, Response, Status};

use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use tonic_web::GrpcWebLayer;

pub mod hello_world {
tonic::include_proto!("helloworld");
@@ -33,14 +34,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let greeter = MyGreeter::default();
let greeter = GreeterServer::new(greeter);
let greeter = tonic_web::config()
.allow_origins(vec!["127.0.0.1"])
.enable(greeter);

println!("GreeterServer listening on {}", addr);

Server::builder()
.accept_http1(true)
.layer(GrpcWebLayer::new())
.add_service(greeter)
.serve(addr)
.await?;
2 changes: 1 addition & 1 deletion interop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ path = "src/bin/server.rs"
[dependencies]
async-stream = "0.3"
bytes = "1.0"
clap = {version = "3.2.1", features = ["derive"]}
clap = {version = "4.0.26", features = ["derive"]}
console = "0.14"
futures-core = "0.3"
futures-util = "0.3"
8 changes: 4 additions & 4 deletions interop/src/bin/client.rs
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@ struct Opts {
#[clap(name = "use_tls", long, action = ArgAction::SetTrue)]
use_tls: bool,

#[clap(
#[arg(
long = "test_case",
use_value_delimiter = true,
min_values = 1,
arg_enum,
num_args(1..),
value_enum,
action = ArgAction::Append
)]
test_case: Vec<Testcase>,
@@ -99,7 +99,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[derive(Debug, Copy, Clone, clap::ArgEnum)]
#[derive(Debug, Copy, Clone, clap::ValueEnum)]
#[clap(rename_all = "snake_case")]
enum Testcase {
EmptyUnary,
17 changes: 17 additions & 0 deletions tests/disable_comments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
authors = ["bouzuya <m@bouzuya.net>"]
edition = "2018"
license = "MIT"
name = "disable-comments"
publish = false
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prost = "0.11"
tonic = { path = "../../tonic" }

[build-dependencies]
prost-build = "0.11"
tonic-build = { path = "../../tonic-build" }
11 changes: 11 additions & 0 deletions tests/disable_comments/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main() {
let mut config = prost_build::Config::default();
config.disable_comments(&["test.Input1", "test.Output1"]);
tonic_build::configure()
.disable_comments("test.Service1")
.disable_comments("test.Service1.Rpc1")
.build_client(true)
.build_server(true)
.compile_with_config(config, &["proto/test.proto"], &["proto"])
.unwrap();
}
29 changes: 29 additions & 0 deletions tests/disable_comments/proto/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";

package test;

// This comment will be removed.
service Service1 {
// This comment will be removed.
rpc Rpc1(Input1) returns (Output1);
// This comment will not be removed.
rpc Rpc2(Input2) returns (Output2);
}

// This comment will not be removed.
service Service2 {
// This comment will not be removed.
rpc Rpc(Input1) returns (Output1);
}

// This comment will be removed.
message Input1 {}

// This comment will not be removed.
message Input2 {}

// This comment will be removed.
message Output1 {}

// This comment will not be removed.
message Output2 {}
3 changes: 3 additions & 0 deletions tests/disable_comments/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("test");
}
15 changes: 15 additions & 0 deletions tests/disable_comments/tests/disable_comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::{fs, path::PathBuf};

#[test]
fn test() {
let path = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("test.rs");
let s = fs::read_to_string(path).unwrap();
assert!(!s.contains("This comment will be removed."));
let mut count = 0_usize;
let mut index = 0_usize;
while let Some(found) = s[index..].find("This comment will not be removed.") {
index += found + 1;
count += 1;
}
assert_eq!(count, 2 + 3 + 3); // message: 2, client: 3, server: 3
}
4 changes: 2 additions & 2 deletions tonic-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@ license = "MIT"
name = "tonic-build"
readme = "README.md"
repository = "https://github.com/hyperium/tonic"
version = "0.8.2"
version = "0.8.3"

[dependencies]
prettyplease = { version = "0.1" }
proc-macro2 = "1.0"
prost-build = { version = "0.11", optional = true }
prost-build = { version = "0.11.2", optional = true }
quote = "1.0"
syn = "1.0"

64 changes: 57 additions & 7 deletions tonic-build/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use super::{Attributes, Method, Service};
use crate::{generate_doc_comments, naive_snake_case};
use proc_macro2::TokenStream;
@@ -7,19 +9,46 @@ use quote::{format_ident, quote};
///
/// This takes some `Service` and will generate a `TokenStream` that contains
/// a public module with the generated client.
#[deprecated(since = "0.8.3", note = "Use the CodeGenBuilder::generate_client")]
pub fn generate<T: Service>(
service: &T,
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
build_transport: bool,
attributes: &Attributes,
) -> TokenStream {
generate_internal(
service,
emit_package,
proto_path,
compile_well_known_types,
build_transport,
attributes,
&HashSet::default(),
)
}

pub(crate) fn generate_internal<T: Service>(
service: &T,
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
build_transport: bool,
attributes: &Attributes,
disable_comments: &HashSet<String>,
) -> TokenStream {
let service_ident = quote::format_ident!("{}Client", service.name());
let client_mod = quote::format_ident!("{}_client", naive_snake_case(service.name()));
let methods = generate_methods(service, emit_package, proto_path, compile_well_known_types);
let methods = generate_methods(
service,
emit_package,
proto_path,
compile_well_known_types,
disable_comments,
);

let connect = generate_connect(&service_ident);
let service_doc = generate_doc_comments(service.comment());
let connect = generate_connect(&service_ident, build_transport);

let package = if emit_package { service.package() } else { "" };
let path = format!(
@@ -29,6 +58,12 @@ pub fn generate<T: Service>(
service.identifier()
);

let service_doc = if disable_comments.contains(&path) {
TokenStream::new()
} else {
generate_doc_comments(service.comment())
};

let mod_attributes = attributes.for_mod(package);
let struct_attributes = attributes.for_struct(&path);

@@ -109,8 +144,8 @@ pub fn generate<T: Service>(
}

#[cfg(feature = "transport")]
fn generate_connect(service_ident: &syn::Ident) -> TokenStream {
quote! {
fn generate_connect(service_ident: &syn::Ident, enabled: bool) -> TokenStream {
let connect_impl = quote! {
impl #service_ident<tonic::transport::Channel> {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
@@ -122,11 +157,17 @@ fn generate_connect(service_ident: &syn::Ident) -> TokenStream {
Ok(Self::new(conn))
}
}
};

if enabled {
connect_impl
} else {
TokenStream::new()
}
}

#[cfg(not(feature = "transport"))]
fn generate_connect(_service_ident: &syn::Ident) -> TokenStream {
fn generate_connect(_service_ident: &syn::Ident, _enabled: bool) -> TokenStream {
TokenStream::new()
}

@@ -135,6 +176,7 @@ fn generate_methods<T: Service>(
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
disable_comments: &HashSet<String>,
) -> TokenStream {
let mut stream = TokenStream::new();
let package = if emit_package { service.package() } else { "" };
@@ -148,7 +190,15 @@ fn generate_methods<T: Service>(
method.identifier()
);

stream.extend(generate_doc_comments(method.comment()));
if !disable_comments.contains(&format!(
"{}{}{}.{}",
package,
if package.is_empty() { "" } else { "." },
service.identifier(),
method.identifier()
)) {
stream.extend(generate_doc_comments(method.comment()));
}

let method = match (method.client_streaming(), method.server_streaming()) {
(false, false) => generate_unary(method, proto_path, compile_well_known_types, path),
Loading