Description
Problem
When building Rust projects on Windows 10 arm64, rustc cannot find MSVC installation to use tools like link.exe.
The reason is because Visual Studio Installer doesn't properly register the installation on arm64.
To determine MSVC installation, rustc uses the great cc-rs crate which itself uses the SetupConfiguration COM component (Microsoft.VisualStudio.Setup.Configuration.Native.dll) to determine the path of Visual Studio (or Visual C++ Build Tools) installation. On Windows 10 arm64, it fails to create an instance of a COM class.
Steps
- Install
aarch64-pc-windows-msvc
toolchain on a Windows 10 arm64 machine - Open cmd.exe and navigate to a Rust project
- Run
cargo build
Possible Solution(s)
The issue happens because on arm64 VS Installer doesn't register the COM component. To be more precise, it registers the x86 version of the COM component, but there is no arm64 version. Unfortunately Microsoft is not willing to fix the issue, even though it was reported twice, with the reason being that Visual Studio doesn't support running on arm64.
A (rather easy) workaround to the issue is to always run cargo/rustc within the x86_arm64 Developer Console. To do this, the user has to call vcvarsx86_arm64.bat
before doing anything else in the console. This way, cc-rs can determine Visual Studio installation from the environment variables.
For rustc itself, a solution could be to first attempt searching in the known VS Installer path (%ProgramFiles(x86)%\Microsoft Visual Studio\Installer
) for vswhere.exe
on arm64 Windows and, if found, running it to get information about the installed VS instances.
Another option could be spawning a dedicated x86-emulated process that would be able to use the x86 COM component and give the information back to rustc, though this option seems to be an overkill 😅
Meta
rustc --version --verbose
:
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: aarch64-pc-windows-msvc
release: 1.50.0
Environment:
- Windows 10 arm64 (20H2)
aarch64-pc-windows-msvc
toolchain