use anyhow::Result; use std::env; use std::path::PathBuf; const OUT_DIR: &str = "src/generated"; fn main() -> Result<()> { // Generate protobuf sources let descriptor_path = PathBuf::from(env::var("OUT_DIR")?).join("proto_descriptor.bin"); let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR")?; let include_dir = PathBuf::from_iter([&cargo_manifest_dir, "protobuf"]); tonic_build::configure() .out_dir(OUT_DIR) .file_descriptor_set_path(&descriptor_path) .protoc_arg("--experimental_allow_proto3_optional") .compile_well_known_types(true) .extern_path(".google.protobuf", "::pbjson_types") .compile(&["onprem/device/v1/device_config.proto", "onprem/user/v1/user_service.proto"], &[include_dir])?; // Generate pbjson serde support let descriptor_set = std::fs::read(descriptor_path)?; pbjson_build::Builder::new() .out_dir(OUT_DIR) .register_descriptors(&descriptor_set)? .ignore_unknown_fields() .emit_fields() .build(&[".google.protobuf", ".onprem.device.v1", ".onprem.user.v1"])?; Ok(()) }