This document tries to provide guidance for C++/Rust FFI. CLs to improve this guidance are welcomed.
Chromium recommends using the cxx
crate for C++/Rust FFI. For introductory guidance, please see the cxx
chapter in the Chromium day of the Comprehensive Rust course.
Chromium also supports the following tools:
bindgen
- see //build/rust/rust_bindgen.gni
for usage instructions.At this point Chromium's //build/rust/*.gni
templates do not support other FFI tools like:
cxx
guidancenamespace
. For example: #[cxx::bridge(namespace = "some_cpp_namespace")]
.#[cxx::bridge]
declaration. cxx
supports reusing types across multiple bridge
s, but there are some rough edges.TODO: Provide some examples or suggestions on how to structure FFI bindings (even if these suggestions wouldn't necessarily rise to the level of “best practices”).