diff --git a/tonic-build/Cargo.toml b/tonic-build/Cargo.toml index 5352567..5528e25 100644 --- a/tonic-build/Cargo.toml +++ b/tonic-build/Cargo.toml @@ -11,4 +11,7 @@ prost-build = "0.5" syn = "1.0" quote = "1.0" proc-macro2 = "1.0" -rustfmt = "0.10" + + +[features] +rustfmt = [] diff --git a/tonic-build/src/lib.rs b/tonic-build/src/lib.rs index ca795a7..baf11b2 100644 --- a/tonic-build/src/lib.rs +++ b/tonic-build/src/lib.rs @@ -28,6 +28,7 @@ where compile_protos_with_out_dir(protos, includes, package, out_dir.as_str()) } +#[allow(unused_variables)] pub fn compile_protos_with_out_dir>( protos: &[P], includes: &[P], @@ -40,6 +41,7 @@ pub fn compile_protos_with_out_dir>( config.out_dir(out_dir.as_ref()); config.compile_protos(protos, includes)?; + #[cfg(feature = "rustfmt")] fmt( out_dir.as_ref().to_str().expect("Execpted utf8 out_dir"), &format!("{}.rs", package), @@ -48,6 +50,7 @@ pub fn compile_protos_with_out_dir>( Ok(()) } +#[cfg(feature = "rustfmt")] fn fmt(out_dir: &str, file: &str) { let out = Command::new("rustfmt") .arg("--emit") diff --git a/tonic-examples/Cargo.toml b/tonic-examples/Cargo.toml index 8517db8..f06e908 100644 --- a/tonic-examples/Cargo.toml +++ b/tonic-examples/Cargo.toml @@ -33,4 +33,4 @@ async-stream = { git = "https://github.com/tokio-rs/async-stream" } http = "0.1" [build-dependencies] -tonic-build = { path = "../tonic-build" } +tonic-build = { path = "../tonic-build", features = ["rustfmt"] }