# tonin-build
`build.rs` helper that wraps [`tonic-build`](https://crates.io/crates/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](https://crates.io/crates/tonin) framework.
## Usage
Add it as a build-dependency in your service's `Cargo.toml`:
```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:
```rust,no_run
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](https://crates.io/crates/tonin) — umbrella crate re-exporting the runtime
- [tonin-core](https://crates.io/crates/tonin-core) — `Service` builder, traits, transport, telemetry
- [micro](https://crates.io/crates/micro) — CLI that scaffolds services with a ready-to-use `build.rs`
---
Licensed under the Apache License, Version 2.0.