about summary refs log tree commit diff
path: root/pkgs/development/libraries
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2020-03-11 03:24:33 +0100
committerJan Tojnar <jtojnar@gmail.com>2020-03-11 03:45:25 +0100
commitb552b84ae29628b2574da116b9736e90f12485df (patch)
treee1a06bad7ccd77be75bc83a810fe270849a53b72 /pkgs/development/libraries
parentc16d5b6534321ee0495e1e42fcc1b7e0baa06b62 (diff)
downloadnixlib-b552b84ae29628b2574da116b9736e90f12485df.tar
nixlib-b552b84ae29628b2574da116b9736e90f12485df.tar.gz
nixlib-b552b84ae29628b2574da116b9736e90f12485df.tar.bz2
nixlib-b552b84ae29628b2574da116b9736e90f12485df.tar.lz
nixlib-b552b84ae29628b2574da116b9736e90f12485df.tar.xz
nixlib-b552b84ae29628b2574da116b9736e90f12485df.tar.zst
nixlib-b552b84ae29628b2574da116b9736e90f12485df.zip
suitesparse: ultimate clean-up
* Switch to default buildPhase & installPhase
* In preConfigure
	* Do not add -DNPARTITION to CHOLMOD_CONFIG. That would disable the use of Metis but we already have that.
	* Do not remove -lrt on Darwin, Darwin compiler can handle that and the code no longer exists anyway.
	* With CUDA enabled
		* Do not replace CUDA_ROOT. It does not exist any more. Instead we are setting CUDA_PATH in makeFlags.
		* Do not replace GPU_BLAS_PATH, it defaults to CUDA_PATH so it will end up with the same value.
		* Do not add -DCHOLMOD_OMP_NUM_THREADS to GPU_CONFIG. Why would be having the library use the same number of threads as the builder a good idea?
		* Do not replace CUDA_PATH, we are setting it in makeFlags now.
		* Do not replace CUDART_LIB and CUBLAS_LIB. They were being replaced incorrectly (cuda libs are located in lib directory, not lib64). Instead set the correct paths in makeFlags.
		* Do not replace CUDA_INC_PATH. Its default looks like it will end up with the same value.
		* Do not replace NV20, NV30, NV35 – not used any more.
		* Do not replace NVCC, defaults to the same.
		* Do not replace NVCCFLAGS, we just used the default from SourceSparse 4.4.7 with -gencode=arch=compute_60,code=compute_60 tacked on top. Current upstream default looks much better.
* Stop adding -DNTIMER to CFLAGS on Darwin – clock_gettime is supported by macOS 10.12 SDK.
* In buildPhase
	* Move the make arguments to makeFlags and library to buildFlags, allowing us to drop the manual make call. I did not verify all of these are still needed.
	* Remove the creation of libsuitesparse.so. As far as I could tell it is some kind of remnant of our old expression – perhaps due to past deficiencies of the build scripts, we created the individual libraries as symlinks to libsuitesparse.so: https://github.com/NixOS/nixpkgs/commit/e36b3ec0a56c3b06152a205a46804733b88695d6 But since the build script can now build individual .so libraries, there should be no need for this abomination. No other distros do this either.
* In installPhase
	* No need to copy things manually, there is an install target. We just need to pass INSTALL=$out flag to make to let it know where to install the files.
	* I do not have means of verifying the darwin dylib name fix but it looks like it might be fixed in an upcoming release.
	* I dropped the rpath fixup as it does not seem to be needed any more (ldd does not report any unresolved libraries).
Diffstat (limited to 'pkgs/development/libraries')
-rw-r--r--pkgs/development/libraries/science/math/suitesparse/default.nix102
1 files changed, 23 insertions, 79 deletions
diff --git a/pkgs/development/libraries/science/math/suitesparse/default.nix b/pkgs/development/libraries/science/math/suitesparse/default.nix
index 4eb3264b2af2..f4adafd0f387 100644
--- a/pkgs/development/libraries/science/math/suitesparse/default.nix
+++ b/pkgs/development/libraries/science/math/suitesparse/default.nix
@@ -33,80 +33,33 @@ stdenv.mkDerivation rec {
   ] ++ stdenv.lib.optional enableCuda cudatoolkit;
 
   preConfigure = ''
-    mkdir -p $out/lib
-    mkdir -p $dev/include
-    mkdir -p $doc/share/doc/${pname}-${version}
-
     # Mongoose and GraphBLAS are packaged separately
     sed -i "Makefile" -e '/GraphBLAS\|Mongoose/d'
