use std::path::{Path, PathBuf}; fn main() -> std::io::Result<()> { compile_proto(&["examples/routeguide/route_guide.proto"], ".routeguide")?; Ok(()) } fn compile_proto(paths: &[&str], package: &str) -> std::io::Result<()> { for path in paths { println!("cargo:rerun-if-changed={path}"); } let descriptor_path = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()) .join("proto") .join(package) .with_extension("bin"); std::fs::create_dir_all(descriptor_path.parent().unwrap())?; let parent_dir = Path::new(paths[0]).parent().unwrap(); prost_build::Config::new() .file_descriptor_set_path(&descriptor_path) .compile_well_known_types() .extern_path(".google.protobuf", "::pbjson_types") .compile_protos(paths, &[parent_dir])?; let descriptors = std::fs::read(descriptor_path)?; pbjson_build::Builder::new() .register_descriptors(&descriptors)? .ignore_unknown_fields() .build(&[package])?; Ok(()) }