diff --git a/services/commtest/build.rs b/services/commtest/build.rs index 46d4d769f..5772aa137 100644 --- a/services/commtest/build.rs +++ b/services/commtest/build.rs @@ -1,26 +1,21 @@ use std::fs; -use std::io::{Error, ErrorKind}; +use std::io::Error; + +const PROTO_DIR: &'static str = "../../shared/protos"; fn main() -> Result<(), Error> { - const PROTO_FILES_PATH: &str = "../../shared/protos"; - let proto_files = fs::read_dir(PROTO_FILES_PATH)?; + let proto_files = fs::read_dir(PROTO_DIR)?; for path in proto_files { - let path_str = path? - .path() - .file_name() - .ok_or(Error::new( - ErrorKind::Other, - "failed to obtain the file name", - ))? - .to_string_lossy() - .into_owned(); - println!("{}", path_str.as_str()); - // skip CMakeLists.txt and _generated directory - if path_str.contains("CMakeLists.txt") || path_str.eq("_generated") { + let filename: String = path?.file_name().to_string_lossy().to_string(); + + // Avoid passing non protobuf files to tonic + if !filename.ends_with(".proto") { continue; } - assert!(path_str.contains(".proto")); - tonic_build::compile_protos(format!("{}/{}", PROTO_FILES_PATH, path_str))?; + + println!("Compiling protobuf file: {}", filename); + println!("cargo:rerun-if-changed={}/{}", PROTO_DIR, filename); + tonic_build::compile_protos(format!("{}/{}", PROTO_DIR, filename))?; } Ok(()) }