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 inner bridge mod #119

Closed
dtolnay opened this issue Apr 16, 2020 · 4 comments · Fixed by #197
Closed

Support inner bridge mod #119

dtolnay opened this issue Apr 16, 2020 · 4 comments · Fixed by #197

Comments

@dtolnay
Copy link
Owner

dtolnay commented Apr 16, 2020

Currently we only find the #[cxx::bridge] invocation if it is at the top level of the Rust file passed as argument to the code generator. If it isn't at the top level, we fail with an error that looks like:

cxxbridge: no #[cxx::bridge] module found

It would be good to also look for it inside of nested modules:

// lib.rs

pub fn ...

#[doc(hidden)]
mod details {
    #[cxx::bridge]
    mod ffi {
        ...
        ...
    }

    pub fn ...
}
@regexident
Copy link

I might be misinterpreting this issue, but whenever I put the #[cxx::bridge] anywhere but the crate root I still get

cxxbridge: no #[cxx::bridge] module found

Reproduce

  1. Open project cxx/demo
  2. Add pub mod bridge; to main.rs, along with corresponding file src/bridge.rs
  3. Move #[cxx::bridge(namespace = "org::blobstore")] mod ffi { … } from main.rs to bridge.rs
  4. Mark mod ffi as pub mod ffi.
  5. cargo build

Module structure

crate demo
└── pub mod bridge
    │   #[cxx::bridge(…)]
    └── pub mod ffi

Error

❯ cargo build
   Compiling demo v0.0.0 (/cxx/demo)
error: failed to run custom build command for `demo v0.0.0 (/cxx/demo)`

Caused by:
  process didn't exit successfully: `/cxx/target/debug/build/demo-02f344be574bf590/build-script-build` (exit code: 1)
  --- stdout
  cargo:CXXBRIDGE_PREFIX=demo
  cargo:CXXBRIDGE_DIR0=/.../cxx/target/debug/build/demo-9b77e4bc641295bf/out/cxxbridge/include
  cargo:CXXBRIDGE_DIR1=/.../cxx/target/debug/build/demo-9b77e4bc641295bf/out/cxxbridge/crate

  --- stderr
  cxxbridge: no #[cxx::bridge] module found

@dtolnay
Copy link
Owner Author

dtolnay commented Nov 25, 2020

Probably your cxx_build::bridge call in build.rs is pointed to the wrong file.

@regexident
Copy link

regexident commented Nov 25, 2020

Oh, so it needs to be within the file passed to cxx_build::bridge?
My understanding was that with #508 it now could be in any sub-module of the root module.

Makes sense. So the correct call would be cxx_build::bridge("src/bridge.rs") then.
Works. 👍

@dtolnay
Copy link
Owner Author

dtolnay commented Nov 25, 2020

It can be within any submodule in the given file -- like in the comment at the top of this issue the bridge is the submodule self::details::ffi inside lib.rs.

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

Successfully merging a pull request may close this issue.

2 participants