autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

Support rust::* types in C++ headers

Open adetaylor opened this issue 4 years ago • 3 comments

If we find a rust::* type in a C++ header per this list, include that in our generated cxx bindings.

In theory this is just a matter of contributing such types to known_types.rs. In practice it won't be that simple...

First step would be to add some tests to integration_tests.rs.

adetaylor avatar Jan 20 '21 22:01 adetaylor

We already support rust::Str and rust::String but still need a fair bit of work to support rust::Box, rust::Slice and opaque Rust types.

adetaylor avatar Feb 06 '21 19:02 adetaylor

I'm not sure if this problem applies here. But how do we actually introduce "rust/cxx.h" in the CPP code? I'm having a cxx binding but since it is not full now, I'd like to migrate to autocxx. But the thing is, once I do like in the example, the "rust/cxx.h" thing is complaining.

Escapingbug avatar Jun 23 '21 02:06 Escapingbug

Thanks for getting in touch.

Can you be precise about the error message you're getting?

My guess is that you're not setting the C++ build include path to include the location of cxx.h. If you're using cargo and copying the autocxx demo example, then the build is done by the cc crate and its include path is set in the build.rs. You will need to put cxx.h somewhere and then set up the include path appropriately to include that directory.

cxx.h is not distributed as part of autocxx, so you'll need to get that directly from the cxx crate.

This could be done automatically by autocxx-build. It could write out cxx.h to a temporary directory and then include this directory automatically in the include path which it passes to the cc crate. I'd be OK with that - feel free to raise a pull request! (Or whoever tackles this particular github issue in the future might want to consider that. Maybe it'll be me.)

Irrespective of that: based on the use-case you're describing, you might want to consider mixing automatic and manual bindings. This is possible using the approach described here. HTH!

adetaylor avatar Jun 23 '21 16:06 adetaylor