Resources
Tooling
Bindgen is the most popular and mature tool and is maintained by the Rust project. It is used to create bindings for C code (and some C++) in Rust code. Cbindgen can be used to create C bindings to Rust code. The other tools below are for C++ interop; cxx is the current favourite tool with the community, but is not suitable for all use cases.
- bindgen
- cbindgen
- cxx, repo
- autocxx (Google tool for 'integrating cxx with bindgen')
- diplomat
- rust-cpp (
cpp!
macro) - flapigen (formerly Swig)
- cxx-async
- ABI Cafe for comparing the output of compilers for ABI compatibility
- crubit experimental C++ interop from Chrome folk
You may want to use COM/WinRT for inter-language interaction, the best Rust support for COM and WinRT is in windows-rs.
Documentation
- Nomicon chapter
- Unofficial FFI guide
- FFI omnibus
- Firefox docs for C++ interop
- FFI idioms and patterns
- Chrome docs for C++ interop
- FFI chapter in ANSSI-FR Secure Rust Guidelines
Unsafe programming
Resources for learning about unsafe programming:
- Chapter in The Book.
- Nomicon
- Unsafe code guidelines
- Ralf's thesis
- Stacked borrows paper
- GhostCell paper
- Ralf's blog
- Gankra's thesis
- Gankra's blog
- MIRI repo