diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 419c7d33a..7a8c50fd9 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -27,7 +27,7 @@ codegen = ["dep:async-trait"] gzip = ["dep:flate2"] deflate = ["dep:flate2"] zstd = ["dep:zstd"] -default = ["transport", "codegen", "prost"] +default = ["router", "transport", "codegen", "prost"] prost = ["dep:prost"] _tls-any = ["dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"] # Internal. Please choose one of `tls-ring` or `tls-aws-lc` tls-ring = ["_tls-any", "tokio-rustls/ring"] @@ -36,7 +36,6 @@ tls-native-roots = ["_tls-any", "channel", "dep:rustls-native-certs"] tls-webpki-roots = ["_tls-any","channel", "dep:webpki-roots"] router = ["dep:axum", "dep:tower", "tower?/util"] server = [ - "router", "dep:h2", "dep:hyper", "hyper?/server", "dep:hyper-util", "hyper-util?/service", "hyper-util?/server-auto", diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index 63491e5ab..ef7376e39 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -12,7 +12,11 @@ mod unix; use tokio_stream::StreamExt as _; use tracing::{debug, trace}; -use crate::service::Routes; +#[cfg(feature = "router")] +use crate::{server::NamedService, service::Routes}; + +#[cfg(feature = "router")] +use std::convert::Infallible; pub use conn::{Connected, TcpConnectInfo}; use hyper_util::{ @@ -40,7 +44,6 @@ use crate::transport::Error; use self::service::{ConnectInfoLayer, RecoverError, ServerIo}; use super::service::GrpcTimeout; use crate::body::Body; -use crate::server::NamedService; use bytes::Bytes; use http::{Request, Response}; use http_body_util::BodyExt; @@ -48,7 +51,6 @@ use hyper::{body::Incoming, service::Service as HyperService}; use pin_project::pin_project; use std::future::pending; use std::{ - convert::Infallible, fmt, future::{self, poll_fn, Future}, marker::PhantomData, @@ -132,6 +134,7 @@ impl Default for Server { } /// A stack based [`Service`] router. +#[cfg(feature = "router")] #[derive(Debug)] pub struct Router { server: Server, @@ -393,6 +396,7 @@ impl Server { /// /// This will clone the `Server` builder and create a router that will /// route around different services. + #[cfg(feature = "router")] pub fn add_service(&mut self, svc: S) -> Router where S: Service, Error = Infallible> @@ -416,6 +420,7 @@ impl Server { /// # Note /// Even when the argument given is `None` this will capture *all* requests to this service name. /// As a result, one cannot use this to toggle between two identically named implementations. + #[cfg(feature = "router")] pub fn add_optional_service(&mut self, svc: Option) -> Router where S: Service, Error = Infallible> @@ -436,6 +441,7 @@ impl Server { /// /// This will clone the `Server` builder and create a router that will /// route around different services that were already added to the provided `routes`. + #[cfg(feature = "router")] pub fn add_routes(&mut self, routes: Routes) -> Router where L: Clone, @@ -815,12 +821,14 @@ async fn sleep_or_pending(wait_for: Option) { }; } +#[cfg(feature = "router")] impl Router { pub(crate) fn new(server: Server, routes: Routes) -> Self { Self { server, routes } } } +#[cfg(feature = "router")] impl Router { /// Add a new service to this router. pub fn add_service(mut self, svc: S) -> Self