This is a classic FFI problem, and the solution is to use a โwatch glassโ: Language A <=> Common ABI <=> Language B.
Of course, bindgen could be developed so that it can accurately reproduce C ++ ABI, but in practice this would require a complete C ++ compiler, which would probably be too large.
Using the hour-glass project, each language with a complex ABI uses its own specialized toolchain to convert to a specific known ABI. In this case, it will be C ++ <=> C <=> Rust.
A possible solution is to create a C wrapper library around the C ++ API, and then use bindgen. This is what LLVM and Clang do.
This is the simplest solution, and the Octavo project may well be ready to integrate such an octavo-c facade into a tree (which is always better to guarantee its relevance).
Another solution would be to create a C ++ - compatible library for bindgen, which will take care of providing C-ABI for common C ++ types (e.g. std::string ). This would be more difficult, especially since:
- C has no generics, so C ++ templates should either be out of scope, or pre-created templates should be wrapped one at a time,
- C does not know how to call move or copy constructors, so if C ++ types are not PODs, they need to be manipulated with opaque pointers,
- C doesn't know ...
source share