11@@ echo on
2- REM set Visual Studio 2017 toolchain (v141)
2+ REM set Visual Studio toolchain given bitness, VS year and toolchain number.
33IF [%1 ] == [] GOTO NoArgErr
44set VS_BITS = %1
55IF [%2 ] == [] GOTO NoArgErr
66set VS_YEAR = %2
7+ IF [%3 ] == [] GOTO NoArgErr
8+ set VS_TOOLCHAIN = %3
79
810
11+ REM Tools can come from any of Professional, Community, BuildTools or Enterprise install.
912if not exist " %VSINSTALLDIR% " (
1013set " VSINSTALLDIR = %ProgramFiles(x86)% \Microsoft Visual Studio\%VS_YEAR% \Professional\"
1114)
@@ -19,6 +22,7 @@ if not exist "%VSINSTALLDIR%" (
1922set " VSINSTALLDIR = %ProgramFiles(x86)% \Microsoft Visual Studio\%VS_YEAR% \Enterprise\"
2023)
2124
25+ REM Discover the latest Windows SDK available.
2226call :GetWin10SdkDir
2327:: dir /ON here is sorting the list of folders, such that we use the latest one that we have
2428for /F %%i in ('dir /ON /B " %WindowsSdkDir% \include\10.*" ') DO (
@@ -30,13 +34,20 @@ if errorlevel 1 (
3034 echo Windows SDK version found as: " %WindowsSDKVer% "
3135)
3236
33- call " %VSINSTALLDIR% \VC\Auxiliary\Build\vcvars%1 .bat" -vcvars_ver=14.16 %WindowsSDKVer%
37+ REM Set bitness, toolchain version and SDK.
38+ call " %VSINSTALLDIR% \VC\Auxiliary\Build\vcvars%1 .bat" -vcvars_ver=%VS_TOOLCHAIN% %WindowsSDKVer%
3439REM https://docs.python.org/3.9/distutils/apiref.html#module-distutils.msvccompiler
35- REM Force our SDK, rather than Python's
40+ REM or
41+ REM https://setuptools.pypa.io/en/latest/deprecated/distutils/apiref.html#module-distutils.msvccompiler
42+ REM Force our SDK, rather than the Python was built with.
3643set DISTUTILS_USE_SDK = 1
3744set MSSdk = 1
45+
46+ REM All done, finish here.
3847goto :eof
3948
49+ REM Various subroutines.
50+
4051:GetWin10SdkDir
4152call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node > nul 2 >& 1
4253if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node > nul 2 >& 1
@@ -55,5 +66,6 @@ for /F "tokens=1,2*" %%i in ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10
5566exit /B 0
5667
5768:NoArgErr
58- echo " Need to specify input bitness and VS year"
59- exit 1
69+ echo " Need to specify input bitness, VS year and toolchain number"
70+ echo " e.g 64 2019 14.16"
71+ exit 1
0 commit comments