Skip to content

Commit 3a8c751

Browse files
committed
Build Windows binaries with Visual Studio 2022 Build Tools.
1 parent e2e4542 commit 3a8c751

12 files changed

+280
-19
lines changed

conda/vs2022/activate.bat

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:: 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
4+
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"
10+
11+
set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
12+
set "MSYS2_ENV_CONV_EXCL=CL"
13+
14+
:: For Python 3.5+, ensure that we link with the dynamic runtime. See
15+
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info
16+
set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime143.dll"
17+
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 (
24+
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
25+
set "VSINSTALLDIR=%%i\"
26+
goto :vswhere
27+
)
28+
)
29+
30+
:vswhere
31+
32+
:: Shorten PATH to avoid the `input line too long` error.
33+
SET MyPath=%PATH%
34+
35+
setlocal EnableDelayedExpansion
36+
37+
SET TempPath="%MyPath:;=";"%"
38+
SET var=
39+
FOR %%a IN (%TempPath%) DO (
40+
IF EXIST %%~sa (
41+
SET "var=!var!;%%~sa"
42+
)
43+
)
44+
45+
set "TempPath=!var:~1!"
46+
endlocal & set "PATH=%TempPath%"
47+
48+
:: Shorten current directory too
49+
FOR %%A IN (.) DO CD "%%~sA"
50+
51+
:: other things added by install_activate.bat at package build time

conda/vs2022/conda_build_config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
blas_impl:
2+
- mkl # [x86_64]
3+
c_compiler:
4+
- vs2022 # [win]
5+
cxx_compiler:
6+
- vs2022 # [win]
7+
python:
8+
- 3.5
9+
- 3.6
10+
# This differs from target_platform in that it determines what subdir the compiler
11+
# will target, not what subdir the compiler package will be itself.
12+
# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32
13+
# code on win-64 miniconda.
14+
cross_compiler_target_platform:
15+
- win-64 # [win]
16+
target_platform:
17+
- win-64 # [win]
18+
vc:
19+
- 14
20+
zip_keys:
21+
- # [win]
22+
- vc # [win]
23+
- c_compiler # [win]
24+
- cxx_compiler # [win]

conda/vs2022/install_activate.bat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set YEAR=2022
2+
set VER=17
3+
4+
mkdir "%PREFIX%\etc\conda\activate.d"
5+
copy "%RECIPE_DIR%\activate.bat" "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
6+
7+
if "%cross_compiler_target_platform%" == "win-64" (
8+
set "target_platform=amd64"
9+
echo set "CMAKE_GENERATOR=Visual Studio %VER% %YEAR% Win64" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
10+
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
11+
if "%VSDEVCMD_ARGS%" == "" (
12+
echo call "VC\Auxiliary\Build\vcvarsall.bat" x64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
13+
) else (
14+
echo call "VC\Auxiliary\Build\vcvarsall.bat" x64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
15+
)
16+
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
17+
) else (
18+
set "target_platform=x86"
19+
echo set "CMAKE_GENERATOR=Visual Studio %VER% %YEAR%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
20+
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
21+
echo call "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
22+
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
23+
)
24+

