146 releases (25 breaking)
| new 0.25.3 | Apr 2, 2026 |
|---|---|
| 0.25.2 | Mar 30, 2026 |
| 0.25.0 | Jan 9, 2026 |
| 0.24.0 | Dec 24, 2025 |
| 0.0.5 | Nov 23, 2014 |
#7 in Development tools
523,718 downloads per month
Used in 167 crates
(67 directly)
1.5MB
30K
SLoC
Cap'n Proto code generation for Rust
The generated code depends on the capnproto-rust runtime library.
Code generation can be customized through the annotations defined in rust.capnp.
lib.rs:
Cap'n Proto Schema Compiler Plugin Library
This library allows you to do
Cap'n Proto code generation
within a Cargo build. You still need the capnp binary (implemented in C++).
(If you use a package manager, try looking for a package called
capnproto.)
In your Cargo.toml:
[dependencies]
capnp = "0.25" # Note this is a different library than capnp*c*
[build-dependencies]
capnpc = "0.25"
In your build.rs:
fn main() {
capnpc::CompilerCommand::new()
.src_prefix("schema")
.file("schema/foo.capnp")
.file("schema/bar.capnp")
.run().expect("schema compiler command");
}
In your lib.rs:
capnp::generated_code!(mod foo_capnp);
capnp::generated_code!(mod bar_capnp);
This will be equivalent to executing the shell command
capnp compile -orust:$OUT_DIR --src-prefix=schema schema/foo.capnp schema/bar.capnp