Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for namespaced module generation #173

Closed
samuela opened this issue Apr 29, 2020 · 7 comments
Closed

Support for namespaced module generation #173

samuela opened this issue Apr 29, 2020 · 7 comments

Comments

@samuela
Copy link

samuela commented Apr 29, 2020

Right now if you try to include a generated rust capnp module outside the root module, you run into some problems:

 // In src/newworld/mod.rs
pub mod filetree_capnp {
  include!(concat!(env!("OUT_DIR"), "/src/newworld/filetree_capnp.rs"));
}
// In build.rs
fn main() {
  ::capnpc::CompilerCommand::new()
    .file("src/newworld/filetree.capnp")
    .run()
    .unwrap();
}

We get a bunch of errors like:

error[E0433]: failed to resolve: unresolved import
 --> /opt/nuvemfs/cli/cargo-target-dir/debug/build/nuvemfs-cli-c1dfeda28eaf92b2/out/src/newworld/filetree_capnp.rs:9:67
  |
9 |   pub type HeartbeatParams<> = ::capnp::capability::Params<crate::filetree_capnp::peer::heartbeat_params::Owned>;
  |                                                                   ^^^^^^^^^^^^^^
  |                                                                   |
  |                                                                   unresolved import
  |                                                                   help: a similar path exists: `crate::newworld::filetree_capnp`
@dwrensha
Copy link
Member

Hi! Did you try using the Rust.parentModule annotation? It was added just a few days ago. See #16.

@samuela
Copy link
Author

samuela commented Apr 29, 2020

I tried following along with the example, so now I have

@0xa850d6aba0560467;

using Rust = import "rust.capnp";
$Rust.parentModule("newworld");

interface Peer {
  heartbeat @0 ();
}

but I'm getting a capnp compilation error:

src/newworld/filetree.capnp:3:21-33: error: Import failed: rust.capnp
src/newworld/filetree.capnp:4:2-6: error: Not defined: Rust

@dwrensha
Copy link
Member

You'll need to have rust.capnp in the include path somehow. I recommend just copying it over to wherever the rest of your schema files are.

@samuela
Copy link
Author

samuela commented Apr 29, 2020

Hmm, I see... Is there any way that capnpc::CompilerCommand could inject rust.capnp into the include path at build time?

@dwrensha
Copy link
Member

I think the ideal solution would involve something like this: rust-lang/cargo#3544

Another thing we might try is to get rust.capnp included alongside c++.capnp in the binary packaging of the capnp tool.

If we're really ambitious, we could rewrite the capnp tool in Rust and inject rust.capnp there, but that would be a lot of work.

Aside from those approaches, I think the best we can do for now is to copy rust.capnp into a temporary directory and to pass that directory as a -I parameter to the capnp tool. I'm a bit reluctant to do that, though, as it seems hacky.

@samuela
Copy link
Author

samuela commented Apr 29, 2020

Aside from those approaches, I think the best we can do for now is to copy rust.capnp into a temporary directory and to pass that directory as a -I parameter to the capnp tool. I'm a bit reluctant to do that, though, as it seems hacky.

Yeah it does seem a bit hacky... It's not ideal but I'm ok with having things at the root of my project for now, so I think I'll revisit this once it get too unwieldy.

@dwrensha
Copy link
Member

dwrensha commented May 3, 2020

Closing, because parentModule addresses this issue. If you have other, more specific problems, please open new issues for them.

I've added a few doc comments: 998510c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants