Generating ergonomic C++ APIs using Rustdoc, procedural macros, and Serde
summary
Generates idiomatic C++ bindings by turning annotated Rust functions into low‑level extern "C" byte‑buffer stubs, using procedural macros to emit pointer-safe FFI and unwind-safe error handling, then parsing Rustdoc JSON plus rustdoc-types to discover APIs and running Serde/bincode for (de)serialization; produces generated C and C++ headers and high‑level wrappers. Framework shipped as Buffy and Buffy‑macro on crates.io, runs in production and customer deployments for over a year, trades modest serialization overhead for zero manual unsafe glue and safer cross‑language ergonomics, requires nightly rustdoc JSON pinning.
AI-written summary · about
chapters (13)
- 0:00Rust FFI journey
- 1:51Need for better FFI solutions
- 3:35Manual FFI problems
- 6:05Goals for ergonomic APIs
- 7:31Extern C with macros
- 11:27Rustdoc for code analysis
- 13:58Filtering functions and types
- 15:22C++ code from Rust types
- 16:51Simple C++ API example
- 18:14Async and cyclic types example
- 19:40Approach pros and cons
- 21:28Introducing Buffy macro
- 22:29Production readiness
related talks
28mGenerating ergonomic C++ APIs using Rustdoc, procedural macros, and Serde
25mRust and C++
29mMacromancy: an introduction to Rust macros
24mMacros for a More Productive Rust
53mC++/Rust Interop: A Practical Guide to Bridging the Gap Between C++ and Rust
31mFrom C++ APIs to Idiomatic Rust: Wrapper Design Patterns
31mRustly typed APIs; ... JSON RPC with Rust, Procedural macros and a DSL
31mUsing Rust from C... or Any Language
