fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "grpc-api")]
{
use std::path::PathBuf;
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
let local_proto = manifest_dir.join("proto");
let workspace_proto = manifest_dir
.parent()
.map(|p| p.join("proto"))
.unwrap_or_default();
let proto_root = if local_proto.join("tasker/v1").exists() {
local_proto
} else if workspace_proto.join("tasker/v1").exists() {
workspace_proto
} else {
panic!(
"Proto directory not found. Checked {:?} and {:?}. Expected proto files at proto/tasker/v1/",
local_proto, workspace_proto
);
};
let proto_files = [
"tasker/v1/common.proto",
"tasker/v1/tasks.proto",
"tasker/v1/steps.proto",
"tasker/v1/templates.proto",
"tasker/v1/analytics.proto",
"tasker/v1/dlq.proto",
"tasker/v1/health.proto",
"tasker/v1/config.proto",
"tasker/v1/worker.proto", ];
let proto_paths: Vec<PathBuf> = proto_files
.iter()
.map(|f| {
let path = proto_root.join(f);
if !path.exists() {
panic!("Proto file not found: {:?}", path);
}
path
})
.collect();
tonic_prost_build::configure()
.build_server(true)
.build_client(true)
.build_transport(true)
.file_descriptor_set_path(
PathBuf::from(std::env::var("OUT_DIR")?).join("tasker_descriptor.bin"),
)
.emit_rerun_if_changed(true)
.compile_protos(&proto_paths, std::slice::from_ref(&proto_root))?;
println!("cargo:rerun-if-changed={}", proto_root.display());
for proto in &proto_files {
println!(
"cargo:rerun-if-changed={}",
proto_root.join(proto).display()
);
}
}
Ok(())
}