make rustfmt optional

This commit is contained in:
Lucio Franco
2019-09-06 18:25:27 -04:00
parent cd44bf8e9f
commit cc8a7bfcbf
3 changed files with 8 additions and 2 deletions
+4 -1
View File
@@ -11,4 +11,7 @@ prost-build = "0.5"
syn = "1.0"
quote = "1.0"
proc-macro2 = "1.0"
rustfmt = "0.10"
[features]
rustfmt = []
+3
View File
@@ -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<P: AsRef<Path>>(
protos: &[P],
includes: &[P],
@@ -40,6 +41,7 @@ pub fn compile_protos_with_out_dir<P: AsRef<Path>>(
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<P: AsRef<Path>>(
Ok(())
}
#[cfg(feature = "rustfmt")]
fn fmt(out_dir: &str, file: &str) {
let out = Command::new("rustfmt")
.arg("--emit")
+1 -1
View File
@@ -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"] }