-
-    sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
-        -e '/CHOLMOD_CONFIG ?=/ s/$/ -DNPARTITION/'
-  ''
-  + stdenv.lib.optionalString stdenv.isDarwin ''
-    sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
-        -e 's/^[[:space:]]*\(LIB = -lm\) -lrt/\1/'
-  ''
-  + stdenv.lib.optionalString enableCuda ''
-    sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
-        -e 's|^[[:space:]]*\(CUDA_ROOT     =\)|CUDA_ROOT = ${cudatoolkit}|' \
-        -e 's|^[[:space:]]*\(GPU_BLAS_PATH =\)|GPU_BLAS_PATH = $(CUDA_ROOT)|' \
-        -e 's|^[[:space:]]*\(GPU_CONFIG    =\)|GPU_CONFIG = -I$(CUDA_ROOT)/include -DGPU_BLAS -DCHOLMOD_OMP_NUM_THREADS=$(NIX_BUILD_CORES) |' \
-        -e 's|^[[:space:]]*\(CUDA_PATH     =\)|CUDA_PATH = $(CUDA_ROOT)|' \
-        -e 's|^[[:space:]]*\(CUDART_LIB    =\)|CUDART_LIB = $(CUDA_ROOT)/lib64/libcudart.so|' \
-        -e 's|^[[:space:]]*\(CUBLAS_LIB    =\)|CUBLAS_LIB = $(CUDA_ROOT)/lib64/libcublas.so|' \
-        -e 's|^[[:space:]]*\(CUDA_INC_PATH =\)|CUDA_INC_PATH = $(CUDA_ROOT)/include/|' \
-        -e 's|^[[:space:]]*\(NV20          =\)|NV20 = -arch=sm_20 -Xcompiler -fPIC|' \
-        -e 's|^[[:space:]]*\(NV30          =\)|NV30 = -arch=sm_30 -Xcompiler -fPIC|' \
-        -e 's|^[[:space:]]*\(NV35          =\)|NV35 = -arch=sm_35 -Xcompiler -fPIC|' \
-        -e 's|^[[:space:]]*\(NVCC          =\) echo|NVCC = $(CUDA_ROOT)/bin/nvcc|' \
-        -e 's|^[[:space:]]*\(NVCCFLAGS     =\)|NVCCFLAGS = $(NV20) -O3 -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_60,code=sm_60|'
-  '';
-
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-DNTIMER";
-
-  buildPhase = ''
-    runHook preBuild
-
-    # Build individual shared libraries
-    make library        \
-        JOBS=$NIX_BUILD_CORES \
-        BLAS=-lopenblas \
-        MY_METIS_LIB=-lmetis \
-        LAPACK=""       \
-        ${stdenv.lib.optionalString openblas.blas64 "CFLAGS=-DBLAS64"}
-
-    # Build libsuitesparse.so which bundles all the individual libraries.
-    # Bundling is done by building the static libraries, extracting objects from
-    # them and combining the objects into one shared library.
-    mkdir -p static
-    make static JOBS=$NIX_BUILD_CORES \
-        MY_METIS_LIB=-lmetis \
-        AR_TARGET=$(pwd)/static/'$(LIBRARY).a'
-    (
-        cd static
-        for i in lib*.a; do
-          ar -x $i
-        done
-    )
-    ${if enableCuda then "${cudatoolkit}/bin/nvcc" else "${stdenv.cc.outPath}/bin/cc"} \
-        static/*.o                                                                     \
-        ${if stdenv.isDarwin then "-dynamiclib" else "--shared"}                       \
-        -o "lib/libsuitesparse${stdenv.hostPlatform.extensions.sharedLibrary}"         \
-        -lopenblas                                                                     \
-        ${stdenv.lib.optionalString enableCuda "-lcublas"}
-
-    runHook postBuild
   '';
 
-  installPhase = ''
-    runHook preInstall
-
-    cp -r lib $out/
-    cp -r include $dev/
-    cp -r share $doc/
-  ''
-  + stdenv.lib.optionalString stdenv.isDarwin ''
+  makeFlags = [
+    "INSTALL=${placeholder "out"}"
+    "INSTALL_INCLUDE=${placeholder "dev"}/include"
+    "JOBS=$(NIX_BUILD_CORES)"
+    "BLAS=-lopenblas"
+    "MY_METIS_LIB=-lmetis"
+    "LAPACK="
+  ] ++ stdenv.lib.optionals openblas.blas64 [
+    "CFLAGS=-DBLAS64"
+  ] ++ stdenv.lib.optionals enableCuda [
+    "CUDA_PATH=${cudatoolkit}"
+    "CUDART_LIB=${cudatoolkit.lib}/lib/libcudart.so"
+    "CUBLAS_LIB=${cudatoolkit}/lib/libcublas.so"
+  ];
+
+  buildFlags = [
+    # Build individual shared libraries, not demos
+    "library"
+  ];
+
+  # Likely fixed after 5.7.1
+  # https://github.com/DrTimothyAldenDavis/SuiteSparse/commit/f6daae26ee391e475e2295e77c839aa7c1a8b784
+  postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
     # The fixDarwinDylibNames in nixpkgs can't seem to fix all the libraries.
     # We manually fix them up here.
     fixDarwinDylibNames() {
@@ -125,15 +78,6 @@ stdenv.mkDerivation rec {
     }
 
     fixDarwinDylibNames $(find "$out" -name "*.dylib")
-  ''
-  + stdenv.lib.optionalString (!stdenv.isDarwin) ''
-    # Fix rpaths
-    cd $out
-    find -name \*.so\* -type f -exec \
-      patchelf --set-rpath "$out/lib:${stdenv.lib.makeLibraryPath buildInputs}" {} \;
-  ''
-  + ''
-    runHook postInstall
   '';
 
   meta = with stdenv.lib; {