From 5f3864f7d8693e6481ced8b509b1c977d1d16e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Barto=C5=88?= Date: Mon, 7 Nov 2022 13:03:56 +0100 Subject: [PATCH 1/3] Build Windows binaries with Visual Studio 2022 Build Tools --- conda/vs2022/activate.bat | 51 +++++++++++++++++++++++ conda/vs2022/conda_build_config.yaml | 24 +++++++++++ conda/vs2022/install_activate.bat | 24 +++++++++++ conda/vs2022/install_runtime.bat | 49 ++++++++++++++++++++++ conda/vs2022/meta.yaml | 24 +++++++++++ windows/internal/check_deps.bat | 12 +++--- windows/internal/cuda_install.bat | 7 +++- windows/internal/env_fix.bat | 17 ++++++-- windows/internal/smoke_test.bat | 13 ++++-- windows/internal/vc_install_helper.bat | 14 ++++++- windows/internal/vs2022_install.ps1 | 56 ++++++++++++++++++++++++++ windows/internal/vs_install.bat | 8 ++-- 12 files changed, 280 insertions(+), 19 deletions(-) create mode 100644 conda/vs2022/activate.bat create mode 100644 conda/vs2022/conda_build_config.yaml create mode 100644 conda/vs2022/install_activate.bat create mode 100644 conda/vs2022/install_runtime.bat create mode 100644 conda/vs2022/meta.yaml create mode 100644 windows/internal/vs2022_install.ps1 diff --git a/conda/vs2022/activate.bat b/conda/vs2022/activate.bat new file mode 100644 index 000000000..00228ec48 --- /dev/null +++ b/conda/vs2022/activate.bat @@ -0,0 +1,51 @@ +:: Set env vars that tell distutils to use the compiler that we put on path +SET DISTUTILS_USE_SDK=1 +SET MSSdk=1 + +SET "VS_VERSION=17.4" +SET "VS_MAJOR=17" +SET "VC_YEAR=2022" +SET "VC_VERSION_LOWER=17" +set "VC_VERSION_UPPER=18" + +set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out" +set "MSYS2_ENV_CONV_EXCL=CL" + +:: For Python 3.5+, ensure that we link with the dynamic runtime. See +:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info +set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime143.dll" + +if NOT "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VSINSTALLDIR=%VS15INSTALLDIR%\" + goto :vswhere +) + +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 ( + if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VSINSTALLDIR=%%i\" + goto :vswhere + ) +) + +:vswhere + +:: Shorten PATH to avoid the `input line too long` error. +SET MyPath=%PATH% + +setlocal EnableDelayedExpansion + +SET TempPath="%MyPath:;=";"%" +SET var= +FOR %%a IN (%TempPath%) DO ( + IF EXIST %%~sa ( + SET "var=!var!;%%~sa" + ) +) + +set "TempPath=!var:~1!" +endlocal & set "PATH=%TempPath%" + +:: Shorten current directory too +FOR %%A IN (.) DO CD "%%~sA" + +:: other things added by install_activate.bat at package build time diff --git a/conda/vs2022/conda_build_config.yaml b/conda/vs2022/conda_build_config.yaml new file mode 100644 index 000000000..41808f7af --- /dev/null +++ b/conda/vs2022/conda_build_config.yaml @@ -0,0 +1,24 @@ +blas_impl: + - mkl # [x86_64] +c_compiler: + - vs2022 # [win] +cxx_compiler: + - vs2022 # [win] +python: + - 3.5 + - 3.6 +# This differs from target_platform in that it determines what subdir the compiler +# will target, not what subdir the compiler package will be itself. +# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32 +# code on win-64 miniconda. +cross_compiler_target_platform: + - win-64 # [win] +target_platform: + - win-64 # [win] +vc: + - 14 +zip_keys: + - # [win] + - vc # [win] + - c_compiler # [win] + - cxx_compiler # [win] diff --git a/conda/vs2022/install_activate.bat b/conda/vs2022/install_activate.bat new file mode 100644 index 000000000..eb85767d6 --- /dev/null +++ b/conda/vs2022/install_activate.bat @@ -0,0 +1,24 @@ +set YEAR=2022 +set VER=17 + +mkdir "%PREFIX%\etc\conda\activate.d" +copy "%RECIPE_DIR%\activate.bat" "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + +if "%cross_compiler_target_platform%" == "win-64" ( + set "target_platform=amd64" + echo set "CMAKE_GENERATOR=Visual Studio %VER% %YEAR% Win64" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + if "%VSDEVCMD_ARGS%" == "" ( + echo call "VC\Auxiliary\Build\vcvarsall.bat" x64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + ) else ( + echo call "VC\Auxiliary\Build\vcvarsall.bat" x64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + ) + echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" +) else ( + set "target_platform=x86" + echo set "CMAKE_GENERATOR=Visual Studio %VER% %YEAR%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo call "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" + echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" +) + diff --git a/conda/vs2022/install_runtime.bat b/conda/vs2022/install_runtime.bat new file mode 100644 index 000000000..bac684dae --- /dev/null +++ b/conda/vs2022/install_runtime.bat @@ -0,0 +1,49 @@ +set VC_PATH=x86 +if "%ARCH%"=="64" ( + set VC_PATH=x64 +) + +set MSC_VER=2022 + +rem :: This should always be present for VC installed with VS. Not sure about VC installed with Visual C++ Build Tools 2015 +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 ( +rem set SP=%%A +rem ) + +rem if not "%SP%" == "%PKG_VERSION%" ( +rem echo "Version detected from registry: %SP%" +rem echo "does not match version of package being built (%PKG_VERSION%)" +rem echo "Do you have current updates for VS 2015 installed?" +rem exit 1 +rem ) + + +REM ========== REQUIRES Win 10 SDK be installed, or files otherwise copied to location below! +robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%LIBRARY_BIN%" *.dll /E +robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%PREFIX%" *.dll /E +if %ERRORLEVEL% GEQ 8 exit 1 + +REM ========== This one comes from visual studio 2022 +set "VC_VER=143" + +for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [17^,18^) -property installationPath`) do ( + if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( + set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" + goto :eof + ) +) + +@setlocal +call "%VS15VARSALL%" x64 + +set "REDIST_ROOT=%VCToolsRedistDir%%VC_PATH%" + +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%LIBRARY_BIN%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%PREFIX%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%LIBRARY_BIN%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%PREFIX%" *.dll /E +if %ERRORLEVEL% LSS 8 exit 0 +@endlocal diff --git a/conda/vs2022/meta.yaml b/conda/vs2022/meta.yaml new file mode 100644 index 000000000..184c4c32d --- /dev/null +++ b/conda/vs2022/meta.yaml @@ -0,0 +1,24 @@ +{% set vcver="17.4" %} +{% set vcfeature="17" %} +{% set vsyear="2022" %} +{% set fullver="17.4.33110.190" %} + +package: + name: vs{{ vsyear }} + version: {{ fullver }} + +build: + skip: True [not win] + script_env: + - VSDEVCMD_ARGS # [win] + +outputs: + - name: vs{{ vsyear }}_{{ cross_compiler_target_platform }} + script: install_activate.bat + track_features: + # VS 2022 is binary-compatible with VS 2019/vc 14.2, VS 2017/vc 14.1 and 2015/vc14. Tools are "v143". + strong: + - vc{{ vcfeature }} + about: + summary: Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler + license: BSD 3-clause diff --git a/windows/internal/check_deps.bat b/windows/internal/check_deps.bat index 25c4c4a51..2502af289 100755 --- a/windows/internal/check_deps.bat +++ b/windows/internal/check_deps.bat @@ -17,18 +17,20 @@ IF "%BUILD_VISION%" == "" ( ) IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows + echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows exit /b 1 ) -IF "%VC_YEAR%" == "" set VC_YEAR=2019 - -set VC_VERSION_LOWER=16 -set VC_VERSION_UPPER=17 +set VC_VERSION_LOWER=17 +set VC_VERSION_UPPER=18 IF "%VC_YEAR%" == "2017" ( set VC_VERSION_LOWER=15 set VC_VERSION_UPPER=16 ) +IF "%VC_YEAR%" == "2019" ( + set VC_VERSION_LOWER=16 + set VC_VERSION_UPPER=17 +) if NOT "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" ( set "VS15VCVARSALL=%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" diff --git a/windows/internal/cuda_install.bat b/windows/internal/cuda_install.bat index 33a2679d5..f31de8649 100644 --- a/windows/internal/cuda_install.bat +++ b/windows/internal/cuda_install.bat @@ -17,7 +17,7 @@ set CUDNN_FOLDER="cuda" set CUDNN_LIB_FOLDER="lib\x64" :: Skip all of this if we already have cuda installed -if exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" goto set_cuda_env_vars +if exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" goto set_cuda_env_vars if %CUDA_VER% EQU 116 goto cuda116 if %CUDA_VER% EQU 117 goto cuda117 @@ -112,7 +112,7 @@ goto cuda_common :: With GHA runners these should be pre-installed as part of our AMI process :: If you cannot find the CUDA version you want to build for here then please :: add it @ https://github.com/pytorch/test-infra/tree/main/aws/ami/windows -if not exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" ( +if not exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_STR%\bin\nvcc.exe" ( if not exist "%SRC_DIR%\temp_build\NvToolsExt.7z" ( curl -k -L https://ossci-windows.s3.us-east-1.amazonaws.com/builder/NvToolsExt.7z --output "%SRC_DIR%\temp_build\NvToolsExt.7z" if errorlevel 1 exit /b 1 @@ -143,6 +143,9 @@ if not exist "C:\\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION if "%VC_YEAR%" == "2019" ( 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" ) + if "%VC_YEAR%" == "2022" ( + 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" + ) echo Installing NvToolsExt... 7z x %SRC_DIR%\temp_build\NvToolsExt.7z -o"%SRC_DIR%\temp_build\NvToolsExt" diff --git a/windows/internal/env_fix.bat b/windows/internal/env_fix.bat index dd0aaf5f2..d988ed496 100644 --- a/windows/internal/env_fix.bat +++ b/windows/internal/env_fix.bat @@ -6,11 +6,22 @@ setlocal IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows + echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows exit /b 1 ) -for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do ( +set VC_VERSION_LOWER=17 +set VC_VERSION_UPPER=18 +IF "%VC_YEAR%" == "2017" ( + set VC_VERSION_LOWER=15 + set VC_VERSION_UPPER=16 +) +IF "%VC_YEAR%" == "2019" ( + set VC_VERSION_LOWER=16 + set VC_VERSION_UPPER=17 +) + +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 ( if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( set "VS15INSTALLDIR=%%i" set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" @@ -21,7 +32,7 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio :vswhere IF "%VS15VCVARSALL%"=="" ( - echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch on Windows + echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows exit /b 1 ) diff --git a/windows/internal/smoke_test.bat b/windows/internal/smoke_test.bat index 5b8ffbbcd..7d1c4ade7 100644 --- a/windows/internal/smoke_test.bat +++ b/windows/internal/smoke_test.bat @@ -148,6 +148,9 @@ goto end echo "install and test libtorch" if "%VC_YEAR%" == "2017" powershell internal\vs2017_install.ps1 +if "%VC_YEAR%" == "2019" powershell internal\vs2019_install.ps1 +if "%VC_YEAR%" == "2022" powershell internal\vs2022_install.ps1 + if ERRORLEVEL 1 exit /b 1 for /F "delims=" %%i in ('where /R "%PYTORCH_FINAL_PACKAGE_DIR:/=\%" *-latest.zip') do 7z x "%%i" -otmp @@ -155,12 +158,16 @@ if ERRORLEVEL 1 exit /b 1 pushd tmp\libtorch -set VC_VERSION_LOWER=16 -set VC_VERSION_UPPER=17 +set VC_VERSION_LOWER=17 +set VC_VERSION_UPPER=18 IF "%VC_YEAR%" == "2017" ( set VC_VERSION_LOWER=15 set VC_VERSION_UPPER=16 ) +IF "%VC_YEAR%" == "2019" ( + set VC_VERSION_LOWER=16 + set VC_VERSION_UPPER=17 +) 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 ( 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 :vswhere IF "%VS15VCVARSALL%"=="" ( - echo Visual Studio 2017 C++ BuildTools is required to compile PyTorch test on Windows + echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch test on Windows exit /b 1 ) call "%VS15VCVARSALL%" x64 diff --git a/windows/internal/vc_install_helper.bat b/windows/internal/vc_install_helper.bat index 6a2a0e0d9..cf4d4bbaa 100644 --- a/windows/internal/vc_install_helper.bat +++ b/windows/internal/vc_install_helper.bat @@ -1,7 +1,17 @@ +if "%VC_YEAR%" == "2017" powershell windows/internal/vs2017_install.ps1 if "%VC_YEAR%" == "2019" powershell windows/internal/vs2019_install.ps1 +if "%VC_YEAR%" == "2022" powershell windows/internal/vs2022_install.ps1 -set VC_VERSION_LOWER=16 -set VC_VERSION_UPPER=17 +set VC_VERSION_LOWER=17 +set VC_VERSION_UPPER=18 +IF "%VC_YEAR%" == "2017" ( + set VC_VERSION_LOWER=15 + set VC_VERSION_UPPER=16 +) +IF "%VC_YEAR%" == "2019" ( + set VC_VERSION_LOWER=16 + set VC_VERSION_UPPER=17 +) 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 ( if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( diff --git a/windows/internal/vs2022_install.ps1 b/windows/internal/vs2022_install.ps1 new file mode 100644 index 000000000..55fba4737 --- /dev/null +++ b/windows/internal/vs2022_install.ps1 @@ -0,0 +1,56 @@ +# https://developercommunity.visualstudio.com/t/install-specific-version-of-vs-component/1142479 +# https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history#evergreen-bootstrappers + +# 17.4.3 BuildTools +$VS_DOWNLOAD_LINK = "https://download.visualstudio.microsoft.com/download/pr/8f480125-28b8-4a2c-847c-c2b02a8cdd1b/64be21d4ada005d7d07896ed0b004c322409bd04d6e8eba4c03c9fa39c928e7a/vs_BuildTools.exe" +$COLLECT_DOWNLOAD_LINK = "https://aka.ms/vscollect.exe" +$VS_INSTALL_ARGS = @("--nocache","--quiet","--wait", "--add Microsoft.VisualStudio.Workload.VCTools", + "--add Microsoft.Component.MSBuild", + "--add Microsoft.VisualStudio.Component.Roslyn.Compiler", + "--add Microsoft.VisualStudio.Component.TextTemplating", + "--add Microsoft.VisualStudio.Component.VC.CoreIde", + "--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest", + "--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core", + "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64", + "--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81") + +curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe +if ($LASTEXITCODE -ne 0) { + echo "Download of the VS $VC_YEAR Version $VS_VERSION installer failed" + exit 1 +} + +if (Test-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe") { + $existingPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products "Microsoft.VisualStudio.Product.BuildTools" -version "[17, 18)" -property installationPath + if ($existingPath -ne $null) { + if (!${env:CIRCLECI}) { + echo "Found correctly versioned existing BuildTools installation in $existingPath" + exit 0 + } + echo "Found existing BuildTools installation in $existingPath" + $VS_UNINSTALL_ARGS = @("uninstall", "--installPath", "`"$existingPath`"", "--quiet","--wait") + $process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_UNINSTALL_ARGS -NoNewWindow -Wait -PassThru + $exitCode = $process.ExitCode + if (($exitCode -ne 0) -and ($exitCode -ne 3010)) { + echo "Original BuildTools uninstall failed with code $exitCode" + exit 1 + } + echo "Original BuildTools uninstalled" + } +} + +$process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_INSTALL_ARGS -NoNewWindow -Wait -PassThru +Remove-Item -Path vs_installer.exe -Force +$exitCode = $process.ExitCode +if (($exitCode -ne 0) -and ($exitCode -ne 3010)) { + echo "VS $VC_YEAR installer exited with code $exitCode, which should be one of [0, 3010]." + curl.exe --retry 3 -kL $COLLECT_DOWNLOAD_LINK --output Collect.exe + if ($LASTEXITCODE -ne 0) { + echo "Download of the VS Collect tool failed." + exit 1 + } + Start-Process "${PWD}\Collect.exe" -NoNewWindow -Wait -PassThru + New-Item -Path "C:\w\build-results" -ItemType "directory" -Force + Copy-Item -Path "C:\Users\circleci\AppData\Local\Temp\vslogs.zip" -Destination "C:\w\build-results\" + exit 1 +} diff --git a/windows/internal/vs_install.bat b/windows/internal/vs_install.bat index 624227f0b..221ec3313 100644 --- a/windows/internal/vs_install.bat +++ b/windows/internal/vs_install.bat @@ -1,12 +1,12 @@ @echo off -set VS_DOWNLOAD_LINK=https://aka.ms/vs/15/release/vs_buildtools.exe +set VS_DOWNLOAD_LINK=https://download.visualstudio.microsoft.com/download/pr/8f480125-28b8-4a2c-847c-c2b02a8cdd1b/64be21d4ada005d7d07896ed0b004c322409bd04d6e8eba4c03c9fa39c928e7a/vs_BuildTools.exe IF "%VS_LATEST%" == "1" ( set VS_INSTALL_ARGS= --nocache --norestart --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools set VSDEVCMD_ARGS= ) ELSE ( set VS_INSTALL_ARGS=--nocache --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools ^ - --add Microsoft.VisualStudio.Component.VC.Tools.14.11 ^ + --add Microsoft.VisualStudio.Component.VC.Tools.14.34 ^ --add Microsoft.Component.MSBuild ^ --add Microsoft.VisualStudio.Component.Roslyn.Compiler ^ --add Microsoft.VisualStudio.Component.TextTemplating ^ @@ -14,9 +14,9 @@ IF "%VS_LATEST%" == "1" ( --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^ --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core ^ --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^ - --add Microsoft.VisualStudio.Component.VC.Tools.14.11 ^ + --add Microsoft.VisualStudio.Component.VC.Tools.14.34 ^ --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 - set VSDEVCMD_ARGS=-vcvars_ver=14.11 + set VSDEVCMD_ARGS=-vcvars_ver=14.34 ) curl -k -L %VS_DOWNLOAD_LINK% --output vs_installer.exe From 3d208f357946b267163be0fd745429321cb39113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Barto=C5=88?= Date: Thu, 5 Jan 2023 12:08:16 +0100 Subject: [PATCH 2/3] Unify casing in Batch files, remove VS 2017 installation --- windows/internal/check_deps.bat | 8 ++------ windows/internal/cuda_install.bat | 3 --- windows/internal/env_fix.bat | 10 +++------ windows/internal/smoke_test.bat | 5 ----- windows/internal/vc_install_helper.bat | 7 +------ windows/internal/vs2017_install.ps1 | 28 -------------------------- 6 files changed, 6 insertions(+), 55 deletions(-) delete mode 100644 windows/internal/vs2017_install.ps1 diff --git a/windows/internal/check_deps.bat b/windows/internal/check_deps.bat index 2502af289..5e1f58e35 100755 --- a/windows/internal/check_deps.bat +++ b/windows/internal/check_deps.bat @@ -16,18 +16,14 @@ IF "%BUILD_VISION%" == "" ( ) ) -IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( +if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows exit /b 1 ) set VC_VERSION_LOWER=17 set VC_VERSION_UPPER=18 -IF "%VC_YEAR%" == "2017" ( - set VC_VERSION_LOWER=15 - set VC_VERSION_UPPER=16 -) -IF "%VC_YEAR%" == "2019" ( +if "%VC_YEAR%" == "2019" ( set VC_VERSION_LOWER=16 set VC_VERSION_UPPER=17 ) diff --git a/windows/internal/cuda_install.bat b/windows/internal/cuda_install.bat index f31de8649..fc281bed0 100644 --- a/windows/internal/cuda_install.bat +++ b/windows/internal/cuda_install.bat @@ -137,9 +137,6 @@ if not exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v%CUDA_VERSION_ popd echo Installing VS integration... - if "%VC_YEAR%" == "2017" ( - 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" - ) if "%VC_YEAR%" == "2019" ( 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" ) diff --git a/windows/internal/env_fix.bat b/windows/internal/env_fix.bat index d988ed496..2a53198a9 100644 --- a/windows/internal/env_fix.bat +++ b/windows/internal/env_fix.bat @@ -5,18 +5,14 @@ setlocal -IF NOT EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( +if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows exit /b 1 ) set VC_VERSION_LOWER=17 set VC_VERSION_UPPER=18 -IF "%VC_YEAR%" == "2017" ( - set VC_VERSION_LOWER=15 - set VC_VERSION_UPPER=16 -) -IF "%VC_YEAR%" == "2019" ( +if "%VC_YEAR%" == "2019" ( set VC_VERSION_LOWER=16 set VC_VERSION_UPPER=17 ) @@ -31,7 +27,7 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio :vswhere -IF "%VS15VCVARSALL%"=="" ( +if "%VS15VCVARSALL%"=="" ( echo Visual Studio %VC_YEAR% C++ BuildTools is required to compile PyTorch on Windows exit /b 1 ) diff --git a/windows/internal/smoke_test.bat b/windows/internal/smoke_test.bat index 7d1c4ade7..8ec4d076f 100644 --- a/windows/internal/smoke_test.bat +++ b/windows/internal/smoke_test.bat @@ -147,7 +147,6 @@ goto end :libtorch echo "install and test libtorch" -if "%VC_YEAR%" == "2017" powershell internal\vs2017_install.ps1 if "%VC_YEAR%" == "2019" powershell internal\vs2019_install.ps1 if "%VC_YEAR%" == "2022" powershell internal\vs2022_install.ps1 @@ -160,10 +159,6 @@ pushd tmp\libtorch set VC_VERSION_LOWER=17 set VC_VERSION_UPPER=18 -IF "%VC_YEAR%" == "2017" ( - set VC_VERSION_LOWER=15 - set VC_VERSION_UPPER=16 -) IF "%VC_YEAR%" == "2019" ( set VC_VERSION_LOWER=16 set VC_VERSION_UPPER=17 diff --git a/windows/internal/vc_install_helper.bat b/windows/internal/vc_install_helper.bat index cf4d4bbaa..61ab6d5f8 100644 --- a/windows/internal/vc_install_helper.bat +++ b/windows/internal/vc_install_helper.bat @@ -1,14 +1,9 @@ -if "%VC_YEAR%" == "2017" powershell windows/internal/vs2017_install.ps1 if "%VC_YEAR%" == "2019" powershell windows/internal/vs2019_install.ps1 if "%VC_YEAR%" == "2022" powershell windows/internal/vs2022_install.ps1 set VC_VERSION_LOWER=17 set VC_VERSION_UPPER=18 -IF "%VC_YEAR%" == "2017" ( - set VC_VERSION_LOWER=15 - set VC_VERSION_UPPER=16 -) -IF "%VC_YEAR%" == "2019" ( +if "%VC_YEAR%" == "2019" ( set VC_VERSION_LOWER=16 set VC_VERSION_UPPER=17 ) diff --git a/windows/internal/vs2017_install.ps1 b/windows/internal/vs2017_install.ps1 deleted file mode 100644 index 873e4eb17..000000000 --- a/windows/internal/vs2017_install.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -$VS_DOWNLOAD_LINK = "https://aka.ms/vs/15/release/vs_buildtools.exe" -$VS_INSTALL_ARGS = @("--nocache","--quiet","--wait", "--add Microsoft.VisualStudio.Workload.VCTools", - "--add Microsoft.Component.MSBuild", - "--add Microsoft.VisualStudio.Component.Roslyn.Compiler", - "--add Microsoft.VisualStudio.Component.TextTemplating", - "--add Microsoft.VisualStudio.Component.VC.CoreIde", - "--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest", - "--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core", - "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64", - "--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81") - -if ($args.Count -ne 0) { - $VS_INSTALL_ARGS += "--add Microsoft.VisualStudio.Component.VC.Tools.$($args[0])" -} - -curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe -if ($LASTEXITCODE -ne 0) { - echo "Download of the VS 2017 installer failed" - exit 1 -} - -$process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_INSTALL_ARGS -NoNewWindow -Wait -PassThru -Remove-Item -Path vs_installer.exe -Force -$exitCode = $process.ExitCode -if (($exitCode -ne 0) -and ($exitCode -ne 3010)) { - echo "VS 2017 installer exited with code $exitCode, which should be one of [0, 3010]." - exit 1 -} From 35ad942ec598c55f148ebf538a9d2691f1418322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Barto=C5=88?= Date: Thu, 5 Jan 2023 12:51:50 +0100 Subject: [PATCH 3/3] Remove VS 2017 Conda scripts, unify casing in conda Batch scripts, minor Conda scripts tweaks --- conda/vs2017/activate.bat | 44 ------------------------- conda/vs2017/conda_build_config.yaml | 24 -------------- conda/vs2017/install_activate.bat | 24 -------------- conda/vs2017/install_runtime.bat | 49 ---------------------------- conda/vs2017/meta.yaml | 24 -------------- conda/vs2022/activate.bat | 28 ++++++++-------- conda/vs2022/conda_build_config.yaml | 5 +-- 7 files changed, 17 insertions(+), 181 deletions(-) delete mode 100755 conda/vs2017/activate.bat delete mode 100755 conda/vs2017/conda_build_config.yaml delete mode 100755 conda/vs2017/install_activate.bat delete mode 100755 conda/vs2017/install_runtime.bat delete mode 100755 conda/vs2017/meta.yaml diff --git a/conda/vs2017/activate.bat b/conda/vs2017/activate.bat deleted file mode 100755 index ccecfc254..000000000 --- a/conda/vs2017/activate.bat +++ /dev/null @@ -1,44 +0,0 @@ -:: Set env vars that tell distutils to use the compiler that we put on path -SET DISTUTILS_USE_SDK=1 -SET MSSdk=1 - -SET "VS_VERSION=15.0" -SET "VS_MAJOR=15" -SET "VS_YEAR=2017" - -set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out" -set "MSYS2_ENV_CONV_EXCL=CL" - -:: For Python 3.5+, ensure that we link with the dynamic runtime. See -:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info -set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime140.dll" - -for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do ( - if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( - set "VSINSTALLDIR=%%i\" - goto :vswhere - ) -) - -:vswhere - -:: Shorten PATH to avoid the `input line too long` error. -SET MyPath=%PATH% - -setlocal EnableDelayedExpansion - -SET TempPath="%MyPath:;=";"%" -SET var= -FOR %%a IN (%TempPath%) DO ( - IF EXIST %%~sa ( - SET "var=!var!;%%~sa" - ) -) - -set "TempPath=!var:~1!" -endlocal & set "PATH=%TempPath%" - -:: Shorten current directory too -FOR %%A IN (.) DO CD "%%~sA" - -:: other things added by install_activate.bat at package build time diff --git a/conda/vs2017/conda_build_config.yaml b/conda/vs2017/conda_build_config.yaml deleted file mode 100755 index 5188bb0eb..000000000 --- a/conda/vs2017/conda_build_config.yaml +++ /dev/null @@ -1,24 +0,0 @@ -blas_impl: - - mkl # [x86_64] -c_compiler: - - vs2017 # [win] -cxx_compiler: - - vs2017 # [win] -python: - - 3.5 - - 3.6 -# This differs from target_platform in that it determines what subdir the compiler -# will target, not what subdir the compiler package will be itself. -# For example, we need a win-64 vs2008_win-32 package, so that we compile win-32 -# code on win-64 miniconda. -cross_compiler_target_platform: - - win-64 # [win] -target_platform: - - win-64 # [win] -vc: - - 14 -zip_keys: - - # [win] - - vc # [win] - - c_compiler # [win] - - cxx_compiler # [win] diff --git a/conda/vs2017/install_activate.bat b/conda/vs2017/install_activate.bat deleted file mode 100755 index 2ca223ebc..000000000 --- a/conda/vs2017/install_activate.bat +++ /dev/null @@ -1,24 +0,0 @@ -set YEAR=2017 -set VER=15 - -mkdir "%PREFIX%\etc\conda\activate.d" -copy "%RECIPE_DIR%\activate.bat" "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - -if "%cross_compiler_target_platform%" == "win-64" ( - set "target_platform=amd64" - echo set "CMAKE_GENERATOR=Visual Studio %VER% %YEAR% Win64" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - if "%VSDEVCMD_ARGS%" == "" ( - echo call "VC\Auxiliary\Build\vcvarsall.bat" x64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - ) else ( - echo call "VC\Auxiliary\Build\vcvarsall.bat" x64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - ) - echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" -) else ( - set "target_platform=x86" - echo set "CMAKE_GENERATOR=Visual Studio %VER% %YEAR%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - echo call "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" - echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat" -) - diff --git a/conda/vs2017/install_runtime.bat b/conda/vs2017/install_runtime.bat deleted file mode 100755 index 5163c16cf..000000000 --- a/conda/vs2017/install_runtime.bat +++ /dev/null @@ -1,49 +0,0 @@ -set VC_PATH=x86 -if "%ARCH%"=="64" ( - set VC_PATH=x64 -) - -set MSC_VER=2017 - -rem :: This should always be present for VC installed with VS. Not sure about VC installed with Visual C++ Build Tools 2015 -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 ( -rem set SP=%%A -rem ) - -rem if not "%SP%" == "%PKG_VERSION%" ( -rem echo "Version detected from registry: %SP%" -rem echo "does not match version of package being built (%PKG_VERSION%)" -rem echo "Do you have current updates for VS 2015 installed?" -rem exit 1 -rem ) - - -REM ========== REQUIRES Win 10 SDK be installed, or files otherwise copied to location below! -robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%LIBRARY_BIN%" *.dll /E -robocopy "C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\%VC_PATH%" "%PREFIX%" *.dll /E -if %ERRORLEVEL% GEQ 8 exit 1 - -REM ========== This one comes from visual studio 2017 -set "VC_VER=141" - -for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [15^,16^) -property installationPath`) do ( - if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" ( - set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat" - goto :eof - ) -) - -@setlocal -call "%VS15VARSALL%" x64 - -set "REDIST_ROOT=%VCToolsRedistDir%%VC_PATH%" - -robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%LIBRARY_BIN%" *.dll /E -if %ERRORLEVEL% LSS 8 exit 0 -robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.CRT" "%PREFIX%" *.dll /E -if %ERRORLEVEL% LSS 8 exit 0 -robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%LIBRARY_BIN%" *.dll /E -if %ERRORLEVEL% LSS 8 exit 0 -robocopy "%REDIST_ROOT%\Microsoft.VC%VC_VER%.OpenMP" "%PREFIX%" *.dll /E -if %ERRORLEVEL% LSS 8 exit 0 -@endlocal diff --git a/conda/vs2017/meta.yaml b/conda/vs2017/meta.yaml deleted file mode 100755 index 1f569525e..000000000 --- a/conda/vs2017/meta.yaml +++ /dev/null @@ -1,24 +0,0 @@ -{% set vcver="14.1" %} -{% set vcfeature="14" %} -{% set vsyear="2017" %} -{% set fullver="15.4.27004.2010" %} - -package: - name: vs{{ vsyear }} - version: {{ fullver }} - -build: - skip: True [not win] - script_env: - - VSDEVCMD_ARGS # [win] - -outputs: - - name: vs{{ vsyear }}_{{ cross_compiler_target_platform }} - script: install_activate.bat - track_features: - # VS 2017 is binary-compatible with VS 2015/vc14. Tools are "v141". - strong: - - vc{{ vcfeature }} - about: - summary: Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler - license: BSD 3-clause diff --git a/conda/vs2022/activate.bat b/conda/vs2022/activate.bat index 00228ec48..fe18f7723 100644 --- a/conda/vs2022/activate.bat +++ b/conda/vs2022/activate.bat @@ -1,11 +1,11 @@ :: Set env vars that tell distutils to use the compiler that we put on path -SET DISTUTILS_USE_SDK=1 -SET MSSdk=1 +set DISTUTILS_USE_SDK=1 +set MSSdk=1 -SET "VS_VERSION=17.4" -SET "VS_MAJOR=17" -SET "VC_YEAR=2022" -SET "VC_VERSION_LOWER=17" +set "VS_VERSION=17.4" +set "VS_MAJOR=17" +set "VC_YEAR=2022" +set "VC_VERSION_LOWER=17" set "VC_VERSION_UPPER=18" set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out" @@ -15,7 +15,7 @@ set "MSYS2_ENV_CONV_EXCL=CL" :: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime143.dll" -if NOT "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" ( +if not "%VS15INSTALLDIR%" == "" if exist "%VS15INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" ( set "VSINSTALLDIR=%VS15INSTALLDIR%\" goto :vswhere ) @@ -30,15 +30,15 @@ for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio :vswhere :: Shorten PATH to avoid the `input line too long` error. -SET MyPath=%PATH% +set MyPath=%PATH% setlocal EnableDelayedExpansion -SET TempPath="%MyPath:;=";"%" -SET var= -FOR %%a IN (%TempPath%) DO ( - IF EXIST %%~sa ( - SET "var=!var!;%%~sa" +set TempPath="%MyPath:;=";"%" +set var= +for %%a in (%TempPath%) do ( + if exist %%~sa ( + set "var=!var!;%%~sa" ) ) @@ -46,6 +46,6 @@ set "TempPath=!var:~1!" endlocal & set "PATH=%TempPath%" :: Shorten current directory too -FOR %%A IN (.) DO CD "%%~sA" +for %%A in (.) do cd "%%~sA" :: other things added by install_activate.bat at package build time diff --git a/conda/vs2022/conda_build_config.yaml b/conda/vs2022/conda_build_config.yaml index 41808f7af..e2a4de3c2 100644 --- a/conda/vs2022/conda_build_config.yaml +++ b/conda/vs2022/conda_build_config.yaml @@ -5,8 +5,9 @@ c_compiler: cxx_compiler: - vs2022 # [win] python: - - 3.5 - - 3.6 + - 3.8 + - 3.9 + - 3.10 # This differs from target_platform in that it determines what subdir the compiler # will target, not what subdir the compiler package will be itself. # For example, we need a win-64 vs2008_win-32 package, so that we compile win-32