If a header is in multiple targets, take it as part of the first target (lexicographically).

This is not Good Behavior. In particular, this means that adding a dependency can break Rust callers. Consider the following:

```cc
//h1.h
struct S {};
```

```cc
//h2.h
void Foo(S s);
```

with this BUILD file:

```py
cc_library(name="h1_a", hdrs=["h1.h"], ...)
cc_library(name="h1_b", hdrs=["h1.h"], ...)

cc_library(name="h2_a", hdrs=["h2.h"], deps=[":h1_a"])
cc_library(name="h2_b", hdrs=["h2.h"], deps=[":h1_b"])
cc_library(name="h2_ab", hdrs=["h2.h"], deps=[":h1_a", ":h1_b"])
```

Then:

* `h2_a` contains `fn Foo(s: h1_a::S);`
* `h2_b` contains `fn Foo(s: h2_a::S);`
* `h2_ab` contains `fn Foo(s: h1_a::S);`

Meaning that adding a single (TRANSITIVE) dependency can accidentally change the type of your parameters, breaking Rust callers -- a caller who was passing `h2_a::S` would get broken if a transitive dependency on `h1_a` were added.

But note: without this CL, we're even _worse_ off, because that same transitive dependency breaks the build entirely, and there is no way to resolve it. After this CL, there is a quick fix: use `h1_a::S`.

---

Alternatives considered:

* We could fix all headers everywhere to have a single canonical build target, but this is a big task. We do likely want to do it eventually, but it shouldn't block early adopters from trying Crubit.

---

It's worth noting that with the proposed[]

PiperOrigin-RevId: 501900537
7 files changed
tree: 97415940db443754473a1dc1abf739a993946a90
  1. .bazelci/
  2. bazel/
  3. cc_bindings_from_rs/
  4. cc_import/
  5. cc_template/
  6. common/
  7. docs/
  8. lifetime_analysis/
  9. lifetime_annotations/
  10. migrator/
  11. nullability_verification/
  12. rs_bindings_from_cc/
  13. .bazelrc
  14. .gitignore
  15. BUILD
  16. Cargo.Bazel.lock
  17. CODE_OF_CONDUCT
  18. CONTRIBUTING
  19. LICENSE
  20. README.md
  21. WORKSPACE
README.md

Crubit: C++/Rust Bidirectional Interop Tool

Build status

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.

Building Crubit

$ 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

Using a prebuilt LLVM tree

$ 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