Skip to content

The agent that grows with you

fix(windows): pin vcpkg to the Visual Studio that has the arm64 toolset

dalebetzea93303f473b
diff --git a/scripts/windows-build-deps.ps1 b/scripts/windows-build-deps.ps1
index 92371454b60..779342b36b2 100644
--- a/scripts/windows-build-deps.ps1
+++ b/scripts/windows-build-deps.ps1
@@ -252,6 +252,11 @@ function Initialize-HermesArm64BuildTools {
Invoke-HermesBuildCommand (Join-Path $vcpkgRoot 'bootstrap-vcpkg.bat') @('-disableMetrics') 'Building vcpkg'
}
$env:VCPKG_ROOT = $vcpkgRoot
+ # vcpkg resolves Visual Studio itself and takes the newest instance, which may lack the
+ # native arm64 toolset even though the instance above has it: the arm64-windows triplet
+ # then fails with "Unable to find a valid toolchain" and the whole update aborts. Point
+ # vcpkg at the instance VsDevCmd was initialized against, unless the caller pinned one.
+ if (-not $env:VCPKG_VISUAL_STUDIO_PATH) { $env:VCPKG_VISUAL_STUDIO_PATH = $vs }
# The install tree can be cached independently of the discovered checkout.
if (-not $OpenSSLRoot) { $OpenSSLRoot = $vcpkgRoot }
$env:OPENSSL_DIR = Install-HermesArm64OpenSSL -Vcpkg (Join-Path $vcpkgRoot 'vcpkg.exe') -Root $OpenSSLRoot
diff --git a/tests/pm/test_windows_build_deps.py b/tests/pm/test_windows_build_deps.py
index c25fbfbaf71..099d761db3d 100644
--- a/tests/pm/test_windows_build_deps.py
+++ b/tests/pm/test_windows_build_deps.py
@@ -179,6 +179,7 @@ function Get-Command {
function Invoke-HermesBuildCommand { throw 'Unexpected installation' }
function Invoke-WebRequest { throw 'Unexpected download' }
Remove-Item Env:VCPKG_ROOT -ErrorAction SilentlyContinue
+Remove-Item Env:VCPKG_VISUAL_STUDIO_PATH -ErrorAction SilentlyContinue
$env:VCPKG_INSTALLATION_ROOT = $vcpkg
$env:RUSTUP_TOOLCHAIN = 'caller-selected-toolchain'
if ($Homes -eq 'explicit') {
@@ -196,6 +197,8 @@ $cargoBin = Join-Path $cargoHome 'bin'
$expectedPath = $devDir + '\;' + $inheritedPath
if ($cargoBin -notin ($expectedPath -split ';')) { $expectedPath = $cargoBin + ';' + $expectedPath }
Initialize-HermesArm64BuildTools -StateRoot $Root -OpenSSLRoot $openssl
+# The discovered instance is the one VsDevCmd used; vcpkg must not pick another.
+if ($env:VCPKG_VISUAL_STUDIO_PATH -ne $vs) { throw 'vcpkg was not pinned to the discovered Visual Studio' }
if ($env:CARGO_HOME -ne $cargoHome -or $env:RUSTUP_HOME -ne $rustupHome) { throw 'Rust homes lost' }
if ($env:RUSTUP_TOOLCHAIN -ne 'caller-selected-toolchain') { throw 'Caller Rust toolchain lost' }
if ($env:PATH -ne $expectedPath) { throw 'PATH lost or reordered' }
@@ -224,6 +227,10 @@ foreach ($invalid in @('INCLUDE', 'LIB', 'VSCMD_ARG_HOST_ARCH', 'VSCMD_ARG_TGT_A
if ((Get-Item "env:$name").Value -cne $prepared[$name]) { throw "Did not repair $invalid" }
}
}
+# A caller's explicit pin wins: the guard must not clobber it.
+$env:VCPKG_VISUAL_STUDIO_PATH = 'caller-pinned VS'
+Initialize-HermesArm64BuildTools -StateRoot $Root -OpenSSLRoot $openssl
+if ($env:VCPKG_VISUAL_STUDIO_PATH -ne 'caller-pinned VS') { throw 'Caller Visual Studio pin was overwritten' }
$env:VSCMD_ARG_TGT_ARCH = 'x64'
[IO.File]::WriteAllText((Join-Path $devDir 'VsDevCmd.bat'), "@exit /b 19`r`n")
$failed = $false