capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

Please improve getting started instructions -- `include!`

Open xpe opened this issue 6 years ago • 2 comments

The current getting started text from https://crates.io/crates/capnp-rpc would benefit from additional clarity in the following section...

and you can include the generated code in your project like this:

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

My questions are:

  • Where exactly does mod foo_capnp belong?
  • How is the path for "foo_capnp.rs" generated? I'm digging around looking for it in my 'target' directory.

xpe avatar Sep 13 '19 01:09 xpe

Ok, I see that:

  1. the include! code belongs in the top-level "lib.rs"
  2. the outputted Rust files have the same path used to read the .capnp files (except they are under "target/.../.../out" instead)

So, if "build.rs" includes:

fn main() {
    ::capnpc::CompilerCommand::new().file("src/capnp/foo.capnp").run().unwrap();
}

then "lib.rs" should contain:

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

I think the README would benefit by having these details. Would anyone else agree?

xpe avatar Sep 13 '19 01:09 xpe

There's some documentation about this here: https://github.com/capnproto/capnproto-rust/blob/96f2f7894fbbf55e741c39b183a824e27ddbcc3e/capnpc/src/lib.rs

I agree that more/better documentation would be good. Perhaps the best place to discuss how to include!() would be here: https://github.com/capnproto/capnproto-rust/blob/96f2f7894fbbf55e741c39b183a824e27ddbcc3e/capnp/src/lib.rs

as then it would be at the top of the first page that people see when clicking on the documentation link in the readme: https://docs.capnproto-rust.org/capnp/

dwrensha avatar Sep 14 '19 00:09 dwrensha