blob: ac20e7af186870bb101c2d44e66541d48c91d4cd [file] [log] [blame] [view]
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00001# Crubit: C++/Rust Bidirectional Interop Tool
2
Marcel Hlopkod3916612022-06-03 02:25:50 -07003[![Build status](https://badge.buildkite.com/7a57a14e68aa3a0ab70972cbf2a35fd79d342ba152fee4a5b4.svg)](https://buildkite.com/bazel/crubit)
4
Devin Jeanpierre8bc1cd02023-11-30 00:55:38 -08005Crubit is a bidirectional bindings generator for C++ and Rust.
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00006
Marcel Hlopkoac46bf92022-03-25 15:27:22 +00007Please don't use, this is an experiment and we don't yet know where will it take
Devin Jeanpierred7add542023-04-03 14:40:23 -07008us. There will be breaking changes without warning. Unfortunately, we can't
9take contributions at this point.
10
Jing Ludd2ed2e2023-07-14 06:47:10 -070011Crubit allows for C++ code and Rust code to call each other without manually
12wrapping the APIs in an FFI-friendly interop layer. For example, a C++ function
13like this:
Devin Jeanpierred7add542023-04-03 14:40:23 -070014
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```