Skip to content

Commit 937c83a

Browse files
peterjc123fmassa
authored andcommitted
[wip] try vs2019 toolchain (#1509)
* Try vs2019 toolchain * ver num * pass env var * fix search logic * Support both VS2017 and VS2019 * Some small fixes
1 parent f46f2c1 commit 937c83a

File tree

8 files changed

+211
-3
lines changed

8 files changed

+211
-3
lines changed

packaging/build_conda.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ setup_env 0.5.0
99
export SOURCE_ROOT_DIR="$PWD"
1010
setup_conda_pytorch_constraint
1111
setup_conda_cudatoolkit_constraint
12+
setup_visual_studio_constraint
1213
conda build $CONDA_CHANNEL_FLAGS -c defaults -c conda-forge --no-anaconda-upload --python "$PYTHON_VERSION" packaging/torchvision

packaging/conda/build_vision.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,16 @@ for py_ver in "${DESIRED_PYTHON[@]}"; do
157157
rm -rf "$output_folder"
158158
mkdir "$output_folder"
159159

160+
export VSTOOLCHAIN_PACKAGE=vs2017
161+
160162
# We need to build the compiler activation scripts first on Windows
161163
time VSDEVCMD_ARGS=${VSDEVCMD_ARGS[@]} \
162164
conda build -c "$ANACONDA_USER" \
163165
--no-anaconda-upload \
164166
--output-folder "$output_folder" \
165-
../vs2017
167+
../$VSTOOLCHAIN_PACKAGE
168+
169+
cp ../$VSTOOLCHAIN_PACKAGE/conda_build_config.yaml ../torchvision/conda_build_config.yaml
166170

167171
conda config --set anaconda_upload no
168172
echo "Calling conda-build at $(date)"

packaging/pkg_helpers.bash

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ setup_conda_pytorch_constraint() {
199199
export CONDA_CHANNEL_FLAGS="-c pytorch-nightly"
200200
export PYTORCH_VERSION="$(conda search --json 'pytorch[channel=pytorch-nightly]' | \
201201
python -c "import os, sys, json, re; cuver = os.environ.get('CU_VERSION'); \
202-
cuver = (cuver[:-1] + '.' + cuver[-1]).replace('cu', 'cuda') if cuver != 'cpu' else cuver; \
202+
cuver_1 = cuver.replace('cu', 'cuda') if cuver != 'cpu' else cuver; \
203+
cuver_2 = (cuver[:-1] + '.' + cuver[-1]).replace('cu', 'cuda') if cuver != 'cpu' else cuver; \
203204
print(re.sub(r'\\+.*$', '', \
204205
[x['version'] for x in json.load(sys.stdin)['pytorch'] \
205-
if (x['platform'] == 'darwin' or cuver in x['fn']) \
206+
if (x['platform'] == 'darwin' or cuver_1 in x['fn'] or cuver_2 in x['fn']) \
206207
and 'py' + os.environ['PYTHON_VERSION'] in x['fn']][-1]))")"
207208
if [[ -z "$PYTORCH_VERSION" ]]; then
208209
echo "PyTorch version auto detection failed"
@@ -248,3 +249,13 @@ setup_conda_cudatoolkit_constraint() {
248249
esac
249250
fi
250251
}
252+
253+
# Build the proper compiler package before building the final package
254+
setup_visual_studio_constraint() {
255+
if [[ "$OSTYPE" == "msys" ]]; then
256+
export VSTOOLCHAIN_PACKAGE=vs2019
257+
export VSDEVCMD_ARGS=''
258+
conda build $CONDA_CHANNEL_FLAGS --no-anaconda-upload packaging/$VSTOOLCHAIN_PACKAGE
259+
cp packaging/$VSTOOLCHAIN_PACKAGE/conda_build_config.yaml packaging/torchvision/conda_build_config.yaml
260+
fi
261+
}

packaging/vs2019/activate.bat

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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=16.0"
6+
SET "VS_MAJOR=16"
7+
SET "VS_YEAR=2019"
8+
9+
set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out"
10+
set "MSYS2_ENV_CONV_EXCL=CL"
11+
12+
:: For Python 3.5+, ensure that we link with the dynamic runtime. See
13+
:: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ for more info
14+
set "PY_VCRUNTIME_REDIST=%PREFIX%\\bin\\vcruntime140.dll"
15+
16+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [16^,17^) -property installationPath`) do (
17+
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
18+
set "VSINSTALLDIR=%%i\"
19+
goto :vswhere
20+
)
21+
)
22+
23+
:vswhere
24+
25+
:: Shorten PATH to avoid the `input line too long` error.
26+
SET MyPath=%PATH%
27+
28+
setlocal EnableDelayedExpansion
29+
30+
SET TempPath="%MyPath:;=";"%"
31+
SET var=
32+
FOR %%a IN (%TempPath%) DO (
33+
IF EXIST %%~sa (
34+
SET "var=!var!;%%~sa"
35+
)
36+
)
37+
38+
set "TempPath=!var:~1!"
39+
endlocal & set "PATH=%TempPath%"
40+
41+
:: Shorten current directory too
42+
FOR %%A IN (.) DO CD "%%~sA"
43+
44+
:: other things added by install_activate.bat at package build time
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+
- vs2019 # [win]
5+
cxx_compiler:
6+
- vs2019 # [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]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
set YEAR=2019
2+
set VER=16
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+
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
14+
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
15+
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
16+
) ELSE (
17+
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
18+
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
19+
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
20+
echo CALL "VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 %VSDEVCMD_ARGS% >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
21+
)
22+
echo popd >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
23+
) else (
24+
set "target_platform=x86"
25+
echo SET "CMAKE_GENERATOR=Visual Studio %VER% %YEAR%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
26+
echo pushd "%%VSINSTALLDIR%%" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
27+
echo CALL "VC\Auxiliary\Build\vcvars32.bat" >> "%PREFIX%\etc\conda\activate.d\vs%YEAR%_compiler_vars.bat"
28+
echo popd
29+
)
30+
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=2019
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 2019
27+
set "VC_VER=142"
28+
29+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [16^,17^) -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

packaging/vs2019/meta.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% set vcver="14.2" %}
2+
{% set vcfeature="14" %}
3+
{% set vsyear="2019" %}
4+
{% set fullver="15.4.27004.2010" %}
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 2019 is binary-compatible with VS 2017/vc 14.1 and 2015/vc14. Tools are "v142".
20+
strong:
21+
- vc{{ vcfeature }}
22+
run_exports:
23+
- vc {{ vcver }}
24+
about:
25+
summary: Activation and version verification of MSVC {{ vcver }} (VS {{ vsyear }}) compiler
26+
license: BSD 3-clause
27+
- name: vs{{ vsyear }}_runtime
28+
script: install_runtime.bat
29+
- name: vc
30+
version: {{ vcver }}
31+
track_features:
32+
- vc{{ vcfeature }}
33+
requirements:
34+
run:
35+
- {{ pin_subpackage('vs' ~ vsyear ~ '_runtime') }}
36+
about:
37+
home: https://github.com/conda/conda/wiki/VC-features
38+
license: Modified BSD License (3-clause)
39+
license_family: BSD
40+
summary: A meta-package to track VC features.
41+
description: |
42+
This metapackage is used to activate vc features without
43+
depending on Python.
44+
doc_url: https://github.com/conda/conda/wiki/VC-features
45+
dev_url: https://github.com/conda/conda/wiki/VC-features

0 commit comments

Comments
 (0)