use std::path::PathBuf;
fn main() {
if std::env::var_os("PROTOC").is_none() && which::which("protoc").is_err() {
if let Ok(p) = protoc_bin_vendored::protoc_bin_path() {
unsafe {
std::env::set_var("PROTOC", p);
}
}
}
let manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
let candidates = [
PathBuf::from(&manifest).join("proto"), PathBuf::from(&manifest).join("breathe-api-server").join("proto"), PathBuf::from("proto"), PathBuf::from("breathe-api-server").join("proto"), ];
let proto_dir = candidates
.iter()
.find(|p| p.join("breathe.proto").is_file())
.expect("breathe-api-server build.rs: could not locate proto/breathe.proto");
let proto_file = proto_dir.join("breathe.proto");
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR"));
let descriptor_path = out_dir.join("proto_descriptor.bin");
let mut config = prost_build::Config::new();
config.compile_well_known_types();
config.extern_path(".google.protobuf", "::pbjson_types");
config.file_descriptor_set_path(&descriptor_path);
tonic_build::configure()
.compile_protos_with_config(config, &[proto_file.clone()], &[proto_dir.clone()])
.expect("compile proto/breathe.proto");
let descriptor_set = std::fs::read(&descriptor_path).expect("read descriptor set");
pbjson_build::Builder::new()
.register_descriptors(&descriptor_set)
.expect("register descriptors")
.build(&[".breathe.v1"])
.expect("build pbjson serde impls");
println!("cargo:rerun-if-changed={}", proto_file.display());
}