lol
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 gfortran,
6 blas,
7 lapack,
8 metis,
9 fixDarwinDylibNames,
10 gmp,
11 mpfr,
12 config,
13 enableCuda ? config.cudaSupport,
14 cudaPackages,
15 openmp ? null,
16}@inputs:
17
18let
19 stdenv = throw "Use effectiveStdenv instead";
20 effectiveStdenv = if enableCuda then cudaPackages.backendStdenv else inputs.stdenv;
21in
22effectiveStdenv.mkDerivation rec {
23 pname = "suitesparse";
24 version = "5.13.0";
25
26 outputs = [
27 "out"
28 "dev"
29 "doc"
30 ];
31
32 src = fetchFromGitHub {
33 owner = "DrTimothyAldenDavis";
34 repo = "SuiteSparse";
35 rev = "v${version}";
36 sha256 = "sha256-Anen1YtXsSPhk8DpA4JtADIz9m8oXFl9umlkb4iImf8=";
37 };
38
39 nativeBuildInputs =
40 [
41 ]
42 ++ lib.optionals effectiveStdenv.hostPlatform.isDarwin [
43 fixDarwinDylibNames
44 ]
45 ++ lib.optionals enableCuda [
46 cudaPackages.cuda_nvcc
47 ];
48
49 # Use compatible indexing for lapack and blas used
50 buildInputs =
51 assert (blas.isILP64 == lapack.isILP64);
52 [
53 blas
54 lapack
55 metis
56 (lib.getLib gfortran.cc)
57 gmp
58 mpfr
59 ]
60 ++ lib.optionals effectiveStdenv.cc.isClang [
61 openmp
62 ]
63 ++ lib.optionals enableCuda [
64 cudaPackages.cuda_cudart
65 cudaPackages.cuda_cccl
66 cudaPackages.libcublas
67 ];
68
69 preConfigure = ''
70 # Mongoose and GraphBLAS are packaged separately
71 sed -i "Makefile" -e '/GraphBLAS\|Mongoose/d'
72 '';
73
74 makeFlags =
75 [
76 "INSTALL=${placeholder "out"}"
77 "INSTALL_INCLUDE=${placeholder "dev"}/include"
78 "JOBS=$(NIX_BUILD_CORES)"
79 "MY_METIS_LIB=-lmetis"
80 ]
81 ++ lib.optionals blas.isILP64 [
82 "CFLAGS=-DBLAS64"
83 ]
84 ++ lib.optionals enableCuda [
85 "CUDA_PATH=${cudaPackages.cuda_nvcc}"
86 "CUDART_LIB=${lib.getLib cudaPackages.cuda_cudart}/lib/libcudart.so"
87 "CUBLAS_LIB=${lib.getLib cudaPackages.libcublas}/lib/libcublas.so"
88 ]
89 ++ lib.optionals effectiveStdenv.hostPlatform.isDarwin [
90 # Unless these are set, the build will attempt to use `Accelerate` on darwin, see:
91 # https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/v5.13.0/SuiteSparse_config/SuiteSparse_config.mk#L368
92 "BLAS=-lblas"
93 "LAPACK=-llapack"
94 ];
95
96 env =
97 {
98 # in GCC14 these two warnings were promoted to error
99 # let's make them warnings again to fix the build failure
100 NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration -Wno-error=incompatible-pointer-types";
101 }
102 // lib.optionalAttrs effectiveStdenv.hostPlatform.isDarwin {
103 # Ensure that there is enough space for the `fixDarwinDylibNames` hook to
104 # update the install names of the output dylibs.
105 NIX_LDFLAGS = "-headerpad_max_install_names";
106 };
107
108 buildFlags = [
109 # Build individual shared libraries, not demos
110 "library"
111 ];
112
113 meta = with lib; {
114 homepage = "http://faculty.cse.tamu.edu/davis/suitesparse.html";
115 description = "Suite of sparse matrix algorithms";
116 license = with licenses; [
117 bsd2
118 gpl2Plus
119 lgpl21Plus
120 ];
121 maintainers = with maintainers; [ ttuegel ];
122 platforms = with platforms; unix;
123 };
124}