commit | 65fb4dda55d467fe08ec1b93f7e26c86d1195994 | [log] [tgz] |
---|---|---|
author | Devin Jeanpierre <jeanpierreda@google.com> | Mon Feb 05 04:32:24 2024 -0800 |
committer | Copybara-Service <copybara-worker@google.com> | Mon Feb 05 04:33:15 2024 -0800 |
tree | 05ca19098ade27fe3e71a876de838f3d8c40dc91 | |
parent | 51d7601a1e86bc086fa63f02b86ea3160b52fe20 [diff] |
Mark OOP support code as experimental. PiperOrigin-RevId: 604278765 Change-Id: I4c8751933091a01778b399fa290a297f8a0db372
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