From 0536f8b20aa74509732a1710554ed1f113498f34 Mon Sep 17 00:00:00 2001 From: LIU JIE Date: Thu, 1 Aug 2024 14:24:39 +0800 Subject: [PATCH] chore(volo-grpc): make grpc-web as a feature (#479) * chore(volo-grpc): make grpc-web as a feature * fix cargo clippy --- Cargo.lock | 108 +++++++++++++++--------- examples/Cargo.toml | 2 +- examples/src/thrift/hello/client.rs | 2 - examples/src/thrift/multiplex/client.rs | 2 - examples/src/thrift/unknown/client.rs | 2 - scripts/clippy-and-test.sh | 1 + volo-grpc/Cargo.toml | 8 +- volo-grpc/src/layer/mod.rs | 1 + 8 files changed, 77 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5448f65..d6b491fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ "once_cell", "serde", "version_check", - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -276,20 +276,26 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" +checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9" dependencies = [ "serde", ] [[package]] name = "cc" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" dependencies = [ "jobserver", "libc", @@ -321,9 +327,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.11" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35723e6a11662c2afb578bcf0b88bf6ea8e21282a953428f240574fcc3a2b5b3" +checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" dependencies = [ "clap_builder", "clap_derive", @@ -331,9 +337,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.11" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49eb96cbfa7cfa35017b7cd548c75b14c3118c98b423041d70562665e07fb0fa" +checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" dependencies = [ "anstream", "anstyle", @@ -344,9 +350,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.11" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d029b67f89d30bbb547c89fd5161293c0aec155fc691d7924b64550662db93e" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -845,7 +851,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.2.6", + "indexmap 2.3.0", "slab", "tokio", "tokio-util", @@ -864,7 +870,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.1.0", - "indexmap 2.2.6", + "indexmap 2.3.0", "slab", "tokio", "tokio-util", @@ -1202,9 +1208,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -1634,18 +1640,18 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1736,9 +1742,9 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "ordered-float" -version = "4.2.1" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ff2cf528c6c03d9ed653d6c4ce1dc0582dc4af309790ad92f07c1cd551b0be" +checksum = "4a91171844676f8c7990ce64959210cd2eaef32c2612c50f9fae9f8aaa6065a6" dependencies = [ "num-traits", "rand", @@ -1840,7 +1846,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.2.6", + "indexmap 2.3.0", ] [[package]] @@ -1997,9 +2003,12 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "dee4364d9f3b902ef14fab8a1ddffb783a1cb6b4bba3bfc1fa3922732c7de97f" +dependencies = [ + "zerocopy 0.6.6", +] [[package]] name = "predicates" @@ -2605,7 +2614,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.3.0", "itoa", "ryu", "serde", @@ -2974,21 +2983,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.17", + "toml_edit 0.22.20", ] [[package]] name = "toml_datetime" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] @@ -2999,22 +3008,22 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.3.0", "toml_datetime", "winnow 0.5.40", ] [[package]] name = "toml_edit" -version = "0.22.17" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.3.0", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.16", + "winnow 0.6.18", ] [[package]] @@ -3406,7 +3415,7 @@ dependencies = [ [[package]] name = "volo-grpc" -version = "0.10.2" +version = "0.10.3" dependencies = [ "anyhow", "async-stream", @@ -3845,9 +3854,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.16" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] @@ -3862,13 +3871,34 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "zerocopy" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6" +dependencies = [ + "byteorder", + "zerocopy-derive 0.6.6", +] + [[package]] name = "zerocopy" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "zerocopy-derive", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy-derive" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", ] [[package]] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 20713b47..48eb7928 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -131,7 +131,7 @@ tracing-subscriber.workspace = true pilota.workspace = true volo = { path = "../volo" } -volo-grpc = { path = "../volo-grpc" } +volo-grpc = { path = "../volo-grpc", features = ["grpc-web"] } volo-thrift = { path = "../volo-thrift", features = ["multiplex"] } volo-http = { path = "../volo-http", features = [ "default_client", diff --git a/examples/src/thrift/hello/client.rs b/examples/src/thrift/hello/client.rs index 27ef8e34..308413f3 100644 --- a/examples/src/thrift/hello/client.rs +++ b/examples/src/thrift/hello/client.rs @@ -12,8 +12,6 @@ lazy_static! { }; } -pub struct LogService(S); - #[volo::main] async fn main() { let req = volo_gen::thrift_gen::hello::HelloRequest { diff --git a/examples/src/thrift/multiplex/client.rs b/examples/src/thrift/multiplex/client.rs index 7b306bc4..d1e281c7 100644 --- a/examples/src/thrift/multiplex/client.rs +++ b/examples/src/thrift/multiplex/client.rs @@ -13,8 +13,6 @@ lazy_static! { }; } -pub struct LogService(S); - #[volo::main] async fn main() { let subscriber = tracing_subscriber::FmtSubscriber::builder() diff --git a/examples/src/thrift/unknown/client.rs b/examples/src/thrift/unknown/client.rs index ad08531f..4eaeb7e4 100644 --- a/examples/src/thrift/unknown/client.rs +++ b/examples/src/thrift/unknown/client.rs @@ -12,8 +12,6 @@ lazy_static! { }; } -pub struct LogService(S); - #[volo::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/scripts/clippy-and-test.sh b/scripts/clippy-and-test.sh index a951420b..f2cf06cc 100644 --- a/scripts/clippy-and-test.sh +++ b/scripts/clippy-and-test.sh @@ -28,6 +28,7 @@ echo_command cargo clippy -p volo-grpc --no-default-features -- --deny warnings echo_command cargo clippy -p volo-grpc --no-default-features --features rustls -- --deny warnings echo_command cargo clippy -p volo-grpc --no-default-features --features native-tls -- --deny warnings echo_command cargo clippy -p volo-grpc --no-default-features --features native-tls-vendored -- --deny warnings +echo_command cargo clippy -p volo-grpc --no-default-features --features grpc-web -- --deny warnings echo_command cargo clippy -p volo-http --no-default-features -- --deny warnings echo_command cargo clippy -p volo-http --no-default-features --features default_client -- --deny warnings echo_command cargo clippy -p volo-http --no-default-features --features default_server -- --deny warnings diff --git a/volo-grpc/Cargo.toml b/volo-grpc/Cargo.toml index 1f440f5d..288865fb 100644 --- a/volo-grpc/Cargo.toml +++ b/volo-grpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "volo-grpc" -version = "0.10.2" +version = "0.10.3" edition.workspace = true homepage.workspace = true repository.workspace = true @@ -55,8 +55,8 @@ pin-project.workspace = true tokio = { workspace = true, features = ["time", "rt", "net", "sync", "signal"] } tokio-stream.workspace = true tokio-util = { workspace = true, features = ["codec", "compat"] } -tonic.workspace = true -tonic-web.workspace = true +tonic = { workspace = true, optional = true } +tonic-web = { workspace = true, optional = true } tower = { workspace = true, features = [ "buffer", "limit", @@ -80,3 +80,5 @@ __tls = [] rustls = ["__tls", "dep:tokio-rustls", "volo/rustls"] native-tls = ["__tls", "dep:tokio-native-tls", "volo/native-tls"] native-tls-vendored = ["native-tls", "volo/native-tls-vendored"] + +grpc-web = ["dep:tonic", "dep:tonic-web"] diff --git a/volo-grpc/src/layer/mod.rs b/volo-grpc/src/layer/mod.rs index 2f712e28..39908cf0 100644 --- a/volo-grpc/src/layer/mod.rs +++ b/volo-grpc/src/layer/mod.rs @@ -1,5 +1,6 @@ pub mod cross_origin; pub mod grpc_timeout; +#[cfg(feature = "grpc-web")] pub mod grpc_web; pub mod loadbalance; pub mod user_agent;