Generating ergonomic C++ APIs using Rustdoc, procedural macros, and Serde - Björn Wieczoreck
Автор: RustLab Conference
Загружено: 2024-12-13
Просмотров: 158
🔔 FOLLOW RUSTLAB CHANNEL 🔔
ABSTRACT:
How to integrate your new shiny Rust code into an existing codebase is a common problem. For this you might need to provide an API so that your Rust code can be accessed from the non-Rust side, for example from a C++ codebase. Rust only provides tools out of the box to define a low level C API, and even that can be troublesome. In this talk we want to demonstrate how you can use procedural macros, Rustdoc's unstable JSON format, and Serde to generate an idiomatic and ergonomic C++ API based on your existing Rust API.
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.
This channel is dedicated to the videos of the RustLab conference.
⚙️ Follow us on TWITTER:
/ rustlab_conf
⚙️ Follow us on FACEBOOK:
/ rustlabconference
RustLab is the first Italian international conference on the Rust programming language, organized by Develer.
Develer is not just an Italian company projecting and releasing hardware and software solutions for the industrial environment, but is also an ensemble of people sharing their great passion for new technologies and how they can be applied to your everyday life.
⚙️ Follow DEVELER on INSTAGRAM:
/ wearedeveler
⚙️ Follow DEVELER on FACEBOOK:
/ we.are.develer
⚙️ Follow DEVELER on TWITTER:
/ develer
⚙️ Follow DEVELER on LINKEDIN:
/ 114426
⚙️ Follow DEVELER on TELEGRAM: https://t.me/wearedeveler
⚙️ Follow DEVELER on TIK TOK:
/ wearedeveler
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: