cxx
cxx copied to clipboard
Support declarative macros generating bridge modules
I dug around but didn't see an issue about this open already. It's not currently possible (AFAIK) to use declarative macros to generate whole cxx::bridge modules. The proc-macro side will work as expected, but the C++ codegen is parsing the unexpanded source and so it misses those modules.
This is different from #274 in that I'm not looking to somehow do macro expansion inside a bridge, which is understandably not possible today. I'm not sure whether there are any better answers here, however.
A similar workaround as was suggested in #274 can be used - i.e. generate the source beforehand, either in build.rs or a previous build step, depending on build system - but that is decidedly less user friendly, so if there are any other promising approaches here I'd like to explore them. The only approaches I can personally think of are (to put it mildly) hacky, e.g. have the proc-macro write the input TokenStream out somewhere so that cxxbridge can also operate on that, perhaps on an opt-in basis. Any other ideas?
autocxx needs to do something similar. David kindly exposed a codegen interface via https://crates.io/crates/cxx-gen/0.7.51, which other macros can choose to use to achieve the cxx C++ side codegen.
Hrm, I suppose I could use that to implement my own proc-macro with the hacky “generate other files in a proc-macro” approach above. Is autocxx doing something like that today?
Any update on this issue? @sbrocket, were you able to find a work-around?