From dc74dfb070bcfcc358c3c0085ba0af87eb0fa9ca Mon Sep 17 00:00:00 2001 From: PLPeeters Date: Sat, 14 Nov 2026 14:27:42 +0100 Subject: [PATCH] Coordinate MSVC toolsets and identify compiler-specific archives --- .github/workflows/main.yml | 20 +++++++------- README.md | 23 ++++++++++++++-- build.ps1 | 56 ++++++++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index efa09dee..354ec9d2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,8 +24,8 @@ jobs: architecture: - x86 - x64 - compiler: - - vs2022 + toolset: + - "14.44" steps: @@ -44,14 +44,14 @@ jobs: install-module pscx -scope CurrentUser -AllowClobber $x64param = if ('${{ matrix.architecture }}' -eq 'x64') { $true } else { $false } $arm64param = if ('${{ matrix.architecture }}' -eq 'arm64') { $true } else { $false } - pwsh .\build.ps1 -x64:$x64param -arm64:$arm64param + pwsh .\build.ps1 -x64:$x64param -arm64:$arm64param -toolset "${{ matrix.toolset }}" - name: upload uses: actions/upload-artifact@v7 with: - name: libraries-${{ matrix.architecture }}.zip + name: libraries-${{ matrix.architecture }}-msvc-${{ matrix.toolset }}.zip path: dist/*.zip - if-no-files-found: ignore + if-no-files-found: error - name: release uses: softprops/action-gh-release@v3 @@ -67,8 +67,8 @@ jobs: matrix: architecture: - arm64 - compiler: - - vs2022 + toolset: + - "14.52" steps: @@ -87,14 +87,14 @@ jobs: install-module pscx -scope CurrentUser -AllowClobber $x64param = if ('${{ matrix.architecture }}' -eq 'x64') { $true } else { $false } $arm64param = if ('${{ matrix.architecture }}' -eq 'arm64') { $true } else { $false } - pwsh .\build.ps1 -x64:$x64param -arm64:$arm64param + pwsh .\build.ps1 -x64:$x64param -arm64:$arm64param -toolset "${{ matrix.toolset }}" - name: upload uses: actions/upload-artifact@v7 with: - name: libraries-${{ matrix.architecture }}.zip + name: libraries-${{ matrix.architecture }}-msvc-${{ matrix.toolset }}.zip path: dist/*.zip - if-no-files-found: ignore + if-no-files-found: error - name: release uses: softprops/action-gh-release@v3 diff --git a/README.md b/README.md index 3d8cf4d3..5f219acc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build status](https://ci.appveyor.com/api/projects/status/cc6q3nrosjul2sgl?svg=true)](https://ci.appveyor.com/project/mhils/libxml2-win-binaries) -This repository contains everything required to compile libiconv, libxml2, and libxslt on Windows with Visual Studio 2015 / UCRT so that it can be used to build lxml wheels for Python 3.5. +This repository builds static libiconv, zlib, libxml2, and libxslt libraries for lxml on Windows with Visual Studio. ## Instructions @@ -12,9 +12,28 @@ This repository contains everything required to compile libiconv, libxml2, and l Set-ExecutionPolicy remotesigned Find-Package pscx | ? ProviderName -eq PSModule | Install-Package -Force ``` -- Run `build.ps1` +- Run `build.ps1` for x86, `build.ps1 -x64` for x64, or `build.ps1 -arm64` for ARM64. - Take binaries from `dist/` +## Compiler compatibility + +The libraries retain whole-program optimisation (`/GL` / LTCG). Both this +repository and lxml select MSVC 14.44 for x86/x64 and 14.52 for ARM64. The +required toolset must already be installed; builds fail instead of silently +selecting a different toolset. Keep the defaults in `build.ps1`, the workflow +matrix, and lxml's `buildlibxml.py` in sync when changing toolset families. + +`build.ps1` passes the selected `VCToolsVersion` to both vcvars and MSBuild. +Every ZIP and its top-level directory include the compiler's `_MSC_FULL_VER`, +for example `iconv-1.19.win-arm64.msvc-195237025.zip`. lxml only consumes +archives for its exact compiler version, including servicing patches, and +uses that identity in its dependency cache keys. + +Publish a new binary release after this change, before using the coordinated +lxml build. After a runner compiler update, rebuild and publish the libraries +with that compiler before lxml can consume them. An older compiler's archives +are deliberately rejected even when the library versions are unchanged. + ## Acknowledgements This work was made possible by https://github.com/winlibs! diff --git a/build.ps1 b/build.ps1 index 69d2d8d8..a5d48ae6 100644 --- a/build.ps1 +++ b/build.ps1 @@ -3,13 +3,15 @@ This script builds libiconv, zlib, libxml2 and libxslt #> Param( [switch]$x64, - [switch]$arm64 + [switch]$arm64, + [ValidateSet("14.44", "14.52")] + [string]$toolset ) $ErrorActionPreference = "Stop" Import-Module Pscx -Function Get-BatPath($vcvarsarch) { +Function Get-BatPath($vcvarsarch, $toolset) { $editions = "Community", "Enterprise" $years = 2022, 18 @@ -30,17 +32,18 @@ Function Get-BatPath($vcvarsarch) { Write-Host "Tried $buildDir, found $vcvars" if (-not $vcvars) { continue } - $msvcVersions = Get-ChildItem $msvcDir -Directory + $msvcVersions = Get-ChildItem $msvcDir -Directory | Where-Object { $_.Name -like "$toolset.*" } + if (-not $msvcVersions) { continue } $paths = $msvcVersions.FullName Write-Host "Found $paths" - $latestVersion = ($msvcVersions | Sort-Object Name -Descending)[0].Name - Write-Host "Using: $vcvars for MSVC $latestVersion" - return $vcvars, $latestVersion + $selectedVersion = ($msvcVersions | Sort-Object { [version]$_.Name } -Descending | Select-Object -First 1).Name + Write-Host "Using: $vcvars for MSVC $selectedVersion" + return $vcvars, $selectedVersion } } - throw "vcvars*.bat not found" + throw "MSVC $toolset for $vcvarsarch is required; install it with the Visual Studio Installer." } $platDir = If($x64) { "\x64" } ElseIf ($arm64) { "\arm64" } Else { "\Win32" } @@ -48,15 +51,34 @@ $distname = If($x64) { "win64" } ElseIf($arm64) { "win-arm64" } Else { "win32" } $vcvarsarch = If($x64) { "x86_amd64" } ElseIf ($arm64) { "arm64" } Else { "32" } -$bat, $latestVersion = Get-BatPath $vcvarsarch -$env:VCTOOLSVERSION = $latestVersion +# Keep these toolset families in sync with lxml/buildlibxml.py. +if (-not $toolset) { $toolset = If ($arm64) { "14.52" } Else { "14.44" } } +$bat, $selectedVersion = Get-BatPath $vcvarsarch $toolset -& cmd.exe /c "`"$bat`" && set" | ForEach-Object { +& cmd.exe /d /c "`"$bat`" -vcvars_ver=$selectedVersion && set" | ForEach-Object { if ($_ -match "^([^=]+)=(.*)$") { [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2]) } } +if ($LASTEXITCODE -ne 0) { throw "vcvars failed: $LASTEXITCODE" } +if ($env:VCToolsVersion.TrimEnd('\', '/') -ne $selectedVersion) { + throw "Visual Studio did not select MSVC $selectedVersion" +} + +# /GL objects require the exact compiler version, including servicing patches. +$probe = [IO.Path]::GetTempFileName() +try { + Set-Content -Path $probe -Value "_MSC_FULL_VER" -Encoding ascii + $compilerVersion = (& cl.exe /nologo /EP /TC $probe | Out-String).Trim() + if ($LASTEXITCODE -ne 0 -or $compilerVersion -notmatch '^\d+$') { + throw "Cannot determine _MSC_FULL_VER: $compilerVersion" + } +} finally { + Remove-Item $probe +} +$distname = "$distname.msvc-$compilerVersion" +Write-Host "_MSC_FULL_VER: $compilerVersion" Write-Host "VCToolsVersion: $env:VCToolsVersion" Write-Host "MSVC_VER: $env:MSVC_VER" Write-Host "VisualStudioVersion: $env:VisualStudioVersion" @@ -65,7 +87,10 @@ Set-Location $PSScriptRoot $msvcConfigDir = If ($arm64) { "MSVC18" } Else { "MSVC17" } Set-Location .\libiconv\$msvcConfigDir -msbuild libiconv_static\libiconv_static.vcxproj /p:Configuration=Release +$platform = If ($x64) { "x64" } ElseIf ($arm64) { "ARM64" } Else { "Win32" } +$platformToolset = If ($toolset -eq "14.44") { "v143" } Else { "v145" } +msbuild libiconv_static\libiconv_static.vcxproj /p:Configuration=Release /p:Platform=$platform /p:PlatformToolset=$platformToolset /p:VCToolsVersion=$selectedVersion +if ($LASTEXITCODE -ne 0) { throw "libiconv build failed: $LASTEXITCODE" } $iconvLib = Join-Path (pwd) $platDir\lib $iconvInc = Join-Path $PSScriptRoot libiconv\source\include @@ -73,7 +98,8 @@ $iconvInc = Join-Path $PSScriptRoot libiconv\source\include Set-Location $PSScriptRoot Set-Location .\zlib -Start-Process -NoNewWindow -Wait nmake "-f win32/Makefile.msc zlib_a.lib" +$build = Start-Process -NoNewWindow -Wait -PassThru nmake "-f win32/Makefile.msc zlib_a.lib" +if ($build.ExitCode -ne 0) { throw "zlib build failed: $($build.ExitCode)" } $zlibLib = (pwd) $zlibInc = (pwd) @@ -83,14 +109,16 @@ Set-Location .. Set-Location .\libxml2\win32 cscript configure.js lib="$zlibLib;$iconvLib" include="$zlibInc;$iconvInc" vcmanifest=yes zlib=yes -Start-Process -NoNewWindow -Wait nmake libxmla +$build = Start-Process -NoNewWindow -Wait -PassThru nmake libxmla +if ($build.ExitCode -ne 0) { throw "libxml2 build failed: $($build.ExitCode)" } $xmlLib = Join-Path (pwd) bin.msvc $xmlInc = Join-Path (pwd) ..\include Set-Location ..\.. Set-Location .\libxslt\win32 cscript configure.js lib="$zlibLib;$iconvLib;$xmlLib" include="$zlibInc;$iconvInc;$xmlInc" vcmanifest=yes zlib=yes -Start-Process -NoNewWindow -Wait nmake "libxslta libexslta" +$build = Start-Process -NoNewWindow -Wait -PassThru nmake "libxslta libexslta" +if ($build.ExitCode -ne 0) { throw "libxslt build failed: $($build.ExitCode)" } Set-Location ..\.. # Bundle releases