commit | c0222bdc14a26326c15f40a8124ce5ea20ae89cc | [log] [tgz] |
---|---|---|
author | Googler <no-reply@google.com> | Wed Feb 07 07:16:43 2024 -0800 |
committer | Copybara-Service <copybara-worker@google.com> | Wed Feb 07 07:17:53 2024 -0800 |
tree | 2980d78ba67298e1f04fe662e67453271fbb41cd | |
parent | 612a215275d952767a5435d21052953547aeee50 [diff] |
Automatic code cleanup. PiperOrigin-RevId: 604974188 Change-Id: I8e5c1f4ea53443287012ff597ebc065b1100f48b
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