Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust Profiles

The rust profile generates a Cargo crate from your .proto files using prost and (optionally) tonic for gRPC. The crate is published either to crates.io (or any Cargo-compatible registry) or to a Git repository.

Available variants:

  • crate — Publish to a Cargo registry.
  • git — Push the generated crate to a Git remote.

Required tools

  • protoc — Protocol Buffers compiler.
  • protoc-gen-prost — Rust message generator.
  • protoc-gen-prost-crate — Crate-layout generator.
  • protoc-gen-tonic — gRPC plugin (only when grpc = true).
  • cargo — Rust toolchain, used for cargo build and cargo publish.
  • git — Required only for the git variant.

The protoc-gen-* plugins are installed via Cargo:

cargo install protoc-gen-prost protoc-gen-prost-crate protoc-gen-tonic

The crate variant

Generates a Cargo crate under target/<profile>/, runs cargo build to verify, then runs cargo publish against the configured registry.

Example

# .buffy/rust-example.toml
[rust.crate]
name = "tomato"
edition = "2021"
repository = "https://github.com/example/tomato"
documentation = "https://docs.rs/tomato"
registry = "crates-io"
grpc = true

Fields

The name field

The crate name as it will appear in Cargo.toml and on the registry. Must follow Cargo naming rules (lowercase, hyphens permitted).

name = "tomato"

The library name (i.e. the Rust module name) is derived by replacing hyphens with underscores: tomato-rs becomes tomato_rs.

The edition field

The Rust edition for the generated crate.

edition = "2021"

Common values: "2021", "2024". The edition is written verbatim to the generated Cargo.toml.

The repository field

A URL to the source repository. Embedded in the crate’s Cargo.toml as the repository field.

repository = "https://github.com/example/tomato"

The documentation field

A URL to the crate’s documentation page.

documentation = "https://docs.rs/tomato"

The registry field

The name of the Cargo registry to publish to. The special value "crates-io" targets crates.io directly. Any other value must correspond to a registry configured in the user’s ~/.cargo/config.toml:

# ~/.cargo/config.toml
[registries]
my-registry = { index = "sparse+https://my-kellnr.example.com/api/v1/crates/" }
# .buffy/rust.toml
registry = "my-registry"

Default: "crates-io".

The prost_version field

Optional. Pin the prost runtime version. If omitted, Buffy queries crates.io for the latest release.

prost_version = "0.13"

The tonic_version field

Optional. Pin the tonic runtime version (and tonic-prost for tonic 0.13+). Only used when grpc = true. If omitted, Buffy queries crates.io for the latest release.

tonic_version = "0.13"

The grpc field

When true, Buffy invokes protoc-gen-tonic and includes tonic and tonic-prost in the crate’s dependencies.

grpc = true

Default: false.

Required environment variables

VariablePurpose
CARGO_REGISTRY_TOKENToken for the configured registry (publish auth)

For non-crates-io registries, the index URL must be configured in ~/.cargo/config.toml as shown above.

Example consumer usage

cargo add tomato
#![allow(unused)]
fn main() {
use tomato::greeter::HelloRequest;

let req = HelloRequest { name: "World".into() };
println!("{}", req.name);
}

The git variant

Generates the same crate as crate, but commits and tags it to a Git repository instead of uploading to a registry. Useful when you want to distribute internally without setting up a registry, or to give consumers a reproducible Git pin.

Example

# .buffy/rust.toml
[rust.git]
name = "tomato"
edition = "2021"
remote = "git@github.com:example/tomato-rs.git"
branch = "main"
repository = "https://github.com/example/tomato-rs"
documentation = "https://github.com/example/tomato-rs"
grpc = true
keep = ["README.md"]

Fields

The same fields as crate (except registry, which doesn’t apply), plus:

  • remote — Git URL the crate is pushed to.
  • branch — Branch to push to.
  • keep — Files to preserve from the remote.

The remote field

remote = "git@github.com:example/tomato-rs.git"

The branch field

branch = "main"

The keep field

keep = ["README.md"]

Default: [].

Example consumer usage

# in the consumer's Cargo.toml
[dependencies]
tomato = { git = "https://github.com/example/tomato-rs", tag = "v0.1.0" }