Support for casting/bridging across separate template instantiations.
This CL reworks how the `forward_declare.rs` crate supports casting
across forward declarations and complete definitions:
1. This CL introduces a new `TransmutabilityEquivalenceClass` trait
(which provides a single associated item - the `Name` type alias).
2. The `IncompleteTransmute<Target>` trait has been made private
and reimplemented on top of the `TransmutabilityEquivalenceClass`
trait:
A. Structs/unions with the same
`TransmutabilityEquivalenceClass::Name` can be safely transmuted
between each other.
B. Default `impl`s define separate equivalences classes for i)
shared/immutable references `&T`, and ii) exclusive/immutable
references `&mut T`, and iii) `Vec<&T>`.
The changes above are sufficient to support casting across separate
template instantiations (because Crubit already generates an appropriate
`!unsafe_define` macro call for template instantiations). This CL adds
an explicit test under `test/templates/bridging` as well as a bit of
test coverage under `test/templates/type_alias`.
For readability/reviewability the CL tries to minimize the amount of
changes (i.e. avoiding removing, renaming, or reordering items in
`forward_declare.rs`). A TODO has been left to follow-up with a
separate CL that will clean things up.
PiperOrigin-RevId: 458234228
Extremely experimental interop tooling 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.
$ 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