use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=proto/");
let proto_files = ["proto/tfplugin5.proto", "proto/tfplugin6.proto"];
let present: Vec<&&str> = proto_files
.iter()
.filter(|p| Path::new(p).exists())
.collect();
if present.is_empty() {
println!(
"cargo:warning=magma-protocol: proto files not yet vendored; \
gRPC bindings unavailable. Vendor tfplugin5.proto + \
tfplugin6.proto from github.com/opentofu/opentofu/internal/ \
then rebuild."
);
return;
}
if std::env::var("PROTOC").is_err() {
if let Ok(path) = protoc_bin_vendored::protoc_bin_path() {
unsafe {
std::env::set_var("PROTOC", path);
}
}
}
let proto_paths: Vec<&str> = present.iter().map(|&&p| p).collect();
if let Err(e) = tonic_build::configure()
.build_server(true)
.build_client(true)
.compile_protos(&proto_paths, &["proto/"])
{
panic!("magma-protocol: tonic-build failed: {e}");
}
}