conda/vs2022/install_runtime.bat

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
set VC_PATH=x86
2+
if "%ARCH%"=="64" (
3+
set VC_PATH=x64
4+
)
5+
6+
set MSC_VER=2022
7+
8+
rem :: This should always be present for VC installed with VS. Not sure about VC installed with Visual C++ Build Tools 2015
9+
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 (
10+
rem set SP=%%A
11+
rem )
12+
13+
rem if not "%SP%" == "%PKG_VERSION%" (
14+
rem echo "Version detected from registry: %SP%"
15+
rem echo "does not match version of package being built (%PKG_VERSION%)"
16+
rem echo "Do you have current updates for VS 2015 installed?"
17+
rem exit 1
18+
rem )
19+
20+
21+
REM ========== REQUIRES Win 10 SDK be installed, or files otherwise copied to location below!
22+
robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%LIBRARY_BIN%" *.dll /E
23+
robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%PREFIX%" *.dll /E
24+
if %ERRORLEVEL% GEQ 8 exit 1
25+
26+
REM ========== This one comes from visual studio 2022
27+
set "VC_VER=143"
28+
29+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [17^,18^) -property installationPath`) do (
30+
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
31+
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
32+
goto :eof
33+
)
34+
)
35+
36+
@setlocal
37+
call "%VS15VARSALL%" x64
38+
39+
set "REDIST_ROOT=%VCToolsRedistDir%%VC_PATH%"
40+
41+
robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%LIBRARY_BIN%" *.dll /E
42+
if %ERRORLEVEL% LSS 8 exit 0
43+
robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%PREFIX%" *.dll /E
44+
if %ERRORLEVEL% LSS 8 exit 0
45+
robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%LIBRARY_BIN%" *.dll /E
46+
if %ERRORLEVEL% LSS 8 exit 0
47+
robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%PREFIX%" *.dll /E
48+
if %ERRORLEVEL% LSS 8 exit 0
49+
@endlocal

conda/vs2022/meta.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% set vcver="17.4" %}
2+
{% set vcfeature="17" %}
3+
{% set vsyear="2022" %}
4+
{% set fullver="17.4.33110.190" %}
5+
6+
package:
7+
name: vs{{ vsyear }}
8+
version: {{ fullver }}
9+
10+
build:
11+
skip: True [not win]
12+
script_env:
13+
- VSDEVCMD_ARGS # [win]
14+
15+
outputs:
16+
- name: vs{{ vsyear }}_{{ cross_compiler_target_platform }}
17+
script: install_activate.bat
18+
track_features:
19+
# VS 2022 is binary-compatible with VS 2019/vc 14.2, VS 2017/vc 14.1 and 2015/vc14. Tools are "v143".
20+
strong:
21+
- vc{{ vcfeature }}
22+
about:
23+
summary: Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler
24+
license: BSD 3-clause

windows/internal/check_deps.bat

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

1919
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
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
24+
set VC_VERSION_LOWER=17
25+
set VC_VERSION_UPPER=18
2826
IF "%VC_YEAR%" == "2017" (
2927
set VC_VERSION_LOWER=15
3028
set VC_VERSION_UPPER=16
3129
)
30+
IF "%VC_YEAR%" == "2019" (
31+
set VC_VERSION_LOWER=16
32+
set VC_VERSION_UPPER=17
33+
)
3234

3335
if NOT "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" (
3436
set "VS15VCVARSALL=%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat"

windows/internal/cuda_install.bat

Lines changed: 5 additions & 2 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
@@ -143,6 +143,9 @@ if not exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION
143143
if "%VC_YEAR%" == "2019" (
144144
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"
145145
)
146+
if "%VC_YEAR%" == "2022" (
147+
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"
148+
)
146149

147150
echo Installing NvToolsExt...
148151
7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt"

windows/internal/env_fix.bat

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@
66
setlocal
77

88
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
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%" == "2017" (
16+
set VC_VERSION_LOWER=15
17+
set VC_VERSION_UPPER=16
18+
)
19+
IF "%VC_YEAR%" == "2019" (
20+
set VC_VERSION_LOWER=16
21+
set VC_VERSION_UPPER=17
22+
)
23+
24+
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 (
1425
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
1526
set "VS15INSTALLDIR=%%i"
1627
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
@@ -21,7 +32,7 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio
2132
:vswhere
2233

2334
IF "%VS15VCVARSALL%"=="" (
24-
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows
35+
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows
2536
exit /b 1
2637
)
2738

windows/internal/smoke_test.bat

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,26 @@ goto end
148148
echo "install and test libtorch"
149149

150150
if "%VC_YEAR%" == "2017" powershell internal\vs2017_install.ps1
151+
if "%VC_YEAR%" == "2019" powershell internal\vs2019_install.ps1
152+
if "%VC_YEAR%" == "2022" powershell internal\vs2022_install.ps1
153+
151154
if ERRORLEVEL 1 exit /b 1
152155

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

156159
pushd tmp\libtorch
157160

158-
set VC_VERSION_LOWER=16
159-
set VC_VERSION_UPPER=17
161+
set VC_VERSION_LOWER=17
162+
set VC_VERSION_UPPER=18
160163
IF "%VC_YEAR%" == "2017" (
161164
set VC_VERSION_LOWER=15
162165
set VC_VERSION_UPPER=16
163166
)
167+
IF "%VC_YEAR%" == "2019" (
168+
set VC_VERSION_LOWER=16
169+
set VC_VERSION_UPPER=17
170+
)
164171

165172
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 (
166173
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
@@ -172,7 +179,7 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio
172179

173180
:vswhere
174181
IF "%VS15VCVARSALL%"=="" (
175-
echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch test on Windows
182+
echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch test on Windows
176183
exit /b 1
177184
)
178185
call "%VS15VCVARSALL%" x64

windows/internal/vc_install_helper.bat

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

3-
set VC_VERSION_LOWER=16
4-
set VC_VERSION_UPPER=17
5+
set VC_VERSION_LOWER=17
6+
set VC_VERSION_UPPER=18
7+
IF "%VC_YEAR%" == "2017" (
8+
set VC_VERSION_LOWER=15
9+
set VC_VERSION_UPPER=16
10+
)
11+
IF "%VC_YEAR%" == "2019" (
12+
set VC_VERSION_LOWER=16
13+
set VC_VERSION_UPPER=17
14+
)
515

616
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 (
717
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (

windows/internal/vs2022_install.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# https://developercommunity.visualstudio.com/t/install-specific-version-of-vs-component/1142479
2+
# https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history#evergreen-bootstrappers
3+
4+
# 17.4.3 BuildTools
5+
$VS_DOWNLOAD_LINK = "https://download.visualstudio.microsoft.com/download/pr/8f480125-28b8-4a2c-847c-c2b02a8cdd1b/64be21d4ada005d7d07896ed0b004c322409bd04d6e8eba4c03c9fa39c928e7a/vs_BuildTools.exe"
6+
$COLLECT_DOWNLOAD_LINK = "https://aka.ms/vscollect.exe"
7+
$VS_INSTALL_ARGS = @("--nocache","--quiet","--wait", "--add Microsoft.VisualStudio.Workload.VCTools",
8+
"--add Microsoft.Component.MSBuild",
9+
"--add Microsoft.VisualStudio.Component.Roslyn.Compiler",
10+
"--add Microsoft.VisualStudio.Component.TextTemplating",
11+
"--add Microsoft.VisualStudio.Component.VC.CoreIde",
12+
"--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
13+
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
14+
"--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
15+
"--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81")
16+
17+
curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe
18+
if ($LASTEXITCODE -ne 0) {
19+
echo "Download of the VS $VC_YEAR Version $VS_VERSION installer failed"
20+
exit 1
21+
}
22+
23+
if (Test-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe") {
24+
$existingPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products "Microsoft.VisualStudio.Product.BuildTools" -version "[17, 18)" -property installationPath
25+
if ($existingPath -ne $null) {
26+
if (!${env:CIRCLECI}) {
27+
echo "Found correctly versioned existing BuildTools installation in $existingPath"
28+
exit 0
29+
}
30+
echo "Found existing BuildTools installation in $existingPath"
31+
$VS_UNINSTALL_ARGS = @("uninstall", "--installPath", "`"$existingPath`"", "--quiet","--wait")
32+
$process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_UNINSTALL_ARGS -NoNewWindow -Wait -PassThru
33+
$exitCode = $process.ExitCode
34+
if (($exitCode -ne 0) -and ($exitCode -ne 3010)) {
35+
echo "Original BuildTools uninstall failed with code $exitCode"
36+
exit 1
37+
}
38+
echo "Original BuildTools uninstalled"
39+
}
40+
}
41+
42+
$process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_INSTALL_ARGS -NoNewWindow -Wait -PassThru
43+
Remove-Item -Path vs_installer.exe -Force
44+
$exitCode = $process.ExitCode
45+
if (($exitCode -ne 0) -and ($exitCode -ne 3010)) {
46+
echo "VS $VC_YEAR installer exited with code $exitCode, which should be one of [0, 3010]."
47+
curl.exe --retry 3 -kL $COLLECT_DOWNLOAD_LINK --output Collect.exe
48+
if ($LASTEXITCODE -ne 0) {
49+
echo "Download of the VS Collect tool failed."
50+
exit 1
51+
}
52+
Start-Process "${PWD}\Collect.exe" -NoNewWindow -Wait -PassThru
53+
New-Item -Path "C:\w\build-results" -ItemType "directory" -Force
54+
Copy-Item -Path "C:\Users\circleci\AppData\Local\Temp\vslogs.zip" -Destination "C:\w\build-results\"
55+
exit 1
56+
}

0 commit comments

Comments
 (0)