use std::path::PathBuf; fn main() { println!("cargo:rerun-if-changed=main.rs"); let proto_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) .join("schemas") .join("proto"); let proto_files = proto_dir .read_dir() .unwrap() .flatten() .map(|e| (e.path(), e.metadata())) .filter_map(|(path, file_type)| { file_type .ok() .filter(|file_type| file_type.is_file()) .map(|_| path) }) .collect::>(); if proto_files.is_empty() { panic!("failed to find any proto files in {}", proto_dir.display()); } tonic_build::compile_protos(proto_files.first().unwrap()).unwrap(); }