Theano: get theano to use a captured build environment

This commit is contained in:
Tyson Whitehead 2018-08-02 15:20:24 -04:00
parent 8413a541d5
commit 303a3f972e
No known key found for this signature in database
GPG Key ID: B22199763A27997B

View File

@ -1,8 +1,8 @@
{ stdenv { stdenv
, runCommandCC
, lib , lib
, fetchPypi , fetchPypi
, gcc , gcc
, writeScriptBin
, buildPythonPackage , buildPythonPackage
, isPyPy , isPyPy
, pythonOlder , pythonOlder
@ -24,17 +24,22 @@ assert cudaSupport -> nvidia_x11 != null
&& cudnn != null; && cudnn != null;
let let
extraFlags = wrapped = command: buildTop: buildInputs:
lib.optionals cudaSupport [ "-I ${cudatoolkit}/include" "-L ${cudatoolkit}/lib" ] runCommandCC "${command}-wrapped" { inherit buildInputs; } ''
++ lib.optionals cudnnSupport [ "-I ${cudnn}/include" "-L ${cudnn}/lib" ] type -P '${command}' || { echo '${command}: not found'; exit 1; }
++ lib.optionals cudaSupport [ "-I ${libgpuarray}/include" "-L ${libgpuarray}/lib" ]; cat > "$out" <<EOF
#!$(type -P bash)
$(declare -xp | sed -e '/^[^=]\+="\('"''${NIX_STORE//\//\\/}"'\|[^\/]\)/!d')
declare -x NIX_BUILD_TOP="${buildTop}"
$(type -P '${command}') "\$@"
EOF
chmod +x "$out"
'';
gcc_ = writeScriptBin "g++" '' # Theano spews warnings and disabled flags if the compiler isn't named g++
#!${stdenv.shell} cxx_compiler = wrapped "g++" "\\$HOME/.theano"
export NIX_CC_WRAPPER_${stdenv.cc.infixSalt}_TARGET_HOST=1 ( stdenv.lib.optional cudaSupport libgpuarray_
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${toString extraFlags}" ++ stdenv.lib.optional cudnnSupport cudnn );
exec ${gcc}/bin/g++ "$@"
'';
libgpuarray_ = libgpuarray.override { inherit cudaSupport cudatoolkit; }; libgpuarray_ = libgpuarray.override { inherit cudaSupport cudatoolkit; };
@ -51,7 +56,7 @@ in buildPythonPackage rec {
postPatch = '' postPatch = ''
substituteInPlace theano/configdefaults.py \ substituteInPlace theano/configdefaults.py \
--replace 'StrParam(param, is_valid=warn_cxx)' 'StrParam('\'''${gcc_}/bin/g++'\''', is_valid=warn_cxx)' \ --replace 'StrParam(param, is_valid=warn_cxx)' 'StrParam('\'''${cxx_compiler}'\''', is_valid=warn_cxx)' \
--replace 'rc == 0 and config.cxx != ""' 'config.cxx != ""' --replace 'rc == 0 and config.cxx != ""' 'config.cxx != ""'
'' + stdenv.lib.optionalString cudaSupport '' '' + stdenv.lib.optionalString cudaSupport ''
substituteInPlace theano/configdefaults.py \ substituteInPlace theano/configdefaults.py \