From 3009cf5261e2a864645b0a5efa266c91de37a838 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 23 Oct 2024 01:31:23 +0900 Subject: [PATCH 1/5] chore: Start development of version 0.13 (#2014) --- examples/helloworld-tutorial.md | 4 ++-- examples/routeguide-tutorial.md | 4 ++-- tonic-build/Cargo.toml | 4 ++-- tonic-build/src/lib.rs | 2 +- tonic-health/Cargo.toml | 8 ++++---- tonic-health/src/lib.rs | 2 +- tonic-reflection/Cargo.toml | 8 ++++---- tonic-reflection/src/lib.rs | 2 +- tonic-types/Cargo.toml | 6 +++--- tonic-types/src/lib.rs | 2 +- tonic-web/Cargo.toml | 6 +++--- tonic-web/src/lib.rs | 2 +- tonic/Cargo.toml | 4 ++-- tonic/src/lib.rs | 2 +- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/examples/helloworld-tutorial.md b/examples/helloworld-tutorial.md index 1ed2003e1..2a2ce4944 100644 --- a/examples/helloworld-tutorial.md +++ b/examples/helloworld-tutorial.md @@ -112,12 +112,12 @@ name = "helloworld-client" path = "src/client.rs" [dependencies] -tonic = "0.12" +tonic = "0.13" prost = "0.13" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } [build-dependencies] -tonic-build = "0.12" +tonic-build = "0.13" ``` 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: diff --git a/examples/routeguide-tutorial.md b/examples/routeguide-tutorial.md index 0727245db..e835940af 100644 --- a/examples/routeguide-tutorial.md +++ b/examples/routeguide-tutorial.md @@ -174,7 +174,7 @@ Edit `Cargo.toml` and add all the dependencies we'll need for this example: ```toml [dependencies] -tonic = "0.12" +tonic = "0.13" prost = "0.13" tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time"] } tokio-stream = "0.1" @@ -185,7 +185,7 @@ serde_json = "1.0" rand = "0.8" [build-dependencies] -tonic-build = "0.12" +tonic-build = "0.13" ``` Create a `build.rs` file at the root of your crate: diff --git a/tonic-build/Cargo.toml b/tonic-build/Cargo.toml index 5648134b7..e116af9d7 100644 --- a/tonic-build/Cargo.toml +++ b/tonic-build/Cargo.toml @@ -4,7 +4,7 @@ categories = ["network-programming", "asynchronous"] description = """ Codegen module of `tonic` gRPC implementation. """ -documentation = "https://docs.rs/tonic-build/0.12.3" +documentation = "https://docs.rs/tonic-build/0.13.0" edition = "2021" homepage = "https://github.com/hyperium/tonic" keywords = ["rpc", "grpc", "async", "codegen", "protobuf"] @@ -12,7 +12,7 @@ license = "MIT" name = "tonic-build" readme = "README.md" repository = "https://github.com/hyperium/tonic" -version = "0.12.3" +version = "0.13.0" [dependencies] prettyplease = { version = "0.2" } diff --git a/tonic-build/src/lib.rs b/tonic-build/src/lib.rs index c9dfe6d61..44b3b44aa 100644 --- a/tonic-build/src/lib.rs +++ b/tonic-build/src/lib.rs @@ -70,7 +70,7 @@ html_logo_url = "https://raw.githubusercontent.com/tokio-rs/website/master/public/img/icons/tonic.svg" )] #![deny(rustdoc::broken_intra_doc_links)] -#![doc(html_root_url = "https://docs.rs/tonic-build/0.12.3")] +#![doc(html_root_url = "https://docs.rs/tonic-build/0.13.0")] #![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] diff --git a/tonic-health/Cargo.toml b/tonic-health/Cargo.toml index e03720ba6..a77048179 100644 --- a/tonic-health/Cargo.toml +++ b/tonic-health/Cargo.toml @@ -4,7 +4,7 @@ categories = ["network-programming", "asynchronous"] description = """ Health Checking module of `tonic` gRPC implementation. """ -documentation = "https://docs.rs/tonic-health/0.12.3" +documentation = "https://docs.rs/tonic-health/0.13.0" edition = "2021" homepage = "https://github.com/hyperium/tonic" keywords = ["rpc", "grpc", "async", "healthcheck"] @@ -12,7 +12,7 @@ license = "MIT" name = "tonic-health" readme = "README.md" repository = "https://github.com/hyperium/tonic" -version = "0.12.3" +version = "0.13.0" [features] default = ["transport"] @@ -23,12 +23,12 @@ async-stream = "0.3" prost = "0.13" tokio = {version = "1.0", features = ["sync"]} tokio-stream = "0.1" -tonic = { version = "0.12", path = "../tonic", default-features = false, features = ["codegen", "prost"] } +tonic = { version = "0.13.0", path = "../tonic", default-features = false, features = ["codegen", "prost"] } [dev-dependencies] tokio = {version = "1.0", features = ["rt-multi-thread", "macros"]} tokio-stream = "0.1" -prost-types = "0.13" +prost-types = "0.13.0" [package.metadata.cargo_check_external_types] allowed_external_types = [ diff --git a/tonic-health/src/lib.rs b/tonic-health/src/lib.rs index 4b2ba6599..4553ca782 100644 --- a/tonic-health/src/lib.rs +++ b/tonic-health/src/lib.rs @@ -16,7 +16,7 @@ html_logo_url = "https://raw.githubusercontent.com/tokio-rs/website/master/public/img/icons/tonic.svg" )] #![deny(rustdoc::broken_intra_doc_links)] -#![doc(html_root_url = "https://docs.rs/tonic-health/0.12.3")] +#![doc(html_root_url = "https://docs.rs/tonic-health/0.13.0")] #![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] diff --git a/tonic-reflection/Cargo.toml b/tonic-reflection/Cargo.toml index 3a102a570..910f92046 100644 --- a/tonic-reflection/Cargo.toml +++ b/tonic-reflection/Cargo.toml @@ -9,13 +9,13 @@ Server Reflection module of `tonic` gRPC implementation. """ edition = "2021" homepage = "https://github.com/hyperium/tonic" -documentation = "https://docs.rs/tonic-reflection/0.12.3" +documentation = "https://docs.rs/tonic-reflection/0.13.0" keywords = ["rpc", "grpc", "async", "reflection"] license = "MIT" name = "tonic-reflection" readme = "README.md" repository = "https://github.com/hyperium/tonic" -version = "0.12.3" +version = "0.13.0" [package.metadata.docs.rs] all-features = true @@ -30,10 +30,10 @@ prost = "0.13" prost-types = {version = "0.13", optional = true} tokio = { version = "1.0", features = ["sync", "rt"], optional = true } tokio-stream = {version = "0.1", features = ["net"], optional = true } -tonic = { version = "0.12", path = "../tonic", default-features = false, features = ["codegen", "prost"] } +tonic = { version = "0.13.0", path = "../tonic", default-features = false, features = ["codegen", "prost"] } [dev-dependencies] -tonic = { version = "0.12", path = "../tonic", default-features = false, features = ["transport"] } +tonic = { version = "0.13.0", path = "../tonic", default-features = false, features = ["transport"] } [package.metadata.cargo_check_external_types] allowed_external_types = [ diff --git a/tonic-reflection/src/lib.rs b/tonic-reflection/src/lib.rs index 117f99f15..574c4765a 100644 --- a/tonic-reflection/src/lib.rs +++ b/tonic-reflection/src/lib.rs @@ -10,7 +10,7 @@ html_logo_url = "https://github.com/hyperium/tonic/raw/master/.github/assets/tonic-docs.png" )] #![deny(rustdoc::broken_intra_doc_links)] -#![doc(html_root_url = "https://docs.rs/tonic-reflection/0.12.3")] +#![doc(html_root_url = "https://docs.rs/tonic-reflection/0.13.0")] #![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] diff --git a/tonic-types/Cargo.toml b/tonic-types/Cargo.toml index 0eb6e3932..62681f47d 100644 --- a/tonic-types/Cargo.toml +++ b/tonic-types/Cargo.toml @@ -7,7 +7,7 @@ categories = ["web-programming", "network-programming", "asynchronous"] description = """ A collection of useful protobuf types that can be used with `tonic`. """ -documentation = "https://docs.rs/tonic-types/0.12.3" +documentation = "https://docs.rs/tonic-types/0.13.0" edition = "2021" homepage = "https://github.com/hyperium/tonic" keywords = ["rpc", "grpc", "protobuf"] @@ -15,12 +15,12 @@ license = "MIT" name = "tonic-types" readme = "README.md" repository = "https://github.com/hyperium/tonic" -version = "0.12.3" +version = "0.13.0" [dependencies] prost = "0.13" prost-types = "0.13" -tonic = { version = "0.12", path = "../tonic", default-features = false } +tonic = { version = "0.13.0", path = "../tonic", default-features = false } [package.metadata.cargo_check_external_types] allowed_external_types = [ diff --git a/tonic-types/src/lib.rs b/tonic-types/src/lib.rs index 73e7b5772..1ba57b99e 100644 --- a/tonic-types/src/lib.rs +++ b/tonic-types/src/lib.rs @@ -150,7 +150,7 @@ html_logo_url = "https://raw.githubusercontent.com/tokio-rs/website/master/public/img/icons/tonic.svg" )] #![deny(rustdoc::broken_intra_doc_links)] -#![doc(html_root_url = "https://docs.rs/tonic-types/0.12.3")] +#![doc(html_root_url = "https://docs.rs/tonic-types/0.13.0")] #![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")] mod generated { diff --git a/tonic-web/Cargo.toml b/tonic-web/Cargo.toml index 3cd17ec09..8a6e4dbcd 100644 --- a/tonic-web/Cargo.toml +++ b/tonic-web/Cargo.toml @@ -4,7 +4,7 @@ categories = ["network-programming", "asynchronous"] description = """ grpc-web protocol translation for tonic services. """ -documentation = "https://docs.rs/tonic-web/0.12.3" +documentation = "https://docs.rs/tonic-web/0.13.0" edition = "2021" homepage = "https://github.com/hyperium/tonic" keywords = ["rpc", "grpc", "grpc-web"] @@ -12,7 +12,7 @@ license = "MIT" name = "tonic-web" readme = "README.md" repository = "https://github.com/hyperium/tonic" -version = "0.12.3" +version = "0.13.0" [dependencies] base64 = "0.22" @@ -22,7 +22,7 @@ http = "1" http-body = "1" http-body-util = "0.1" pin-project = "1" -tonic = { version = "0.12", path = "../tonic", default-features = false } +tonic = { version = "0.13.0", path = "../tonic", default-features = false } tower-service = "0.3" tower-layer = "0.3" tower-http = { version = "0.6", features = ["cors"] } diff --git a/tonic-web/src/lib.rs b/tonic-web/src/lib.rs index aca8f5f2f..4783a12d2 100644 --- a/tonic-web/src/lib.rs +++ b/tonic-web/src/lib.rs @@ -94,7 +94,7 @@ rust_2018_idioms, unreachable_pub )] -#![doc(html_root_url = "https://docs.rs/tonic-web/0.12.3")] +#![doc(html_root_url = "https://docs.rs/tonic-web/0.13.0")] #![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")] pub use call::GrpcWebCall; diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 62df328b1..186d3c03d 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -13,14 +13,14 @@ categories = ["web-programming", "network-programming", "asynchronous"] description = """ A gRPC over HTTP/2 implementation focused on high performance, interoperability, and flexibility. """ -documentation = "https://docs.rs/tonic/0.12.3" +documentation = "https://docs.rs/tonic/0.13.0" edition = "2021" homepage = "https://github.com/hyperium/tonic" keywords = ["rpc", "grpc", "async", "futures", "protobuf"] license = "MIT" readme = "../README.md" repository = "https://github.com/hyperium/tonic" -version = "0.12.3" +version = "0.13.0" [features] codegen = ["dep:async-trait"] diff --git a/tonic/src/lib.rs b/tonic/src/lib.rs index 27830aca7..3e818102e 100644 --- a/tonic/src/lib.rs +++ b/tonic/src/lib.rs @@ -94,7 +94,7 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/tokio-rs/website/master/public/img/icons/tonic.svg" )] -#![doc(html_root_url = "https://docs.rs/tonic/0.12.3")] +#![doc(html_root_url = "https://docs.rs/tonic/0.13.0")] #![doc(issue_tracker_base_url = "https://github.com/hyperium/tonic/issues/")] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] From 6856ffe34df7a1393eda8da4c409c168651c109e Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 23 Oct 2024 01:34:55 +0900 Subject: [PATCH 2/5] chore(codegen): Remove unnecessary collecting iterator (#2018) --- codegen/src/main.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/codegen/src/main.rs b/codegen/src/main.rs index 11e9fcb82..4285ce983 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -78,19 +78,12 @@ fn codegen( .tempdir() .unwrap(); - let iface_files: Vec = iface_files - .iter() - .map(|&path| root_dir.join(path)) - .collect(); - - let include_dirs: Vec = include_dirs - .iter() - .map(|&path| root_dir.join(path)) - .collect(); + let iface_files = iface_files.iter().map(|&path| root_dir.join(path)); + let include_dirs = include_dirs.iter().map(|&path| root_dir.join(path)); let out_dir = root_dir.join(out_dir); let file_descriptor_set_path = root_dir.join(file_descriptor_set_path); - let fds = protox::compile(&iface_files, &include_dirs).unwrap(); + let fds = protox::compile(iface_files, include_dirs).unwrap(); write_fds(&fds, &file_descriptor_set_path); From d40f610d7289d26eac19ee8e7efdeae7952127be Mon Sep 17 00:00:00 2001 From: Shikhar Bhushan Date: Tue, 22 Oct 2024 12:37:26 -0400 Subject: [PATCH 3/5] docs: improve comment around cloning middleware in examples (#1977) --- examples/src/tower/client.rs | 4 +--- examples/src/tower/server.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/src/tower/client.rs b/examples/src/tower/client.rs index e1908033f..b268a6ebb 100644 --- a/examples/src/tower/client.rs +++ b/examples/src/tower/client.rs @@ -68,9 +68,7 @@ mod service { } fn call(&mut self, req: Request) -> Self::Future { - // This is necessary because tonic internally uses `tower::buffer::Buffer`. - // See https://github.com/tower-rs/tower/issues/547#issuecomment-767629149 - // for details on why this is necessary + // See: https://docs.rs/tower/latest/tower/trait.Service.html#be-careful-when-cloning-inner-services let clone = self.inner.clone(); let mut inner = std::mem::replace(&mut self.inner, clone); diff --git a/examples/src/tower/server.rs b/examples/src/tower/server.rs index ba23a7581..b7f524645 100644 --- a/examples/src/tower/server.rs +++ b/examples/src/tower/server.rs @@ -98,9 +98,7 @@ where } fn call(&mut self, req: http::Request) -> Self::Future { - // This is necessary because tonic internally uses `tower::buffer::Buffer`. - // See https://github.com/tower-rs/tower/issues/547#issuecomment-767629149 - // for details on why this is necessary + // See: https://docs.rs/tower/latest/tower/trait.Service.html#be-careful-when-cloning-inner-services let clone = self.inner.clone(); let mut inner = std::mem::replace(&mut self.inner, clone); From 9989968fb080d6a8414bcb86ac3e986a5bd339b8 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 23 Oct 2024 01:48:00 +0900 Subject: [PATCH 4/5] feat(build): Make cleanup-markdown feature additive (#1952) --- tonic-build/Cargo.toml | 2 +- tonic-build/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tonic-build/Cargo.toml b/tonic-build/Cargo.toml index e116af9d7..46ad3af43 100644 --- a/tonic-build/Cargo.toml +++ b/tonic-build/Cargo.toml @@ -25,7 +25,7 @@ syn = "2.0" [features] default = ["transport", "prost"] prost = ["prost-build", "dep:prost-types"] -cleanup-markdown = ["prost", "prost-build/cleanup-markdown"] +cleanup-markdown = ["prost-build?/cleanup-markdown"] transport = [] [package.metadata.docs.rs] diff --git a/tonic-build/src/lib.rs b/tonic-build/src/lib.rs index 44b3b44aa..981655c1b 100644 --- a/tonic-build/src/lib.rs +++ b/tonic-build/src/lib.rs @@ -4,7 +4,8 @@ //! # Feature flags //! //! - `cleanup-markdown`: Enables cleaning up documentation from the generated code. Useful -//! when documentation of the generated code fails `cargo test --doc` for example. +//! when documentation of the generated code fails `cargo test --doc` for example. The +//! `prost` feature must be enabled to use this feature. //! - `prost`: Enables usage of prost generator (enabled by default). //! - `transport`: Enables generation of `connect` method using `tonic::transport::Channel` //! (enabled by default). From d61a55f1ef480dad9f299012c23e199c47d99df5 Mon Sep 17 00:00:00 2001 From: Shikhar Bhushan Date: Tue, 22 Oct 2024 15:37:05 -0400 Subject: [PATCH 5/5] feat: make pub `Channel` fns that allow creating it from a custom connector (#2015) * feat: make pub `Channel` fns that allow creating it from a custom connector The connector is required to be a `Service` that accepts a `http::Uri` and returns a connection implementing hyper's IO traits, which is a very reasonable requirement that can be fulfilled by advanced users that need to customize any mechanics that don't fit into the paved path for HTTP and HTTPS with tonic. One such requirement is customizing `rustls::ClientConfig`, which has come up for a number of users. They have been pointed in the direction of a custom connector, but the APIs on `Endpoint` are not always suitable: `Enedpoint::connect_(lazy_)with_connector` always wraps the provided connector with `transport::channel::service::Connector`. This wrapper validates if the scheme is HTTPS, the TLS feature is enabled, and TLS was not configured on the endpoint, and raises an error `HttpsUriWithoutTlsSupport` in this situation. This is a good safety feature in general, but not if the wrapped connector is taking care of TLS. As a side bonus, `tonic::transport::channel::service::io::BoxedIo` can be avoided. * chore: remove redundant bound on connections --- tonic/src/transport/channel/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tonic/src/transport/channel/mod.rs b/tonic/src/transport/channel/mod.rs index 2fe8a2753..c1bee0140 100644 --- a/tonic/src/transport/channel/mod.rs +++ b/tonic/src/transport/channel/mod.rs @@ -16,7 +16,6 @@ use http::{ uri::{InvalidUri, Uri}, Request, Response, }; -use hyper_util::client::legacy::connect::Connection as HyperConnection; use std::{ fmt, future::Future, @@ -144,12 +143,15 @@ impl Channel { (Self::balance(list, DEFAULT_BUFFER_SIZE, executor), tx) } - pub(crate) fn new(connector: C, endpoint: Endpoint) -> Self + /// Create a new [`Channel`] using a custom connector to the provided [Endpoint]. + /// + /// This is a lower level API, prefer to use [`Endpoint::connect_lazy`] if you are not using a custom connector. + pub fn new(connector: C, endpoint: Endpoint) -> Self where C: Service + Send + 'static, C::Error: Into + Send, C::Future: Send, - C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static, + C::Response: rt::Read + rt::Write + Unpin + Send + 'static, { let buffer_size = endpoint.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE); let executor = endpoint.executor.clone(); @@ -162,12 +164,15 @@ impl Channel { Channel { svc } } - pub(crate) async fn connect(connector: C, endpoint: Endpoint) -> Result + /// Connect to the provided [`Endpoint`] using the provided connector, and return a new [`Channel`]. + /// + /// This is a lower level API, prefer to use [`Endpoint::connect`] if you are not using a custom connector. + pub async fn connect(connector: C, endpoint: Endpoint) -> Result where C: Service + Send + 'static, C::Error: Into + Send, C::Future: Unpin + Send, - C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static, + C::Response: rt::Read + rt::Write + Unpin + Send + 'static, { let buffer_size = endpoint.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE); let executor = endpoint.executor.clone();