commit | 34e070dd979bc7b9c1130c6dabf15df5a8f90864 | [log] [tgz] |
---|---|---|
author | Jing Lu <lujin@google.com> | Wed Nov 08 02:47:10 2023 -0800 |
committer | Copybara-Service <copybara-worker@google.com> | Wed Nov 08 02:47:43 2023 -0800 |
tree | 80c4ccdb6154f4843de0f1e278f18e8d34736fe4 | |
parent | 49c898c642c96b8e1b07c8a85df355583450f876 [diff] |
rs_bindings_from_cc: Add a reproducer that a forward declaration in a different target precludes bindings of actual definition. PiperOrigin-RevId: 580463296 Change-Id: Id9ff93b5a8ca8b8d2407af18de0d7e1a9cbcc59b
Crubit is an experimental bidirectional bindings generator for C++ and Rust.
Please don‘t use, this is an experiment and we don’t yet know where will it take us. There will be breaking changes without warning. Unfortunately, we can't take contributions at this point.
Crubit 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 this:
bool IsAbsPath(std::string_view path);
... becomes callable from Rust as if it were defined as:
pub fn IsAbsPath(path: std::string_view) -> bool {...}
Crubit automatically generates ABI-compatible bindings for structs (which can be passed both by value and by reference), functions, and methods, for a large variety of types. (Trivial types, nontrivial types, templated types, etc.)
$ 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