126 releases

0.18.0 Sep 4, 2023
0.17.2 Jun 26, 2023
0.17.1 May 12, 2023
0.16.3 Feb 27, 2023
0.0.5 Nov 23, 2014

#99 in Encoding

Download history 18815/week @ 2023-06-13 21707/week @ 2023-06-20 19314/week @ 2023-06-27 18736/week @ 2023-07-04 18842/week @ 2023-07-11 19746/week @ 2023-07-18 18389/week @ 2023-07-25 16027/week @ 2023-08-01 18392/week @ 2023-08-08 16240/week @ 2023-08-15 18253/week @ 2023-08-22 19444/week @ 2023-08-29 21457/week @ 2023-09-05 19621/week @ 2023-09-12 20546/week @ 2023-09-19 19886/week @ 2023-09-26

83,837 downloads per month
Used in 52 crates (22 directly)

MIT license

1.5MB
29K 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.18" # Note this is a different library than capnp*c*

[build-dependencies]
capnpc = "0.18"

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