Update `rust_bindgen_library` to only link into the direct consumer (#2361)

Most uses of [bindgen](https://github.com/rust-lang/rust-bindgen) are
via [build
scripts](https://doc.rust-lang.org/cargo/reference/build-scripts.html)
which typically use either `-Lnative=` to specify linker paths for the
current target being built. The way the rules are currently defined, has
the bindgen library linked directly into the final library which leads
to some annoying ordering errors compared to the same project building
with Cargo. This PR aims to support the Cargo style of linking via a
`leak_symbols = False` flag, thus changing the dependency graph when
linking from:
```
cc_lib -> bindgen -> lib_a -> lib_b -> bin
    \__________________________________^
```
to:
```
cc_lib -> bindgen -> lib_a -> lib_b -> bin
```

Note that `leak_symbols` is intended to be used as an escape hatch to
restore the original behavior and will be deleted in the future.
13 files changed
tree: 1d1610c8b26385013b1e6e13c708cf31f6a65779
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. bindgen/
  5. cargo/
  6. crate_universe/
  7. docs/
  8. examples/
  9. ffi/
  10. nix/
  11. proto/
  12. rust/
  13. test/
  14. tools/
  15. util/
  16. wasm_bindgen/
  17. .bazelignore
  18. .bazelrc
  19. .clang-format
  20. .envrc
  21. .gitattributes
  22. .gitignore
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. ARCHITECTURE.md
  26. AUTHORS
  27. BUILD.bazel
  28. CODEOWNERS
  29. COMPATIBILITY.md
  30. CONTRIBUTING.md
  31. CONTRIBUTORS
  32. LICENSE.txt
  33. MODULE.bazel
  34. README.md
  35. version.bzl
  36. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.