fn main() -> Result<(), Box<dyn std::error::Error>> {
if std::env::var("REGENERATE_PROTO").is_ok() {
#[cfg(feature = "regenerate-proto")]
{
println!("cargo:warning=Regenerating protobuf code (REGENERATE_PROTO is set)");
let proto_path = if std::path::Path::new("../../proto/gaia-client.proto").exists() {
"../../proto/gaia-client.proto"
} else {
"proto/gaia-client.proto"
};
let proto_dir = if std::path::Path::new("../../proto").exists() {
"../../proto"
} else {
"proto"
};
tonic_build::configure()
.build_server(false)
.compile(&[proto_path], &[proto_dir])?;
println!("cargo:warning=Protobuf code regenerated in target/*/build/gaia-client-*/out/gaia.rs");
println!("cargo:warning=Copy it to src/proto.rs: cp target/debug/build/gaia-client-*/out/gaia.rs src/proto.rs");
}
#[cfg(not(feature = "regenerate-proto"))]
{
println!("cargo:warning=REGENERATE_PROTO is set but 'regenerate-proto' feature is not enabled");
println!("cargo:warning=Use: REGENERATE_PROTO=1 cargo build --features regenerate-proto");
}
} else {
println!("cargo:rerun-if-changed=src/proto.rs");
}
Ok(())
}