131 releases

0.21.0 Apr 8, 2025
0.20.1 Nov 15, 2024
0.20.0 Sep 17, 2024
0.19.0 Jan 14, 2024
0.0.5 Nov 23, 2014

#8 in Development tools

Download history 53955/week @ 2025-02-26 64480/week @ 2025-03-05 60458/week @ 2025-03-12 55545/week @ 2025-03-19 45219/week @ 2025-03-26 51492/week @ 2025-04-02 50750/week @ 2025-04-09 55290/week @ 2025-04-16 58184/week @ 2025-04-23 53705/week @ 2025-04-30 66635/week @ 2025-05-07 71602/week @ 2025-05-14 55859/week @ 2025-05-21 61353/week @ 2025-05-28 71977/week @ 2025-06-04 69989/week @ 2025-06-11

274,055 downloads per month
Used in 90 crates (40 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.21" # Note this is a different library than capnp*c*

[build-dependencies]
capnpc = "0.21"

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:

mod foo_capnp {
    include!(concat!(env!("OUT_DIR"), "/foo_capnp.rs"));
}

mod bar_capnp {
    include!(concat!(env!("OUT_DIR"), "/bar_capnp.rs"));
}

This will be equivalent to executing the shell command

  capnp compile -orust:$OUT_DIR --src-prefix=schema schema/foo.capnp schema/bar.capnp

Dependencies