Skip to content

Commit c85d235

Browse files
authored
Build Windows binaries with Visual Studio 2022 Build Tools (#1240)
* Build Windows binaries with Visual Studio 2022 Build Tools * Unify casing in Batch files, remove VS 2017 installation * Remove VS 2017 Conda scripts, unify casing in conda Batch scripts, minor Conda scripts tweaks
1 parent d44743a commit c85d235

13 files changed

+137
-89
lines changed
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
:: Set env vars that tell distutils to use the compiler that we put on path
2-
SET DISTUTILS_USE_SDK=1
3-
SET MSSdk=1
2+
set DISTUTILS_USE_SDK=1
3+
set MSSdk=1
44

5-
SET "VS_VERSION=15.0"
6-
SET "VS_MAJOR=15"
7-
SET "VS_YEAR=2017"
5+
set "VS_VERSION=17.4"
6+
set "VS_MAJOR=17"
7+
set "VC_YEAR=2022"
8+
set "VC_VERSION_LOWER=17"
9+
set "VC_VERSION_UPPER=18"
810

911
set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
1012
set "MSYS2_ENV_CONV_EXCL=CL"
1113

1214
:: For Python 3.5+, ensure that we link with the dynamic runtime. See
1315
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info
14-
set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime140.dll"
16+
set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime143.dll"
1517

16-
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do (
18+
if not "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" (
19+
set "VSINSTALLDIR=%VS15INSTALLDIR%\"
20+
goto :vswhere
21+
)
22+
23+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
1724
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
1825
set "VSINSTALLDIR=%%i\"
1926
goto :vswhere
@@ -23,22 +30,22 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio
2330
:vswhere
2431

2532
:: Shorten PATH to avoid the `input line too long` error.
26-
SET MyPath=%PATH%
33+
set MyPath=%PATH%
2734

2835
setlocal EnableDelayedExpansion
2936

30-
SET TempPath="%MyPath:;=";"%"
31-
SET var=
32-
FOR %%a IN (%TempPath%) DO (
33-
IF EXIST %%~sa (
34-
SET "var=!var!;%%~sa"
37+
set TempPath="%MyPath:;=";"%"
38+
set var=
39+
for %%a in (%TempPath%) do (
40+
if exist %%~sa (
41+
set "var=!var!;%%~sa"
3542
)
3643
)
3744

3845
set "TempPath=!var:~1!"
3946
endlocal & set "PATH=%TempPath%"
4047

4148
:: Shorten current directory too
42-
FOR %%A IN (.) DO CD "%%~sA"
49+
for %%A in (.) do cd "%%~sA"
4350

4451
:: other things added by install_activate.bat at package build time

conda/vs2017/conda_build_config.yaml renamed to conda/vs2022/conda_build_config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
blas_impl:
22
- mkl # [x86_64]
33
c_compiler:
4-
- vs2017 # [win]
4+
- vs2022 # [win]
55
cxx_compiler:
6-
- vs2017 # [win]
6+
- vs2022 # [win]
77
python:
8-
- 3.5
9-
- 3.6
8+
- 3.8
9+
- 3.9
10+
- 3.10
1011
# This differs from target_platform in that it determines what subdir the compiler
1112
# will target, not what subdir the compiler package will be itself.
1213
# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32

conda/vs2017/install_activate.bat renamed to conda/vs2022/install_activate.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
set YEAR=2017
2-
set VER=15
1+
set YEAR=2022
2+
set VER=17
33

44
mkdir "%PREFIX%\etc\conda\activate.d"
55
copy "%RECIPE_DIR%\activate.bat" "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"

conda/vs2017/install_runtime.bat renamed to conda/vs2022/install_runtime.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if "%ARCH%"=="64" (
33
set VC_PATH=x64
44
)
55

6-
set MSC_VER=2017
6+
set MSC_VER=2022
77

88
rem :: This should always be present for VC installed with VS. Not sure about VC installed with Visual C++ Build Tools 2015
99
rem FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\Microsoft\DevDiv\VC\Servicing\14.0\IDE.x64" /v UpdateVersion`) DO (
@@ -23,10 +23,10 @@ robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%
2323
robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%PREFIX%" *.dll /E
2424
if %ERRORLEVEL% GEQ 8 exit 1
2525

26-
REM ========== This one comes from visual studio 2017
27-
set "VC_VER=141"
26+
REM ========== This one comes from visual studio 2022
27+
set "VC_VER=143"
2828

29-
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do (
29+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [17^,18^) -property installationPath`) do (
3030
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
3131
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
3232
goto :eof

conda/vs2017/meta.yaml renamed to conda/vs2022/meta.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{% set vcver="14.1" %}
2-
{% set vcfeature="14" %}
3-
{% set vsyear="2017" %}
4-
{% set fullver="15.4.27004.2010" %}
1+
{% set vcver="17.4" %}
2+
{% set vcfeature="17" %}
3+
{% set vsyear="2022" %}
4+
{% set fullver="17.4.33110.190" %}
55

66
package:
77
name: vs{{ vsyear }}
@@ -16,7 +16,7 @@ outputs:
1616
- name: vs{{ vsyear }}_{{ cross_compiler_target_platform }}
1717
script: install_activate.bat
1818
track_features:
19-
# VS 2017 is binary-compatible with VS 2015/vc14. Tools are "v141".
19+
# VS 2022 is binary-compatible with VS 2019/vc 14.2, VS 2017/vc 14.1 and 2015/vc14. Tools are "v143".
2020
strong:
2121
- vc{{ vcfeature }}
2222
about:

windows/internal/check_deps.bat

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ IF "%BUILD_VISION%" == "" (
1616
)
1717
)
1818

19-
IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
20-
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows
19+
if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
20+
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows
2121
exit /b 1
2222
)
2323

24-
IF "%VC_YEAR%" == "" set VC_YEAR=2019
25-
26-
set VC_VERSION_LOWER=16
27-
set VC_VERSION_UPPER=17
28-
IF "%VC_YEAR%" == "2017" (
29-
set VC_VERSION_LOWER=15
30-
set VC_VERSION_UPPER=16
24+
set VC_VERSION_LOWER=17
25+
set VC_VERSION_UPPER=18
26+
if "%VC_YEAR%" == "2019" (
27+
set VC_VERSION_LOWER=16
28+
set VC_VERSION_UPPER=17
3129
)
3230

3331
if NOT "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" (

windows/internal/cuda_install.bat

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set CUDNN_FOLDER="cuda"
1717
set CUDNN_LIB_FOLDER="lib\x64"
1818

1919
:: Skip all of this if we already have cuda installed
20-
if exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" goto set_cuda_env_vars
20+
if exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" goto set_cuda_env_vars
2121

2222
if %CUDA_VER% EQU 116 goto cuda116
2323
if %CUDA_VER% EQU 117 goto cuda117
@@ -112,7 +112,7 @@ goto cuda_common
112112
:: With GHA runners these should be pre-installed as part of our AMI process
113113
:: If you cannot find the CUDA version you want to build for here then please
114114
:: add it @ https://github.com/pytorch/test-infra/tree/main/aws/ami/windows
115-
if not exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" (
115+
if not exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" (
116116
if not exist "%SRC_DIR%\temp_build\NvToolsExt.7z" (
117117
curl -k -L https://ossci-windows.s3.us-east-1.amazonaws.com/builder/NvToolsExt.7z --output "%SRC_DIR%\temp_build\NvToolsExt.7z"
118118
if errorlevel 1 exit /b 1
@@ -137,12 +137,12 @@ if not exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION
137137
popd
138138

139139
echo Installing VS integration...
140-
if "%VC_YEAR%" == "2017" (
141-
xcopy /Y "%SRC_DIR%\temp_build\cuda\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\BuildCustomizations"
142-
)
143140
if "%VC_YEAR%" == "2019" (
144141
xcopy /Y "%SRC_DIR%\temp_build\cuda\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\BuildCustomizations"
145142
)
143+
if "%VC_YEAR%" == "2022" (
144+
xcopy /Y "%SRC_DIR%\temp_build\cuda\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions\*.*" "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\BuildCustomizations"
145+
)
146146

147147
echo Installing NvToolsExt...
148148
7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt"

windows/internal/env_fix.bat

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55

66
setlocal
77

8-
IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
9-
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows
8+
if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
9+
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows
1010
exit /b 1
1111
)
1212

13-
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do (
13+
set VC_VERSION_LOWER=17
14+
set VC_VERSION_UPPER=18
15+
if "%VC_YEAR%" == "2019" (
16+
set VC_VERSION_LOWER=16
17+
set VC_VERSION_UPPER=17
18+
)
19+
20+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
1421
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
1522
set "VS15INSTALLDIR=%%i"
1623
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
@@ -20,8 +27,8 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio
2027

2128
:vswhere
2229

23-
IF "%VS15VCVARSALL%"=="" (
24-
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows
30+
if "%VS15VCVARSALL%"=="" (
31+
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows
2532
exit /b 1
2633
)
2734

windows/internal/smoke_test.bat

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,21 @@ goto end
147147
:libtorch
148148
echo "install and test libtorch"
149149

150-
if "%VC_YEAR%" == "2017" powershell internal\vs2017_install.ps1
150+
if "%VC_YEAR%" == "2019" powershell internal\vs2019_install.ps1
151+
if "%VC_YEAR%" == "2022" powershell internal\vs2022_install.ps1
152+
151153
if ERRORLEVEL 1 exit /b 1
152154

153155
for /F "delims=" %%i in ('where /R "%PYTORCH_FINAL_PACKAGE_DIR:/=\%" *-latest.zip') do 7z x "%%i" -otmp
154156
if ERRORLEVEL 1 exit /b 1
155157

156158
pushd tmp\libtorch
157159

158-
set VC_VERSION_LOWER=16
159-
set VC_VERSION_UPPER=17
160-
IF "%VC_YEAR%" == "2017" (
161-
set VC_VERSION_LOWER=15
162-
set VC_VERSION_UPPER=16
160+
set VC_VERSION_LOWER=17
161+
set VC_VERSION_UPPER=18
162+
IF "%VC_YEAR%" == "2019" (
163+
set VC_VERSION_LOWER=16
164+
set VC_VERSION_UPPER=17
163165
)
164166

165167
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
@@ -172,7 +174,7 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio
172174

173175
:vswhere
174176
IF "%VS15VCVARSALL%"=="" (
175-
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch test on Windows
177+
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch test on Windows
176178
exit /b 1
177179
)
178180
call "%VS15VCVARSALL%" x64

windows/internal/vc_install_helper.bat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
if "%VC_YEAR%" == "2019" powershell windows/internal/vs2019_install.ps1
2+
if "%VC_YEAR%" == "2022" powershell windows/internal/vs2022_install.ps1
23

3-
set VC_VERSION_LOWER=16
4-
set VC_VERSION_UPPER=17
4+
set VC_VERSION_LOWER=17
5+
set VC_VERSION_UPPER=18
6+
if "%VC_YEAR%" == "2019" (
7+
set VC_VERSION_LOWER=16
8+
set VC_VERSION_UPPER=17
9+
)
510

611
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
712
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (

0 commit comments

Comments
 (0)