From d9d62e1c144254c3c12219a06f1197872f693a56 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Fri, 7 Jun 2024 14:12:42 +0200 Subject: [PATCH 1/3] Install a previous version of MSVC build tools There is no way to prevent installing the latest version, so we remove it manually. --- buildkite/setup-windows.ps1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/buildkite/setup-windows.ps1 b/buildkite/setup-windows.ps1 index c90ae33cef..6836a1b5d5 100755 --- a/buildkite/setup-windows.ps1 +++ b/buildkite/setup-windows.ps1 @@ -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..." +$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 + 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") From a8bf41b502063378ee95fd2abd2f77e2844fb06a Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Fri, 7 Jun 2024 14:55:38 +0200 Subject: [PATCH 2/3] fix --- buildkite/setup-windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildkite/setup-windows.ps1 b/buildkite/setup-windows.ps1 index 6836a1b5d5..fd75a0a2a8 100755 --- a/buildkite/setup-windows.ps1 +++ b/buildkite/setup-windows.ps1 @@ -140,7 +140,7 @@ Write-Host "Installing Visual C++ 2019 Build Tools..." ## Install Visual C++ 2022 Build Tools. Write-Host "Installing Visual C++ 2022 Build Tools..." -$version="14.39.17.9." +$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.${tool_version}x86.x64 --add Microsoft.VisualStudio.Component.VC.${tool_version}ARM --add Microsoft.VisualStudio.Component.VC.${tool_version}ARM64" From 0448b46b9a7bfbe281759b91ef5fa18785f6604d Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Fri, 7 Jun 2024 15:34:51 +0200 Subject: [PATCH 3/3] minor fix --- buildkite/setup-windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildkite/setup-windows.ps1 b/buildkite/setup-windows.ps1 index fd75a0a2a8..28d951f5b5 100755 --- a/buildkite/setup-windows.ps1 +++ b/buildkite/setup-windows.ps1 @@ -150,9 +150,9 @@ $tool_version="14.39.17.9." $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 }