Home

prostbuild

prost-build is a Rust library that generates Rust code from Protocol Buffer (.proto) files at build time as part of the Prost ecosystem. It is designed to be used alongside Prost, a Protocol Buffers implementation for Rust, and with tools like tonic for gRPC services. prost-build reads .proto definitions and produces Rust types representing messages, enums, and oneof constructs, with options to customize the generated code.

To use prost-build, developers add it as a build-dependency in Cargo.toml and provide a build script (build.rs)

The generated Rust source files are written to the crate’s OUT_DIR during compilation. The crate then includes

prost-build focuses on generating message types and related code, and does not itself emit gRPC service stubs.

that
configures
and
runs
the
generator.
The
common
workflow
calls
prost_build::compile_protos
with
a
list
of
proto
files
and
include
directories.
A
Config
object
can
be
used
to
customize
the
output,
for
example
to
map
well-known
types
to
external
crates
via
extern_path,
or
to
attach
attributes
to
generated
types
through
type_attribute.
these
generated
modules
with
include!(concat!(env!("OUT_DIR"),
"/<generated>.rs"));,
allowing
the
generated
code
to
be
compiled
as
part
of
the
crate
without
occupying
the
main
source
tree.
For
gRPC
service
generation,
developers
typically
use
tonic-build
in
conjunction
with
prost-build
to
generate
both
message
types
and
service
definitions.