fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let descriptor_path = out_dir.join("echo_descriptor.bin");
let protoc = protoc_bin_vendored::protoc_bin_path()?;
unsafe {
std::env::set_var("PROTOC", &protoc);
}
tonic_build::configure()
.build_client(false)
.build_server(false)
.file_descriptor_set_path(&descriptor_path)
.compile_protos(&["tests/proto/echo.proto"], &["tests/proto"])?;
tonic_build::configure()
.build_client(true)
.build_server(true)
.compile_protos(&["tests/proto/echo.proto"], &["tests/proto"])?;
println!("cargo:rerun-if-changed=tests/proto/echo.proto");
println!(
"cargo:rustc-env=ECHO_DESCRIPTOR_PATH={}",
descriptor_path.display()
);
Ok(())
}