blob: 72addca3d00ef3faa34032be498cd727e7a89394 [file] [log] [blame] [view]
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00001# Crubit: C++/Rust Bidirectional Interop Tool
2
Devin Jeanpierred7add542023-04-03 14:40:23 -07003
Marcel Hlopkod3916612022-06-03 02:25:50 -07004[![Build status](https://badge.buildkite.com/7a57a14e68aa3a0ab70972cbf2a35fd79d342ba152fee4a5b4.svg)](https://buildkite.com/bazel/crubit)
5
Devin Jeanpierred7add542023-04-03 14:40:23 -07006Crubit is an experimental bidirectional bindings generator for C++ and Rust.
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00007
Marcel Hlopkoac46bf92022-03-25 15:27:22 +00008Please don't use, this is an experiment and we don't yet know where will it take
Devin Jeanpierred7add542023-04-03 14:40:23 -07009us. There will be breaking changes without warning. Unfortunately, we can't
10take contributions at this point.
11
12Crubit allows for C++ code and Rust code to call each other without manually wrapping the APIs in an FFI-friendly interop layer. For example, a C++ function like
13this:
14
15```c++
16bool IsAbsPath(std::string_view path);
17```
18
19... becomes callable from Rust as if it were defined as:
20
21```rs
22pub fn IsAbsPath(path: std::string_view) -> bool {...}
23```
24
25Crubit automatically generates ABI-compatible bindings for structs (which can be
26passed both by value and by reference), functions, and methods, for a large
27variety of types. (Trivial types, nontrivial types, templated types, etc.)
Dmitri Gribenko184a80a2022-05-23 14:55:43 -070028
29## Building Crubit
30
31```
32$ apt install clang lld bazel
33$ git clone git@github.com:google/crubit.git
34$ cd crubit
35$ bazel build --linkopt=-fuse-ld=/usr/bin/ld.lld //rs_bindings_from_cc:rs_bindings_from_cc_impl
Matthew Riley03a01e32022-05-24 10:16:04 -070036```
37
38### Using a prebuilt LLVM tree
39
40```
41$ git clone https://github.com/llvm/llvm-project
42$ cd llvm-project
Lukasz Anforowicz4c772642022-05-30 11:11:02 -070043$ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install
Matthew Riley03a01e32022-05-24 10:16:04 -070044$ cmake --build build -j
45$ # wait...
Lukasz Anforowicz4c772642022-05-30 11:11:02 -070046$ cmake --install build
Matthew Riley03a01e32022-05-24 10:16:04 -070047$ cd ../crubit
Lukasz Anforowicz4c772642022-05-30 11:11:02 -070048$ LLVM_INSTALL_PATH=../llvm-project/install bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl
49```