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,18 +24,23 @@ 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)
gcc_ = writeScriptBin "g++" '' $(declare -xp | sed -e '/^[^=]\+="\('"''${NIX_STORE//\//\\/}"'\|[^\/]\)/!d')
#!${stdenv.shell} declare -x NIX_BUILD_TOP="${buildTop}"
export NIX_CC_WRAPPER_${stdenv.cc.infixSalt}_TARGET_HOST=1 $(type -P '${command}') "\$@"
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${toString extraFlags}" EOF
exec ${gcc}/bin/g++ "$@" chmod +x "$out"
''; '';
# Theano spews warnings and disabled flags if the compiler isn't named g++
cxx_compiler = wrapped "g++" "\\$HOME/.theano"
( stdenv.lib.optional cudaSupport libgpuarray_
++ stdenv.lib.optional cudnnSupport cudnn );
libgpuarray_ = libgpuarray.override { inherit cudaSupport cudatoolkit; }; libgpuarray_ = libgpuarray.override { inherit cudaSupport cudatoolkit; };
in buildPythonPackage rec { in buildPythonPackage rec {
@ -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 \