Skip to content

Commit

Permalink
Merge pull request #52 from jaimergp-feedstocks/fix-version-check
Browse files Browse the repository at this point in the history
[Windows] Freeze PKG_VERSION and add fallback lookup in default installation path
  • Loading branch information
Keith Kraus authored Dec 11, 2020
2 parents 91b12e8 + 3e32155 commit 198ee4b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
5 changes: 4 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "nvcc" %}
{% set number = 8 %}
{% set number = 9 %}

package:
name: "{{ name }}"
Expand All @@ -22,6 +22,8 @@ outputs:
- cudatoolkit {{ cuda_compiler_version }}|{{ cuda_compiler_version }}.*
- __glibc >=2.17 # [linux and cuda_compiler_version == "11.0"]
requirements:
build: # [win]
- m2-sed # [win]
host:
# Needed to symlink libcuda into sysroot libs.
- {{ compiler("c") }}
Expand Down Expand Up @@ -63,3 +65,4 @@ extra:
- kkraus14
- mike-wendt
- raydouglass
- jaimergp
42 changes: 27 additions & 15 deletions recipe/windows/activate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@ if defined CXXFLAGS (
set "CXXFLAGS_CONDA_NVCC_BACKUP=%CXXFLAGS%"
)

:: Default to using nvcc.exe to specify %CUDA_HOME%
:: Default to using nvcc.exe to specify %CUDA_PATH%
:: Things we try:
:: 1) CUDA_PATH might be defined already in the env, use it in that case
:: 2) Try to locate nvcc.exe in PATH and calculate CUDA_PATH from there (two levels up)
:: 3) Look if nvcc.exe can be found in the default CUDA installation path and calculate CUDA_PATH from there (two levels up)

:: Try (1)
if not defined CUDA_PATH (
for /f "usebackq tokens=*" %%a in (`where nvcc.exe`) do set "CUDA_NVCC_EXECUTABLE=%%a" || goto :error
:: Try (2)
for /f "usebackq tokens=*" %%a in (`where nvcc.exe`) do set "CUDA_NVCC_EXECUTABLE=%%a"
if "%CUDA_NVCC_EXECUTABLE%"=="" (
echo "Cannot determine CUDA_PATH: nvcc.exe not in PATH"
exit /b 1
:: Try (3)
if exist "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v__PKG_VERSION__\bin\nvcc.exe" (
set "CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v__PKG_VERSION__"
) else (
echo "Cannot determine CUDA_PATH: nvcc.exe not in PATH or default location..."
exit /b 1
)
) else (
for /f "usebackq tokens=*" %%a in (`python -c "from pathlib import Path; print(Path('%CUDA_NVCC_EXECUTABLE%').parents[1])"`) do set "CUDA_PATH=%%a" || goto :error
)
Expand All @@ -38,16 +50,16 @@ if not exist "%CUDA_PATH%\" (
exit /b 1
)

@REM if not exist "%CUDA_PATH%\lib\x64\cuda.lib" (
@REM echo "File '%CUDA_PATH%\lib\x64\cuda.lib' doesn't exist"
@REM exit /b 1
@REM )
if not exist "%CUDA_PATH%\lib\x64\cuda.lib" (
echo "File '%CUDA_PATH%\lib\x64\cuda.lib' doesn't exist"
exit /b 1
)

