tonin-build 0.3.4

build.rs helper for tonin services. Wraps tonic-build with tonin conventions.
Documentation
  • Coverage
  • 20%
    1 out of 5 items documented1 out of 3 items with examples
  • Size
  • Source code size: 32.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 475.57 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Rushit/tonin
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Rushit

tonin-build

build.rs helper that wraps tonic-build with tonin conventions. Every tonin service calls it from its own build.rs to compile .proto files into gRPC client + server stubs.

Part of the tonin framework.

Usage

Add it as a build-dependency in your service's Cargo.toml:

[build-dependencies]
tonin-build = "0.1"

Then call compile from build.rs, passing the protos to compile and the include paths to resolve import statements against:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Skip codegen if protoc is unavailable so the workspace still `cargo check`s
    // without system protoc installed. Set TONIN_SKIP_PROTOC=1 to skip.
    if std::env::var("TONIN_SKIP_PROTOC").is_ok() {
        return Ok(());
    }
    tonin_build::compile(&["proto/greeter.proto"], &["proto"])
}

The generated code lands in OUT_DIR and is pulled into the service with tonic::include_proto!("<package>") in main.rs.

What it does

  • Drives tonic_build::configure().compile_protos(...) — both client and server stubs are generated by default (prost codegen).
  • The TONIN_CODEC env var is reserved for a future codegen path:
    • unset or prost — runs tonic-build (this is what happens today, every build).
    • buffa — reserved for a planned protoc-gen-micro plugin. Setting it today logs a notice to stderr and falls back to tonic-build so scaffolds keep working.
  • Requires protoc on PATH. Services that want to opt out of proto compilation (e.g. for cargo check on a machine without protoc) typically gate the call on a TONIN_SKIP_PROTOC env var, as shown above.

Include paths follow tonic-build / protoc semantics: every directory you want import statements resolved against must be listed.

See also

  • tonin — umbrella crate re-exporting the runtime
  • tonin-coreService builder, traits, transport, telemetry
  • micro — CLI that scaffolds services with a ready-to-use build.rs

Licensed under the Apache License, Version 2.0.