Derive `dlltool` path from the linker for Windows-GNU builds (#4206)

`rustc` on Windows-GNU shells out to `dlltool` to synthesize import
libraries: for `#[link(... kind = "raw-dylib")]` declarations in any
crate (`windows-sys` 0.61+ is the common case), and for the `*.dll.a`
companion that `cdylib` crates emit alongside their `.dll`.

`cc_toolchain` has no action/tool slot for `dlltool`, since `gcc` used
as a linker runs it internally, but `rustc` drives the linker directly
and so needs an explicit `--codegen dlltool=` pointer, which previously
had to be supplied by hand via `extra_rustc_flags` on every target.

Every MinGW toolchain, whether a native Windows distribution (winlibs,
MSYS2 mingw64, llvm-mingw) or a Unix cross toolchain, ships `dlltool`
right next to the linker with the same naming convention (`.exe`/`.EXE`
suffix or none), so derive its path from the `cc_toolchain`'s own linker
tool path instead.

A user-supplied `-Cdlltool=` via `extra_rustc_flags` still wins, since
`rustc` honors the last `-C<key>=` for a given key.

This adds no new `constraint_value` nor `config_setting` and does not
affect toolchain auto-registration or resolution: `target_abi` is
already parsed from the target triple on the resolved `rust_toolchain`,
the same field `portable_link_flags` and `symlink_for_ambiguous_lib` key
off of a few lines below.

Assisted-by: Claude
2 files changed
tree: abfc5bbb084032c332e046819624de2a530b318d
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. extensions/
  9. ffi/
  10. nix/
  11. rust/
  12. test/
  13. tools/
  14. util/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .clippy.toml
  19. .envrc
  20. .gitattributes
  21. .gitignore
  22. .pre-commit-config.yaml
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. .typos.toml
  26. ARCHITECTURE.md
  27. AUTHORS
  28. BUILD.bazel
  29. CODEOWNERS
  30. COMPATIBILITY.md
  31. CONTRIBUTING.md
  32. CONTRIBUTORS
  33. LICENSE.txt
  34. MODULE.bazel
  35. README.md
  36. version.bzl
  37. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Starter repo

The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.

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.