src/exercises/chromium/interoperability-with-cpp.md
#[cxx::bridge] which
specifies a single function, to be called from C++, called hello_from_rust,
taking no parameters and returning no value.hello_from_rust function to remove extern "C" and
#[unsafe(no_mangle)]. This is now just a standard Rust function.gn target to build these bindings.hello_from_rust.
Instead, include the generated header file.It's a good idea to play with CXX a little. It helps you think about how flexible Rust in Chromium actually is.
Some things to try:
include! from your cxx::bridge.
You'll need to declare your C++ function in that new header file.unsafe block to call such a function, or alternatively specify the
unsafe keyword in your #[cxx::bridge] as described here.#include "third_party/rust/cxx/v1/crate/include/cxx.h"#[cxx::bridge], and get used to the errors you see.#[cxx::bridge], and get used to the errors you see.std::unique_ptr of some type from C++ into Rust, so that Rust can own
some C++ object.Box).Now you understand the strengths and limitations of CXX interop, think of a couple of use-cases for Rust in Chromium where the interface would be sufficiently simple. Sketch how you might define that interface.
Some of the questions you may encounter:
cxx::bridge.