A protoc
plugin that generates code using the Prost! code generation engine.
When used in projects that use only Rust code, the preferred mechanism for
generating protobuf definitions with Prost! is to use prost-build
from
within a build.rs
file. However, when working in polyglot environments,
it can be advantageous to utilize common tooling in the Protocol Buffers
ecosystem. One common tool used for this purpose is buf, which simplifies
the code generation process and includes several useful features, including
linting, package management, and breaking change detection.
The various modules that are used for generating Rust code with Prost! and Tonic are available in the named subdirectories. Refer to the README in each of those folders for more information.
- protoc-gen-prost: The core code generation plugin
- protoc-gen-prost-crate: Generates an include file and cargo manifest for turn-key crates
- protoc-gen-prost-serde: Canonical JSON serialization of protobuf types
- protoc-gen-prost-validate: Generate validators based on embedded metadata
- protoc-gen-tonic: gRPC service generation for the Tonic framework
Note: When executing protoc-gen-prost-crate
with the gen_crate
option, remote
generation is not possible, as the manifest template is not made available to a
remote plugin.
version: v2
plugins:
- remote: buf.build/community/neoeinstein-prost:v0.4.0
out: gen/src
opt:
- bytes=.
- compile_well_known_types
- extern_path=.google.protobuf=::pbjson_types
- file_descriptor_set
- remote: buf.build/community/neoeinstein-prost-serde:v0.3.1
out: gen/src
- remote: buf.build/community/neoeinstein-tonic:v0.4.1
out: gen/src
opt:
- compile_well_known_types
- extern_path=.google.protobuf=::pbjson_types
- local: protoc-gen-prost-crate
out: gen
strategy: all
opt:
- gen_crate=Cargo.toml
See example/build-with-buf
for an example of invoking buf
as part of a
build.rs
build script. This may be useful when you want to extend the
generated files with additional trait or inherent implementations.