Skip to content

Commit 0fd8b22

Browse files
committed
fix(ci): use vswhere to locate MSVC for x86 on windows-2025 (VS 2026/18 support)
The hardcoded 2022 discovery failed because windows-2025 runners now use Visual Studio 2026 (paths under Microsoft Visual Studio\18\...). Proper solution (matching ilammy/msvc-dev-cmd logic and community practices for GitHub Actions + VS 2022/2026): - Use vswhere.exe (official locator, handles any VS version/year) - Find installationPath dynamically - Activate with amd64_x86 (64-bit host tools for 32-bit target) - Verify activation (where cl + version) in logs - Export full env via GITHUB_ENV for uv sdist builds (pyyaml etc.) This is the standard robust way used across Python/C++ extension CI on GitHub Windows runners. No external action (avoids Node 20 issues). shell: pwsh for reliable scripting + child cmd for vcvars. Keeps change strictly to the x86 CI fix.
1 parent a995e7d commit 0fd8b22

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

.github/workflows/build_app.yml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,33 @@ jobs:
4646
working-directory: ${{ github.workspace }}/repo
4747
- name: Setup MSVC for x86
4848
if: matrix.arch == 'x86'
49-
shell: cmd
49+
shell: pwsh
5050
run: |
51-
@echo off
52-
setlocal
53-
set "VCVARS="
54-
echo Looking for vcvarsall.bat...
55-
for /f "delims=" %%f in ('dir /s /b "C:\Program Files*\Microsoft Visual Studio\2022\*\VC\Auxiliary\Build\vcvarsall.bat" 2^>nul') do (
56-
set "VCVARS=%%f"
57-
goto :found
58-
)
59-
:found
60-
if not defined VCVARS (
61-
echo ERROR: vcvarsall.bat not found anywhere under VS 2022
62-
dir "C:\Program Files*\Microsoft Visual Studio\2022" 2>&1 | findstr /i "Enterprise Community Professional BuildTools" || echo (no editions visible)
63-
exit /b 1
64-
)
65-
echo Using: %VCVARS%
66-
call "%VCVARS%" amd64_x86
67-
echo === Verifying 32-bit MSVC toolchain (for uv sdist builds) ===
68-
where cl
69-
cl 2>&1 | findstr /C:"Version" || echo (no version banner)
70-
echo ============================================================
71-
set >> %GITHUB_ENV%
51+
$ErrorActionPreference = 'Stop'
52+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
53+
if (-not (Test-Path $vswhere)) {
54+
throw "vswhere.exe not found at $vswhere"
55+
}
56+
$installPath = & $vswhere -latest -products * -property installationPath 2>$null | Select-Object -First 1
57+
if (-not $installPath) {
58+
throw "vswhere did not return an installation path"
59+
}
60+
$vcvarsall = Join-Path $installPath 'VC\Auxiliary\Build\vcvarsall.bat'
61+
if (-not (Test-Path $vcvarsall)) {
62+
throw "vcvarsall.bat not found at $vcvarsall (installPath=$installPath)"
63+
}
64+
Write-Host "Using vcvarsall: $vcvarsall"
65+
66+
# Activate and verify in a child cmd (prints to logs)
67+
cmd /c "`"$vcvarsall`" amd64_x86 && echo === Verifying 32-bit MSVC (for uv sdist win32 builds) === && where cl && cl 2>&1 | findstr /C:Version && echo ============================================"
68+
69+
# Export environment for subsequent steps
70+
cmd /c "`"$vcvarsall`" amd64_x86 && set" | ForEach-Object {
71+
if ($_ -match '^(.*?)=(.*)$') {
72+
Add-Content -Path $env:GITHUB_ENV -Value "$($matches[1])=$($matches[2])" -Encoding utf8
73+
}
74+
}
75+
Write-Host "MSVC x86 environment exported to GITHUB_ENV"
7276
- name: Install dependencies
7377
working-directory: ${{ github.workspace }}/repo
7478
run: uv sync --frozen --compile --group build --group test

0 commit comments

Comments
 (0)