Do not pass `--Clink-arg=-l` for libstd and libtest (#1500)

Fixes #1374

We skip adding `-Clink-arg=-l...` for libstd and libtest from the standard library, as these two libraries are present both as an `.rlib` and a `.so` format. On linux, Rustc adds a -Bdynamic to the linker command line before the libraries specified with `-Clink-arg`, which leads to us linking against the `.so`s but not putting the corresponding value to the runtime library search paths, which results in a "cannot open shared object file: No such file or directory" error at exectuion time. We can fix this by adding a `-Clink-arg=-Bstatic` on linux, but we don't have that option for macos. The proper solution for this issue would be to remove `libtest-{hash}.so` and `libstd-{hash}.so` from the toolchain. However, it is not enough to change the toolchain's `rust_std_{...}` filegroups here: https://github.com/bazelbuild/rules_rust/blob/a9d5d894ad801002d007b858efd154e503796b9f/rust/private/repository_utils.bzl#L144 because rustc manages to escape the sandbox and still finds them at linking time. We need to modify the repository rules to erase those files completely. This PR should be a good workaround until we get do to the proper thing though.

This PR also fixes the following issues for Windows:
* get_lib_name() didn't work properly on windows for `libc`
* `-Clink-arg` should point to the library name with extension included for windows.
9 files changed
tree: 7eb09e48ca27cbfd5cc5e0a62ca0bc01a9281ea0
  1. .bazelci/
  2. .github/
  3. bindgen/
  4. cargo/
  5. crate_universe/
  6. distro/
  7. docs/
  8. examples/
  9. proto/
  10. rust/
  11. test/
  12. tools/
  13. util/
  14. wasm_bindgen/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .gitignore
  19. ARCHITECTURE.md
  20. AUTHORS
  21. BUILD.bazel
  22. CODEOWNERS
  23. COMPATIBILITY.md
  24. CONTRIBUTING.md
  25. CONTRIBUTORS
  26. LICENSE.txt
  27. README.md
  28. version.bzl
  29. WORKSPACE.bazel
  30. workspace.bzl
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.