rustc: correctly handle alwayslink staticlibs (#606)

* test: add test that demonstrates missing alwayslink libraries

* refactor: inline get_libs_for_static_executable into rustc logic

We then move the function to its only remaining caller in bindgen. I
didn't inline it there because it's used in a few different ways and
cleaning it up felt like more work than it was immediately worth.

* refactor: make DepInfo carry around LibraryToLink and not File data

We need this information to implement support for alwayslink, and it
cascaded around the codebase more than a little. The next change will
implement always link, which is currently left as a stub so that this
change has no functional changes.

* rustc: remove awkward file-ending check for _is_dylib

Instead we just verify we're not going to link anything static. This
removes the need for a toolchain in _is_dylib, which will allow
further cleanups in a moment.

* rustc: remove unused toolchain= argument to _make_link_flags

This allows us to use a more efficient construction to add linker
arguments to the command line.

* rustc: add support for alwayslink library dependencies

This follows up on the previous commit's refactoring and actually adds
alwayslink support.

Fixes #325.

* tests: add coverage for a cdylib with alwayslink

Makes sure that cdylibs also correctly pick up their alwayslink
dependencies.

* rustc: tote around LinkerInput for noncrate deps

This lets us avoid reifying a depset a little longer, which is nice.

Co-authored-by: Augie Fackler <augie@google.com>
6 files changed
tree: 109ea56191f44c8bf712a46d8bf2f5acab3c0f19
  1. .bazelci/
  2. bindgen/
  3. cargo/
  4. docs/
  5. examples/
  6. proto/
  7. rust/
  8. test/
  9. tools/
  10. util/
  11. wasm_bindgen/
  12. .bazelignore
  13. .gitignore
  14. ARCHITECTURE.md
  15. AUTHORS
  16. BUILD
  17. CODEOWNERS
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. LICENSE.txt
  21. README.md
  22. WORKSPACE
  23. workspace.bzl
README.md

Rust Rules

  • Postsubmit Build status
  • Postsubmit + Current Bazel Incompatible Flags Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

Please refer to the full documentation.