autocxx
autocxx copied to clipboard
autorust: generate cxx bindings for C++ -> Rust calls
The purpose of autocxx is to skip the need to describe the C++/Rust interface in the cxx IDL.
At the moment, this works for existing C++ APIs.
The concept could be extended to existing Rust APIs, by adding some sort of attribute macro e.g.
#[autocxx::gen]
struct RustStruct {
a: u32,
}
#[autocxx::gen]
pub fn doSomething(s: RustStruct) {
...
}
These too could contribute to the #[cxx::bridge] mod we generate, but functions would go into an extern "Rust" section rather than the current extern "C++" section.
We already have most of the pipeline here:
- We parse the Rust file in a codegen tool using syn
- That tool already generated a
#[cxx::bridge]mod - We have macros which effectively replace the real Rust declarations with something else derived from that codegen tool.
This would be a significant direction change/enhancement for autocxx, so this isn't going to happen any time soon. Recording the idea for the record!
Does this mean that there's no way to populate the ffi module with extern "Rust" section? Or is there a workaround to do it at the moment?
Sorry for missing your question!
That's right, there is no way to do that automatically; however you can do this.
No worries! Our C++ codebase is a bit too complex for autocxx so unfortunately we can't use it yet, but that's a great tip to have in mind!