|
| 1 | +@@echo on |
| 2 | +REM set Visual Studio toolchain given bitness, VS year and toolchain number. |
| 3 | +IF [%1] == [] GOTO NoArgErr |
| 4 | +set VS_BITS=%1 |
| 5 | +IF [%2] == [] GOTO NoArgErr |
| 6 | +set VS_YEAR=%2 |
| 7 | +IF [%3] == [] GOTO NoArgErr |
| 8 | +set VS_TOOLCHAIN=%3 |
| 9 | + |
| 10 | + |
| 11 | +REM Tools can come from any of Professional, Community, BuildTools or Enterprise install. |
| 12 | +if not exist "%VSINSTALLDIR%" ( |
| 13 | +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\Professional\" |
| 14 | +) |
| 15 | +if not exist "%VSINSTALLDIR%" ( |
| 16 | +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\Community\" |
| 17 | +) |
| 18 | +if not exist "%VSINSTALLDIR%" ( |
| 19 | +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\BuildTools\" |
| 20 | +) |
| 21 | +if not exist "%VSINSTALLDIR%" ( |
| 22 | +set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VS_YEAR%\Enterprise\" |
| 23 | +) |
| 24 | + |
| 25 | +REM Discover the latest Windows SDK available. |
| 26 | +call :GetWin10SdkDir |
| 27 | +:: dir /ON here is sorting the list of folders, such that we use the latest one that we have |
| 28 | +for /F %%i in ('dir /ON /B "%WindowsSdkDir%\include\10.*"') DO ( |
| 29 | + SET WindowsSDKVer=%%~i |
| 30 | +) |
| 31 | +if errorlevel 1 ( |
| 32 | + echo "Didn't find any windows 10 SDK. I'm not sure if things will work, but let's try..." |
| 33 | +) else ( |
| 34 | + echo Windows SDK version found as: "%WindowsSDKVer%" |
| 35 | +) |
| 36 | + |
| 37 | +REM Set bitness, toolchain version and SDK. |
| 38 | +call "%VSINSTALLDIR%\VC\Auxiliary\Build\vcvars%1.bat" -vcvars_ver=%VS_TOOLCHAIN% %WindowsSDKVer% |
| 39 | +REM https://docs.python.org/3.9/distutils/apiref.html#module-distutils.msvccompiler |
| 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. |
| 43 | +set DISTUTILS_USE_SDK=1 |
| 44 | +set MSSdk=1 |
| 45 | + |
| 46 | +REM All done, finish here. |
| 47 | +goto:eof |
| 48 | + |
| 49 | +REM Various subroutines. |
| 50 | + |
| 51 | +:GetWin10SdkDir |
| 52 | +call :GetWin10SdkDirHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 |
| 53 | +if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 |
| 54 | +if errorlevel 1 call :GetWin10SdkDirHelper HKLM\SOFTWARE > nul 2>&1 |
| 55 | +if errorlevel 1 call :GetWin10SdkDirHelper HKCU\SOFTWARE > nul 2>&1 |
| 56 | +if errorlevel 1 exit /B 1 |
| 57 | +exit /B 0 |
| 58 | + |
| 59 | +:GetWin10SdkDirHelper |
| 60 | +@@REM `Get Windows 10 SDK installed folder` |
| 61 | +for /F "tokens=1,2*" %%i in ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( |
| 62 | + if "%%i"=="InstallationFolder" ( |
| 63 | + SET WindowsSdkDir=%%~k |
| 64 | + ) |
| 65 | +) |
| 66 | +exit /B 0 |
| 67 | + |
| 68 | +:NoArgErr |
| 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