about summary refs log tree commit diff
path: root/pkgs/development/python-modules/Theano
diff options
context:
space:
mode:
authorTyson Whitehead <twhitehead@gmail.com>2018-08-02 15:20:24 -0400
committerTyson Whitehead <twhitehead@gmail.com>2018-08-02 15:23:22 -0400
commit303a3f972eabd1eda0b3fbd4051d31d258402ad3 (patch)
tree4915148bd00ecf22aebb8b028a2ada23b857c97b /pkgs/development/python-modules/Theano
parent8413a541d524268412d2d88822c376b3b1eb6f36 (diff)
Theano: get theano to use a captured build environment
Diffstat (limited to 'pkgs/development/python-modules/Theano')
-rw-r--r--pkgs/development/python-modules/Theano/default.nix29
1 files changed, 17 insertions, 12 deletions
diff --git a/pkgs/development/python-modules/Theano/default.nix b/pkgs/development/python-modules/Theano/default.nix
index 4341302f33a9e..793488f0b1369 100644
--- a/pkgs/development/python-modules/Theano/default.nix
+++ b/pkgs/development/python-modules/Theano/default.nix
@@ -1,8 +1,8 @@
 { stdenv
+, runCommandCC
 , lib
 , fetchPypi
 , gcc
-, writeScriptBin
 , buildPythonPackage
 , isPyPy
 , pythonOlder
@@ -24,17 +24,22 @@ assert cudaSupport -> nvidia_x11 != null
                    && cudnn != null;
 
 let
-  extraFlags =
-    lib.optionals cudaSupport [ "-I ${cudatoolkit}/include" "-L ${cudatoolkit}/lib" ]
-    ++ lib.optionals cudnnSupport [ "-I ${cudnn}/include" "-L ${cudnn}/lib" ]
-    ++ lib.optionals cudaSupport [ "-I ${libgpuarray}/include" "-L ${libgpuarray}/lib" ];
+  wrapped = command: buildTop: buildInputs:
+    runCommandCC "${command}-wrapped" { inherit buildInputs; } ''
+      type -P '${command}' || { echo '${command}: not found'; exit 1; }
+      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++" ''
-    #!${stdenv.shell}
-    export NIX_CC_WRAPPER_${stdenv.cc.infixSalt}_TARGET_HOST=1
-    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${toString extraFlags}"
-    exec ${gcc}/bin/g++ "$@"
-  '';
+  # 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; };
 
@@ -51,7 +56,7 @@ in buildPythonPackage rec {
 
   postPatch = ''
     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 != ""'
   '' + stdenv.lib.optionalString cudaSupport ''
     substituteInPlace theano/configdefaults.py \