make rustfmt optional
This commit is contained in:
@@ -11,4 +11,7 @@ prost-build = "0.5"
|
||||
syn = "1.0"
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
rustfmt = "0.10"
|
||||
|
||||
|
||||
[features]
|
||||
rustfmt = []
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
Reference in New Issue
Block a user