Problem
When cross-compiling for x86_64-pc-windows-gnu (MinGW) target from Linux, crates_repository
incorrectly selects windows_x86_64_msvc crate variants instead of windows_x86_64_gnu,
causing linking failures with .lib files.
Reproduction
- Register
x86_64-pc-windows-gnu in rust_register_toolchains(extra_target_triples=...)
- Create a rust_binary with
platform = "//platforms:windows-x86_64"
- Build with MinGW linker (
-C linker=x86_64-w64-mingw32-gcc)
Expected Behavior
Crates with platform-specific dependencies (like windows-sys) should resolve to
windows_x86_64_gnu variant when target_env = "gnu".
Actual Behavior
Links with MSVC libraries (.lib files), causing errors like:
x86_64-w64-mingw32-gcc: error: advapi32.lib: No such file or directory
Environment
- rules_rust: v0.48.0
- Bazel: 8.2.1
- Host: Linux x86_64 (WSL)
- Target: x86_64-pc-windows-gnu
Related Work
Workaround
Currently using Cargo directly for Windows builds.
Problem
When cross-compiling for
x86_64-pc-windows-gnu(MinGW) target from Linux,crates_repositoryincorrectly selects
windows_x86_64_msvccrate variants instead ofwindows_x86_64_gnu,causing linking failures with
.libfiles.Reproduction
x86_64-pc-windows-gnuinrust_register_toolchains(extra_target_triples=...)platform = "//platforms:windows-x86_64"-C linker=x86_64-w64-mingw32-gcc)Expected Behavior
Crates with platform-specific dependencies (like
windows-sys) should resolve towindows_x86_64_gnuvariant whentarget_env = "gnu".Actual Behavior
Links with MSVC libraries (
.libfiles), causing errors like:x86_64-w64-mingw32-gcc: error: advapi32.lib: No such file or directory
Environment
Related Work
cfg(target_env = "gnu")conditionsWorkaround
Currently using Cargo directly for Windows builds.