tree: fb2e358772ef038034fcffacbd578aeaef3b98ec [search]
  1. build_performance.md
  2. cpp_api_from_rust.md
  3. README.md
  4. rust_api_from_cpp.md
docs/rust/crubit/README.md

Crubit in Chromium

Crubit is a C++/Rust interop tool. It has two parts:

  • cpp_api_from_rust.md describes how to enable C++ to call Rust. This direction of Crubit interop is fully supported in Chromium (but see the “Caveats” section below).
  • rust_api_from_cpp enables Rust to call C++. It is not yet officially supported in Chromium. Information about partial, experimental support can be found in rust_api_from_cpp.md.

Notes:

  • See //docs/rust/ffi.md for an overview of other Rust interop tools (e.g. cxx or bindgen). These tools remain fully supported (i.e. there is no deprecation schedule that would require actively migrating existing cxx::bridge code to Crubit).
  • Once both interop directions are supported we will consider recommending Crubit as the primary C++/Rust interop solution for Chromium.

Caveats

  • Some directories cannot use Crubit: The Android project's Soong/bp build system does not support Crubit at this point. Consequently, Crubit cannot be used in //base, //net, or other directories that Cronet depends on. This is tracked in https://crbug.com/535682335.

    • Note that it‘s fine to use Crubit in code that runs on Android (e.g. the QR code generator), so long as it doesn’t need to be compiled by the Android project.
  • 2nd-party project limitations: In principle, Crubit will work in projects like PDFium or V8 as well. However, such projects usually support non-Chromium clients or alternative toolchains that may lack Crubit support. In order to use Crubit in a 2nd-party project, that project must first:

    • Make a policy decision to only support clients that have Crubit available, and/or help their clients set up Crubit support.
    • Enable Crubit in their build system by providing //build_overrides/crubit.gni.

Other resources

Documentation

  • Generic, Chromium-agnostic documentation of Crubit can be found at https://crubit.rs. Note that some examples are Bazel-specific, but most of the documentation should still apply to Chromium.
  • Google-internal Crubit documentation can be found at go/crubit
    • This is mostly the same content as above, but is mentioned here because it includes a few extra things like document freshness and owner metadata.
  • TODO: Cover Crubit in Chromium/FFI chapter of Comprehensive Rust course

Chat rooms

Reporting bugs or feature requests