protoc-gen-prost-crate

A protoc plugin that generates Cargo crates and include files.

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.

Usage

Ensure that protoc-gen-prost-crate has been installed within a directory on your $PATH. Then invoke protoc from the command line as follows:

shell protoc --prost-crate_out=proto/gen -I proto proto/greeter/v1/greeter.proto

Options

The following options can be specified:

A note on parameter values:

Usage with buf

When used with buf, options can be specified in the buf.gen.yaml file. This plugin must be run with strategy: all in order to have a complete view of the protobuf schemas and correctly identify dependencies for the input files.

The following will just produce an include file mod.rs in the output gen directory without any conditional compilation feature flags:

yaml version: v1 plugins: - name: prost-crate out: gen strategy: all opt: - no_features

When using the gen_crate option, later Rust generators should generate into the src directory which will be created by this plugin:

yaml version: v1 plugins: - name: prost out: gen/src opt: - bytes=. - file_descriptor_set - name: prost-crate out: gen strategy: all opt: - gen_crate=Cargo.toml.tpl

When working with private, vendored package dependencies, buf tends to push more files for output than desired. To limit the packages that get put into the include file, used the only_include option:

```yaml version: v1 plugins: - name: prost out: gen/src opt: - bytes=. - filedescriptorset - name: prost-crate out: gen strategy: all opt: - gencrate=Cargo.toml.tpl - onlyinclude=.my_company

```

Cargo manifest template

When using the gen_crate option, the template specified will be placed in the output folder. The template should include a commented insertion point that can be referenced for the placement of the features dependency graph.

protoc will insert the computed dependency graph above the insertion point. If this commented line is not included, then protoc will not know where to place the features list and the insertion will be silently skipped.

```toml [package] name = "my-cool-proto-defs" version = "0.1.0" edition = "2021"

[dependencies] prost = "0.10.0"

[features] default = []

@@protocinsertionpoint(features)

```