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

Cannot #include gen.rs.h reliably when building with cargo due to dynamic out location #213

Closed
stoically opened this issue May 31, 2020 · 1 comment · Fixed by #276
Closed
Labels
cargo Issues affecting Cargo-based use of cxx

Comments

@stoically
Copy link

stoically commented May 31, 2020

Thanks for cxx!

It seems that the location of the generated bridge files varies based on the method with which the crate is added as dependency. E.g. in the crate keytar I've used #include "src/lib.rs.h", which works fine while working directly in the crate, since the rs.h file ends up in TARGET_DIR/cxxbridge/src/lib.rs.h. When adding the crate as dependency (ends up in TARGET_DIR/cxxbridge/.cargo/..) or including it via path (ends up in nested paths depending on the local directory name), the out location changes in unpredictable ways, which makes it hard (impossible?) to reliably #include it.

My naive approach to fix this would be to always write the given include path as-is to the OUT_DIR and make it an requirement to include that (or automatically include it as part of cxx_build::bridge).

Maybe I'm missing something obvious and it is possible to reliably define #includes for cargo, in which case I'd appreciate pointers. Thanks!

@dtolnay
Copy link
Owner

dtolnay commented Sep 2, 2020

Fixed in 0.4.0 -- the import paths will now always be crate name + local path within crate, e.g. #include "my-crate/src/lib.rs.h" where my-crate is the crate name and "src/lib.rs" was the path passed to the cxx_build::bridge code generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cargo Issues affecting Cargo-based use of cxx
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants