Expand description
Generic build-helper primitives for proto-source services.
The four primitives this crate exposes are the ones every
.proto-publishing or .proto-consuming Rust crate ends up
reimplementing:
- Stage embedded proto bytes onto a tempdir at protoc-relative
paths so
import "myproto/v1/foo.proto";resolves at build time without the consumer vendoring the file (Stager). - Compile
.protofiles viaprotox(pure Rust, noprotocsubprocess) and return both theprost-reflectdescriptor pool (preserves custom-option VALUES) and the FDS bytes for downstream codegen (compile_protos). - Read
MethodOptionsextension values from the descriptor pool — encoded FDS drops them, the pool keeps them (extract_method_string_extension). - Drive
tonic-prost-buildwithtype_attribute(...)injection from an annotation-FQN map (tonic_prost_build_with_attrs, gated on thetonicfeature).
The crate is schema-agnostic — it doesn’t know about any specific
proto package or annotation. Consumers pair it with a tiny sibling
crate that ships their .proto bytes via include_bytes!:
ⓘ
// some-protos/src/lib.rs (your bytes crate):
const FOO: &[u8] = include_bytes!("../proto/my/v1/foo.proto");
pub fn files() -> impl Iterator<Item = (&'static str, &'static [u8])> {
[("my/v1/foo.proto", FOO)].into_iter()
}Consumer build.rs then composes any number of *-protos crates:
ⓘ
use proto_build_kit::Stager;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let staged = Stager::new()
.with(some_protos::files())
.with(other_protos::files())
.stage()?;
// Drive whatever codegen you want (connectrpc-build, tonic, ...)
// against `staged.path()` on the include path.
Ok(())
}Hold the returned tempfile::TempDir until codegen completes —
drop deletes the staged files.
Structs§
- Compile
Output - Result of
compile_protos. - Stager
- Accumulates
(relative_path, bytes)pairs and writes them to a fresh tempdir laid out as<tmp>/<relative_path>.
Enums§
- Error
- Errors surfaced by the
proto-build-kitprimitives.
Functions§
- compile_
protos - Compile a set of
.protofiles (and all their transitive imports) viaprotox. - extract_
method_ string_ extension - Walk every method declared in
pool, look for theMethodOptions-level extension namedextension_fqn, and return a map keyed by response-message FQN (e.g.my.v1.Resource) with the extension’s string value. - tonic_
prost_ build_ with_ attrs - Run
tonic-prost-buildcodegen onfds_bytes, applying everytype_attribute(<fqn>, <attribute>)fromtype_attributesbefore invocation.