128 releases

0.19.0 Jan 14, 2024
0.18.0 Sep 4, 2023
0.17.2 Jun 26, 2023
0.16.3 Feb 27, 2023
0.0.5 Nov 23, 2014

#140 in Encoding

Download history 4400/week @ 2023-12-23 8601/week @ 2023-12-30 12716/week @ 2024-01-06 13191/week @ 2024-01-13 15146/week @ 2024-01-20 17295/week @ 2024-01-27 16524/week @ 2024-02-03 15686/week @ 2024-02-10 19439/week @ 2024-02-17 19481/week @ 2024-02-24 22061/week @ 2024-03-02 22785/week @ 2024-03-09 23006/week @ 2024-03-16 17848/week @ 2024-03-23 19040/week @ 2024-03-30 17957/week @ 2024-04-06

82,252 downloads per month
Used in 68 crates (31 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.19" # Note this is a different library than capnp*c*

[build-dependencies]
capnpc = "0.19"

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