cbindgen
cbindgen copied to clipboard
Support exporting impls as C++ objects
We should be able to generate the required extern functions using a procedural macro like wasm-bindgen does.
Here's an example that's supported by wasm_bindgen.
#[wasm_bindgen]
pub struct Foo {
contents: u32,
}
#[wasm_bindgen]
impl Foo {
#[wasm_bindgen(constructor)]
pub fn new() -> Foo {
Foo { contents: 0 }
}
pub fn get_contents(&self) -> u32 {
self.contents
}
}
That's not the same though - wasm_bindgen macro generates wrappers for all that code, plus bindings on the JS side, whereas cbindgen tries to generate bindings for existing Rust code w/o modifications.
Perhaps I wasn't clear. The intent here is to have a cbindgen proc macro that generates wrappers for this code and then have those wrappers exposed through a generated header. So in this case there would be modifications to the existing Rust code that would improve the ergonomics of generating bindings.
Here's my current work in progress on this: https://github.com/jrmuizel/cbindgen-macro
https://github.com/getditto/safer_ffi is a similar idea.
See also https://crates.io/crates/cxx