Skip to content

Commit

Permalink
Install a previous version of MSVC build tools (#1968)
Browse files Browse the repository at this point in the history
Fixes #1967

There is no way to prevent installing the latest version, so we remove
it manually.
  • Loading branch information
meteorcloudy authored Jun 7, 2024
1 parent 9d79fb4 commit 68dea4f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion buildkite/setup-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,22 @@ Write-Host "Installing Visual C++ 2019 Build Tools..."

## Install Visual C++ 2022 Build Tools.
Write-Host "Installing Visual C++ 2022 Build Tools..."
$tool_version="14.39.17.9."
& choco install visualstudio2022buildtools
& choco install visualstudio2022-workload-vctools --params "--add Microsoft.VisualStudio.Component.VC.Tools.ARM --add Microsoft.VisualStudio.Component.VC.Tools.ARM64"
# & choco install visualstudio2022-workload-vctools --params "--add Microsoft.VisualStudio.Component.VC.Tools.ARM --add Microsoft.VisualStudio.Component.VC.Tools.ARM64"
& choco install visualstudio2022-workload-vctools --params "--add Microsoft.VisualStudio.Component.VC.${tool_version}x86.x64 --add Microsoft.VisualStudio.Component.VC.${tool_version}ARM --add Microsoft.VisualStudio.Component.VC.${tool_version}ARM64"

## Prevent mysteirous failure caused by newer version of MSVC (14.40.33810). See https://github.com/bazelbuild/bazel/issues/22656
## Remove directories under C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC that don't match the specified version.
$versionPrefix = "14.39" # The installed version doesn't match the version in the component name, so we need to use a substring match.
$msvcPath = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
$directories = Get-ChildItem -Path $msvcPath -Directory | Where-Object { $_.Name -notlike "$versionPrefix*" }
foreach ($directory in $directories) {
$directoryPath = Join-Path -Path $msvcPath -ChildPath $directory.Name
Write-Host "Deleting $directoryPath"
Remove-Item -Path $directoryPath -Recurse -Force
}

[Environment]::SetEnvironmentVariable("BAZEL_VC", "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC", "Machine")
$env:BAZEL_VC = [Environment]::GetEnvironmentVariable("BAZEL_VC", "Machine")

Expand Down

0 comments on commit 68dea4f

Please sign in to comment.