diff --git a/azure-pipelines.yml b/azure-pipelines.yml index abbe5a8..43aaf63 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -17,7 +17,7 @@ jobs: - template: azure/windows.yml parameters: name: "windows2019" - vmImage: "windows-latest" + vmImage: "windows-2019" timeoutInMinutes: 90 matrix: py_3.8_32: diff --git a/azure/set_vs_toolchain.cmd b/azure/set_vs_toolchain.cmd new file mode 100644 index 0000000..6ffb69f --- /dev/null +++ b/azure/set_vs_toolchain.cmd @@ -0,0 +1,71 @@ +@@echo on +REM set Visual Studio toolchain given bitness, VS year and toolchain number. +IF [%1] == [] GOTO NoArgErr +set VS_BITS=%1 +IF [%2] == [] GOTO NoArgErr +set VS_YEAR=%2 +IF [%3] == [] GOTO NoArgErr +set VS_TOOLCHAIN=%3 + + +REM Tools can come from any of Professional, Community, BuildTools or Enterprise install. +if not exist "%VSINSTALLDIR%" ( +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\Professional\" +) +if not exist "%VSINSTALLDIR%" ( +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\Community\" +) +if not exist "%VSINSTALLDIR%" ( +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\BuildTools\" +) +if not exist "%VSINSTALLDIR%" ( +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\Enterprise\" +) + +REM Discover the latest Windows SDK available. +call :GetWin10SdkDir +:: dir /ON here is sorting the list of folders, such that we use the latest one that we have +for /F %%i in ('dir /ON /B "%WindowsSdkDir%\include\10.*"') DO ( + SET WindowsSDKVer=%%~i +) +if errorlevel 1 ( + echo "Didn't find any windows 10 SDK. I'm not sure if things will work, but let's try..." +) else ( + echo Windows SDK version found as: "%WindowsSDKVer%" +) + +REM Set bitness, toolchain version and SDK. +call "%VSINSTALLDIR%\VC\Auxiliary\Build\vcvars%1.bat" -vcvars_ver=%VS_TOOLCHAIN% %WindowsSDKVer% +REM https://docs.python.org/3.9/distutils/apiref.html#module-distutils.msvccompiler +REM or +REM https://setuptools.pypa.io/en/latest/deprecated/distutils/apiref.html#module-distutils.msvccompiler +REM Force our SDK, rather than the Python was built with. +set DISTUTILS_USE_SDK=1 +set MSSdk=1 + +REM All done, finish here. +goto:eof + +REM Various subroutines. + +:GetWin10SdkDir +call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 +if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 +if errorlevel 1 call :GetWin10SdkDirHelper HKLM\SOFTWARE > nul 2>&1 +if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE > nul 2>&1 +if errorlevel 1 exit /B 1 +exit /B 0 + +:GetWin10SdkDirHelper +@@REM `Get Windows 10 SDK installed folder` +for /F "tokens=1,2*" %%i in ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( + if "%%i"=="InstallationFolder" ( + SET WindowsSdkDir=%%~k + ) +) +exit /B 0 + +:NoArgErr +echo "Need to specify input bitness, VS year and toolchain number" +echo "e.g 64 2019 14.16" +exit 1 diff --git a/azure/windows.yml b/azure/windows.yml index f77f19f..9e5ab41 100644 --- a/azure/windows.yml +++ b/azure/windows.yml @@ -20,6 +20,13 @@ jobs: - checkout: self submodules: true + - task: BatchScript@1 + inputs: + filename: azure/set_vs_toolchain.cmd + arguments: $(BITS) 2019 14.16 + modifyEnvironment: True + displayName: Set VS toolchain version + - task: UsePythonVersion@0 inputs: versionSpec: $(PYTHON_VERSION) @@ -122,6 +129,8 @@ jobs: popd displayName: Build wheel - bash: | + # Undo use specify VS build tools. + unset DISTUTILS_USE_SDK MSSdk set -ex source extra_functions.sh source config.sh