130 releases

0.20.1 Nov 15, 2024
0.19.0 Jan 14, 2024
0.18.0 Sep 4, 2023
0.17.2 Jun 26, 2023
0.0.5 Nov 23, 2014

#19 in Development tools

Download history 33359/week @ 2024-09-23 34795/week @ 2024-09-30 35199/week @ 2024-10-07 33305/week @ 2024-10-14 38757/week @ 2024-10-21 33009/week @ 2024-10-28 39272/week @ 2024-11-04 42257/week @ 2024-11-11 47501/week @ 2024-11-18 38368/week @ 2024-11-25 46768/week @ 2024-12-02 45256/week @ 2024-12-09 43712/week @ 2024-12-16 11641/week @ 2024-12-23 16881/week @ 2024-12-30 40304/week @ 2025-01-06

113,407 downloads per month
Used in 80 crates (36 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.20" # Note this is a different library than capnp*c*

[build-dependencies]
capnpc = "0.20"

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