Build-time code generation utilities for Protocol Buffers with enhanced helpers
The bomboni_prost crate provides utilities for compiling Protocol Buffers with prost and generating additional helper functions beyond the standard prost output.
Use the compile function in your build.rs to generate enhanced Rust code from Protocol Buffers:
build.rs
use bomboni_prost::{compile, config::CompileConfig};fn main() { let config = CompileConfig { file_descriptor_set_path: "descriptor.bin".into(), output_path: "src/generated".into(), format: true, ..Default::default() }; compile(config).expect("Failed to compile protobuf files");}
The compile function expects a file descriptor set that has been generated by protoc --descriptor_set_out. This is typically created by tonic-build or prost-build.
The PathMap type allows you to map protobuf types to custom Rust implementations:
use bomboni_prost::path_map::PathMap;let mut external_paths = PathMap::default();// Map google.protobuf.Timestamp to chrono::DateTimeexternal_paths.insert( ".google.protobuf.Timestamp", "chrono::DateTime<chrono::Utc>");// Map custom types to your own implementationsexternal_paths.insert( ".myapi.User", "crate::models::User");
After compilation, generated code is written to files with a .plus suffix:
// Include both prost-generated code and bomboni helpersbomboni_proto::include_proto!("bookstore.v1"); // from prost-buildbomboni_proto::include_proto!("bookstore.v1.plus"); // from bomboni_prost
The .plus suffix distinguishes Bomboni’s enhanced code from the base prost-generated code, allowing you to use both side-by-side.