From 2f215b76aeda958c64130fe4f2805e8e754d988f Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Fri, 27 Dec 2024 22:14:47 -0800 Subject: [PATCH] arpack: add option to use macOS Accelerate Copy darwin flags `-ff2c -fno-second-underscore` from workflow to use Accelerate without segfaulting / failing tests and enable the Accelerate framework when `useAccel` is true. https://github.com/opencollab/arpack-ng/blob/804fa3149a0f773064198a8e883bd021832157ca/.github/workflows/jobs.yml#L184-L192 --- pkgs/by-name/ar/arpack/package.nix | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/ar/arpack/package.nix b/pkgs/by-name/ar/arpack/package.nix index 3023e9a3e9b5..4e059b3ea95c 100644 --- a/pkgs/by-name/ar/arpack/package.nix +++ b/pkgs/by-name/ar/arpack/package.nix @@ -4,11 +4,13 @@ , mpi , openssh , igraph +, useAccel ? false #use Accelerate framework on darwin }: # MPI version can only be built with LP64 interface. # See https://github.com/opencollab/arpack-ng#readme assert useMpi -> !blas.isILP64; +assert useAccel -> stdenv.hostPlatform.isDarwin; stdenv.mkDerivation rec { pname = "arpack"; @@ -22,11 +24,11 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ cmake gfortran ninja ]; - buildInputs = assert (blas.isILP64 == lapack.isILP64); [ - blas - lapack + buildInputs = [ eigen - ] ++ lib.optional useMpi mpi; + ] ++ lib.optionals (!useAccel) (assert (blas.isILP64 == lapack.isILP64); [ + blas lapack + ]) ++ lib.optional useMpi mpi; nativeCheckInputs = lib.optional useMpi openssh; @@ -34,21 +36,26 @@ stdenv.mkDerivation rec { doCheck = true; enableParallelChecking = false; + env = lib.optionalAttrs useAccel { + # Without these flags some tests will fail / segfault when using Accelerate + # framework. They were pulled from the CI Workflow + # https://github.com/opencollab/arpack-ng/blob/804fa3149a0f773064198a8e883bd021832157ca/.github/workflows/jobs.yml#L184-L192 + FFLAGS = "-ff2c -fno-second-underscore"; + }; + cmakeFlags = [ (lib.cmakeBool "BUILD_SHARED_LIBS" stdenv.hostPlatform.hasSharedLibraries) (lib.cmakeBool "EIGEN" true) (lib.cmakeBool "EXAMPLES" true) (lib.cmakeBool "ICB" true) - (lib.cmakeBool "INTERFACE64" blas.isILP64) + (lib.cmakeBool "INTERFACE64" (!useAccel && blas.isILP64)) (lib.cmakeBool "MPI" useMpi) ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ - # prevent cmake from using Accelerate, which causes single precision tests - # to segfault - "-DBLA_VENDOR=Generic" + "-DBLA_VENDOR=${if useAccel then "Apple" else "Generic"}" ]; passthru = { - inherit (blas) isILP64; + isILP64 = !useAccel && blas.isILP64; tests = { inherit igraph; };