2

I'm having difficulty working with the capnpc crate. I'm running Arch Linux and have installed capnp from the AUR and compiled capnpc-rust from the github project and put it in /usr/local/bin. I can manually compile the .capnp file easily with the command

capnp compile -orust --src-prefix=capnp capnp/message.capnp

I tried cloning the capnpc project and compiling the .capnp test file in the test directory and that didn't work either. I'm not getting any errors (whereas earlier I was getting "File not found") so it seems like capnpc is working, but I can't find files anywhere.

build.rs

extern crate capnpc;
fn main() {
    ::capnpc::compile("capnp", &["capnp/message.capnp"]).unwrap();
}

Cargo.toml

...
build = "build.rs"

[lib]
name = "rustp2p"
path = "src/lib.rs"

[build-dependencies]
capnpc = "*"

[dependencies]
capnp = "0.5.0"

Edit: .rs file builds out into /target/debug/build/.../out.

hamersaw
  • 55
  • 2
  • 5
  • Yes, your answer is correct. I noticed people were still answering when it is not needed. I'll remove the edit since it sounds like thats the stackoverflow way of doing things. Thanks for the help. – hamersaw Oct 29 '15 at 20:54
  • Ah, I see. I only provided a comment which doesn't count as an answer. In fact, I tend to delete most of my comments after they have been added to a question / answer, and I will do so for these soon ^_^. The *creator* of the Rust capnproto library answered your question, so it's perfectly acceptable for that to be the accepted answer ;-) – Shepmaster Oct 29 '15 at 21:01

1 Answers1

3

When you invoke capnpc::compile from a Cargo build script, the generated code goes in a subdirectory of target/ that can be found at main compile time through the OUT_DIR environment variable. This strategy is described in the Cargo documentation.

You shouldn't need to install the capnpc-rust binary in /usr/local/bin or anywhere else for this to work.

Your build.rs and Cargo.toml files look fine to me.

You might find it helpful to consult the addressbook example.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366