Skip to content

Commit 56fa98e

Browse files
committed
fix(ci): setup MSVC for x86 using vswhere + cmd activation for reliable 32-bit builds on windows-2025
The x86 job was failing at "Install dependencies" (uv sync --frozen --compile) because packages like pyyaml and greenlet have no cp314-win32 wheels for Python 3.14 and must be built from sdist. This requires the 32-bit MSVC toolchain (cl.exe etc.) to be active in the environment. Key problems with prior attempts: - Hardcoded paths for "2022" broke because windows-2025 now uses VS 2026 (paths under Microsoft Visual Studio\18\...). - ilammy/msvc-dev-cmd is Node 20-based and deprecated under Node 24 forcing. - Env activation in pwsh steps did not reliably propagate to the uv build step (GITHUB_ENV + process env issues for native extension builds). Solution (standard pattern from MS docs, runner-images, and many C++/Python extension projects on GitHub): - Use vswhere.exe (official locator, handles any VS version/edition) to dynamically find the installation. - Activate with "amd64_x86" (correct cross for 64-host -> 32-target). - Verify activation in Setup step logs (where cl + version). - Export VCVARSALL path. - For the critical "Install dependencies" step, use shell: cmd and directly call "%VCVARSALL%" amd64_x86 right before "uv sync", with verification. This ensures the compiler env is active in the exact context where sdist builds happen. Added verification print also in the install step for easier debugging. This is the minimal, reliable change strictly for the x86 CI fix (no dep changes elsewhere). All other actions remain pinned.
1 parent 9ab8b45 commit 56fa98e

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

.github/workflows/build_app.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,58 @@ jobs:
4444
with:
4545
python-version: 'cpython-3.14-windows-${{ matrix.arch }}-none'
4646
working-directory: ${{ github.workspace }}/repo
47+
- name: Setup MSVC for x86
48+
if: matrix.arch == 'x86'
49+
shell: pwsh
50+
run: |
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+
# Use vswhere (the official/recommended way for GitHub runners, handles VS 2022 and 2026+)
57+
$installPath = & $vswhere -latest -products * -property installationPath 2>$null | Select-Object -First 1
58+
if (-not $installPath) {
59+
throw "vswhere did not return an installation path"
60+
}
61+
$vcvarsall = Join-Path $installPath 'VC\Auxiliary\Build\vcvarsall.bat'
62+
if (-not (Test-Path $vcvarsall)) {
63+
throw "vcvarsall.bat not found at $vcvarsall (installPath=$installPath)"
64+
}
65+
Write-Host "Using vcvarsall: $vcvarsall"
66+
67+
# Activate, update *current process* env + export to GITHUB_ENV for next steps.
68+
# Also export VCVARSALL path so later steps (or same if needed) can re-activate reliably.
69+
cmd /c "`"$vcvarsall`" amd64_x86 && set" | ForEach-Object {
70+
if ($_ -match '^(.*?)=(.*)$') {
71+
$n = $matches[1]
72+
$v = $matches[2]
73+
[Environment]::SetEnvironmentVariable($n, $v, 'Process')
74+
Add-Content -Path $env:GITHUB_ENV -Value "$n=$v" -Encoding utf8
75+
}
76+
}
77+
[Environment]::SetEnvironmentVariable('VCVARSALL', $vcvarsall, 'Process')
78+
Add-Content -Path $env:GITHUB_ENV -Value "VCVARSALL=$vcvarsall" -Encoding utf8
79+
80+
# Now verify in the *current* pwsh context (will show in this step's logs)
81+
Write-Host "=== Verifying 32-bit MSVC (for uv sdist win32 builds) ==="
82+
where.exe cl
83+
cl 2>&1 | findstr /C:Version || Write-Host "(cl version not shown)"
84+
Write-Host "========================================================"
85+
Write-Host "MSVC x86 environment applied to current process and exported to GITHUB_ENV"
4786
- name: Install dependencies
4887
working-directory: ${{ github.workspace }}/repo
49-
run: uv sync --frozen --compile --group build --group test
88+
shell: cmd
89+
run: |
90+
if defined VCVARSALL (
91+
echo Re-activating MSVC using %VCVARSALL%
92+
call "%VCVARSALL%" amd64_x86
93+
echo === Verifying 32-bit MSVC in install step ===
94+
where cl
95+
cl 2>&1 | findstr /C:Version || echo (no version)
96+
echo =============================================
97+
)
98+
uv sync --frozen --compile --group build --group test
5099
- name: compile python bytecode
51100
working-directory: ${{ github.workspace }}/repo
52101
run: |

0 commit comments

Comments
 (0)