Abstract
DESCRIPTION:
This talk introduces a novel approach to generate C++ APIs from an existing Rust API by using procedural macros, Rustdoc, and Serde. Functions and impl blocks which should be exposed in the C++ API are annotated with a procedural macro attribute. This macro generates low level extern "C" functions for the corresponding function definitions. Arguments and return values of these functions are passed as byte buffers in this case. Ultimately, Rustdoc's unstable JSON format is used to generate a set of low level bindings for the generated extern "C" functions and, on top of that, a set of ergonomic high level C++ bindings. An intermediate layer handles all the required (de-)serializing of the argument/return type byte buffers to acquire the corresponding native representations.
ADDITIONAL NOTES:
This talk demonstrates how you can generate a "nice to work with" C++ API based on a given Rust API. The proposed workflow is based on procedural macros to generate extern "C" functions, Serde for converting data into the right representation on each side of the FFI interface, and the unstable Rustdoc JSON format to collect and generate the necessary headers for the C++ side. The talk is based on a framework we have developed internally and have been using in production for over a year now. It will start with showing how we handled FFI generation in the past before moving to our new framework. After that it will show in detail how the new framework works internally and which improvements it has over other solutions. Overall our new framework allows for more ergonomic API surfaces on both sides of the FFI interface at the cost of some performance overhead for serialization/deserialization.
There will also be a comparison with existing tools like cbindgen and cxx.