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

Download history 39666/week @ 2025-12-17 24590/week @ 2025-12-24 37995/week @ 2025-12-31 56956/week @ 2026-01-07 49651/week @ 2026-01-14 55043/week @ 2026-01-21 43479/week @ 2026-01-28 56084/week @ 2026-02-04 91823/week @ 2026-02-11 127319/week @ 2026-02-18 158348/week @ 2026-02-25 154089/week @ 2026-03-04 164366/week @ 2026-03-11 116335/week @ 2026-03-18 99475/week @ 2026-03-25 114214/week @ 2026-04-01

523,718 downloads per month
Used in 167 crates (67 directly)

MIT license

1.5MB
30K SLoC

Cap'n Proto code generation for Rust

crates.io

documentation

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

Dependencies