findstr /c:"CUDA Version %PKG_VERSION%" "%CUDA_PATH%\version.txt"
findstr /C:"CUDA Version __PKG_VERSION__" "%CUDA_PATH%\version.txt"
if errorlevel 1 (
:: CUDA 11 does not package a version.txt, so maybe it failed due to
:: that. Let's double check with the output of nvcc.exe --version
"%CUDA_PATH%\bin\nvcc.exe" --version | findstr /C:"release %PKG_VERSION%"
"%CUDA_PATH%\bin\nvcc.exe" --version | findstr /C:"release __PKG_VERSION__"
if errorlevel 1 (
echo "Version of installed CUDA didn't match package or could not be determined."
exit /b 1
Expand All @@ -65,15 +77,15 @@ set "CXXFLAGS=%CXXFLAGS% -I%CUDA_HOME%\include"
:: Stub is used to avoid getting driver code linked into binaries.

:: Make a backup of `cuda.lib` if it exists -- we make sure this is the case in install_nvcc.bat
if exist %LIBRARY_LIB%\cuda.lib (
set "LIBCUDA_SO_CONDA_NVCC_BACKUP=%LIBRARY_LIB%\cuda.lib-conda-nvcc-backup"
ren "%LIBRARY_LIB%\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%"
if exist "%CONDA_PREFIX%\Library\lib\cuda.lib" (
set "LIBCUDA_SO_CONDA_NVCC_BACKUP=%CONDA_PREFIX%\Library\lib\cuda.lib-conda-nvcc-backup"
ren "%CONDA_PREFIX%\Library\lib\cuda.lib" "%LIBCUDA_SO_CONDA_NVCC_BACKUP%"
)

mkdir %LIBRARY_LIB%
mkdir "%CONDA_PREFIX%\Library\lib"
:: symlinking requires admin access or developer mode ON
:: we fallback to a standard copy if mklink fails
mklink "%LIBRARY_LIB%\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "%LIBRARY_LIB%\cuda.lib"
mklink "%CONDA_PREFIX%\Library\lib\cuda.lib" "%CUDA_HOME%\lib\x64\cuda.lib" || copy "%CUDA_HOME%\lib\x64\cuda.lib" "%CONDA_PREFIX%\Library\lib\cuda.lib"
if errorlevel 1 (
echo "Could not create link nor fallback copy"
exit /b 1
Expand Down
8 changes: 4 additions & 4 deletions recipe/windows/deactivate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ if not "%CXXFLAGS_CONDA_NVCC_BACKUP%"=="" (
)

:: Remove or restore `cuda.lib` from the compiler sysroot.
set "CUDALIB_CONDA_NVCC_BACKUP=%LIBRARY_LIB%\cuda.lib-conda-nvcc-backup"
set "CUDALIB_CONDA_NVCC_BACKUP=%CONDA_PREFIX%\Library\lib\cuda.lib-conda-nvcc-backup"
if exist "%CUDALIB_CONDA_NVCC_BACKUP%" (
ren "%CUDALIB_CONDA_NVCC_BACKUP%" "%LIBRARY_LIB%\cuda.lib"
ren "%CUDALIB_CONDA_NVCC_BACKUP%" "%CONDA_PREFIX%\Library\lib\cuda.lib"
) else (
:: We shouldn't need this because we did create an empty one just in case
del "%LIBRARY_LIB%\cuda.lib"
del "%CONDA_PREFIX%\Library\lib\cuda.lib"
if errorlevel 1 (
echo Could not remove link/copy of `cuda.lib`!
echo Could not remove `cuda.lib` stub!
exit /b 1
)
)
2 changes: 2 additions & 0 deletions recipe/windows/install_nvcc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ setlocal enableextensions enabledelayedexpansion || goto :error

:: Activation script
mkdir %PREFIX%\etc\conda\activate.d
:: Render conda-build env vars
sed -i "s/__PKG_VERSION__/%PKG_VERSION%/g" %RECIPE_DIR%\windows\activate.bat
copy %RECIPE_DIR%\windows\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat || goto :error

:: Deactivation script
Expand Down
14 changes: 7 additions & 7 deletions recipe/windows/test_nvcc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ if "%CFLAGS%"=="%CFLAGS_CONDA_NVCC_TEST%" (
echo "CFLAGS is incorrectly set to '%CFLAGS%', should be set to '%CFLAGS_CONDA_NVCC_TEST%'"
exit 1
)
@REM :: If no previous cuda.lib was present, there shouldn't be any!
@REM if "%CUDALIB_CONDA_NVCC_BACKUP%" == "" (
@REM if exist "%LIBRARY_LIB%\cuda.lib" (
@REM echo "%LIBRARY_LIB%\cuda.lib" should not exist!
@REM exit 1
@REM )
@REM )
:: If no previous cuda.lib was present, there shouldn't be any!
if "%CUDALIB_CONDA_NVCC_BACKUP%" == "" (
if exist "%LIBRARY_LIB%\cuda.lib" (
echo "%LIBRARY_LIB%\cuda.lib" should not exist!
exit 1
)
)

:: Reactivate
call %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat
Expand Down

1 comment on commit 198ee4b

@conda-forge-linter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! This is the friendly automated conda-forge-webservice.

I updated the Github team because of this commit.

  • @jaimergp was added to this feedstock maintenance team.

You should get push access to this feedstock and CI services.

Feel free to join the community chat room.

NOTE: Please make sure to not push to the repository directly.
Use branches in your fork for any changes and send a PR.
More details here

Please sign in to comment.