fn main() {
let proto_include = "../proto";
if !std::path::Path::new(proto_include).exists() {
println!("cargo:warning=Not found '{}', skipping proto generation", proto_include);
return;
}
let proto_files : Vec<String> = std::fs::read_dir(proto_include).unwrap().filter_map(|entry| {
let path = entry.unwrap().path();
if path.extension()? == "proto" {
Some(path.to_string_lossy().into_owned())
} else {
None
}
}).collect();
let proto_refs: Vec<&str> = proto_files.iter().map(|s| s.as_str()).collect();
let out_dir = std::path::PathBuf::from("generated");
std::fs::create_dir_all(&out_dir).unwrap();
prost_build::Config::new()
.out_dir(&out_dir)
.compile_protos(&proto_refs, &[proto_include])
.expect("Failed to compile .proto files");
for proto in &proto_files {
println!("cargo:rerun-if-changed={}", proto);
}
}