129 releases

0.20.0 Sep 17, 2024
0.19.0 Jan 14, 2024
0.18.1 Jan 11, 2024
0.18.0 Sep 4, 2023
0.0.5 Nov 23, 2014

#48 in Development tools

Download history 24464/week @ 2024-07-17 27697/week @ 2024-07-24 26173/week @ 2024-07-31 26010/week @ 2024-08-07 27374/week @ 2024-08-14 27613/week @ 2024-08-21 25556/week @ 2024-08-28 34935/week @ 2024-09-04 31859/week @ 2024-09-11 35247/week @ 2024-09-18 32772/week @ 2024-09-25 35382/week @ 2024-10-02 33107/week @ 2024-10-09 37418/week @ 2024-10-16 34875/week @ 2024-10-23 35021/week @ 2024-10-30

147,743 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