[nullability] A call to a non-const operator should also be considered mutating. The additional test in this patch fails without the fix. PiperOrigin-RevId: 608879021 Change-Id: I295a03fefbf4c5041e693daa211f524138e33479
NOTE: Crubit currently expects deep integration with the build system, and is difficult to deploy to environments dissimilar to Google's monorepo. We do not have our tooling set up to accept external contributions at this time.
Crubit is a bidirectional bindings generator for C++ and Rust, with the goal of integrating the C++ and Rust ecosystems. With Crubit, Rust can be used anywhere C++ can be, directly calling and being called by C++. Crubit does not require wrapping C++ or Rust libraries in “FFI-friendly”, simplified APIs. Any C++ interface can be called or implemented by Rust code.
Current status: Crubit is aiming for an initial stable “MVP” version, comparable to bindgen and cbindgen. This will support basic datatypes like integers and pointers, (rust-movable) structs/unions/enums, and extern "C" functions.
Consider the following C++ function:
extern "C" bool IsAbsPath(std::string_view path);
This function, if present in a header file which is processed by Crubit, becomes callable from Rust as if it were defined as:
pub fn IsAbsPath(path: std::string_view) -> bool {...}
There are some temporary restrictions on the API shape. For example, if path were a std::string, or a non-extern "C" function, it would not be callable from Rust directly via Crubit. (For example, std::string is not rust-movable.) These restrictions will be relaxed over time.
For actual copy-pastable examples on getting started with Crubit, see the examples/ subdirectory. examples/cpp includes code which actually calls C++ via Crubit, and a snapshot of what the generated interface looks like.
$ apt install clang lld bazel $ git clone git@github.com:google/crubit.git $ cd crubit $ bazel build --linkopt=-fuse-ld=/usr/bin/ld.lld //rs_bindings_from_cc:rs_bindings_from_cc_impl
$ git clone https://github.com/llvm/llvm-project $ cd llvm-project $ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install $ cmake --build build -j $ # wait... $ cmake --install build $ cd ../crubit $ LLVM_INSTALL_PATH=../llvm-project/install bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl