From 75c854df2ecbcdcd8d4a15e402768d9220811e34 Mon Sep 17 00:00:00 2001 From: David Johnson Date: Fri, 28 Jun 2019 18:10:08 -0400 Subject: [PATCH] Add nix scripts --- arrayfire.cabal | 22 +++++++----- arrayfire.nix | 91 +++++++++++++++++++++++++++++++++++++++++++++++ default.nix | 10 ++++-- no-download.patch | 28 +++++++++++++++ 4 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 arrayfire.nix create mode 100644 no-download.patch diff --git a/arrayfire.cabal b/arrayfire.cabal index f2244c0..6e3174a 100644 --- a/arrayfire.cabal +++ b/arrayfire.cabal @@ -16,6 +16,11 @@ description: High-level Haskell bindings to the ArrayFire General-purpos <> . +flag disable-default-paths + description: When enabled, don't add default hardcoded include/link dirs by default. Needed for nix builds. + default: False + manual: True + library exposed-modules: ArrayFire @@ -66,16 +71,17 @@ library ArrayFire.Internal.Vision build-tools: hsc2hs - include-dirs: - /opt/arrayfire/include - extra-lib-dirs: - /opt/arrayfire/lib - ld-options: - -rpath /opt/arrayfire/lib - cc-options: - -fPIC extra-libraries: af + if !flag(disable-default-paths) + include-dirs: + /opt/arrayfire/include + extra-lib-dirs: + /opt/arrayfire/lib + ld-options: + -rpath /opt/arrayfire/lib + cc-options: + -fPIC c-sources: cbits/wrapper.c build-depends: diff --git a/arrayfire.nix b/arrayfire.nix new file mode 100644 index 0000000..f8e5ef9 --- /dev/null +++ b/arrayfire.nix @@ -0,0 +1,91 @@ +{ stdenv, fetchurl, fetchFromGitHub, cmake, pkgconfig, + cudatoolkit, opencl-clhpp, ocl-icd, fftw, fftwFloat, mkl, + blas, openblas, liblapack, boost, mesa_noglu, libGLU_combined, + freeimage, python, doxygen +}: + +with { + clfftSource = fetchFromGitHub { + owner = "arrayfire"; + repo = "clFFT"; + rev = "16925fb93338b3cac66490b5cf764953d6a5dac7"; + sha256 = "0y35nrdz7w4n1l17myhkni3hwm37z775xn6f76xmf1ph7dbkslsc"; + fetchSubmodules = true; + }; + + clblasSource = fetchFromGitHub { + owner = "arrayfire"; + repo = "clBLAS"; + rev = "1f3de2ae5582972f665c685b18ef0df43c1792bb"; + sha256 = "154mz52r5hm0jrp5fqrirzzbki14c1jkacj75flplnykbl36ibjs"; + fetchSubmodules = true; + }; + + cl2hppSource = fetchurl { + url = "https://github.com/KhronosGroup/OpenCL-CLHPP/releases/download/v2.0.10/cl2.hpp"; + sha256 = "1v4q0g6b6mwwsi0kn7kbjn749j3qafb9r4ld3zdq1163ln9cwnvw"; + }; + + lapack = liblapack.overrideAttrs (old: { + cmakeFlags = (old.cmakeFlags or []) ++ [ + "-DLAPACKE=ON" + "-DCBLAS=ON" + ]; + }); +}; + +stdenv.mkDerivation { + name = "arrayfire-3.6.1"; + + src = fetchFromGitHub { + owner = "arrayfire"; + repo = "arrayfire"; + rev = "25bb360659b091bbca711b463c0ad5f0cf818e9c"; + sha256 = "1d0fcwgg9dicbhwp4shmddqjbjcd05w7x5j1cx2cd4j5iwwg1q50"; + fetchSubmodules = true; + }; + + cmakeFlags = [ + "-DAF_BUILD_OPENCL=OFF" + "-DAF_BUILD_EXAMPLES=OFF" + "-DBUILD_TESTING=OFF" + "-DCMAKE_LIBRARY_PATH=${cudatoolkit}/lib/stubs" + ]; + + # cmakeFlags = [ + # "-DLAPACK_INCLUDE_DIR=${lapack}/include" + # "-DLAPACK_LIBRARIES=${lapack}/lib/liblapacke.a" + # "-DCBLAS_INCLUDE_DIR=${lapack}/include" + # "-DCBLAS_LIBRARIES=${lapack}/lib/libcblas.a" + # ]; + + patches = [ ./no-download.patch ]; + + postPatch = '' + mkdir -p ./build/third_party/clFFT/src + cp -R --no-preserve=mode,ownership ${clfftSource}/ ./build/third_party/clFFT/src/clFFT-ext/ + mkdir -p ./build/third_party/clBLAS/src + cp -R --no-preserve=mode,ownership ${clblasSource}/ ./build/third_party/clBLAS/src/clBLAS-ext/ + mkdir -p ./build/include/CL + cp -R --no-preserve=mode,ownership ${cl2hppSource} ./build/include/CL/cl2.hpp + ''; + + preBuild = '' + export CUDA_PATH="${cudatoolkit}" + ''; + + enableParallelBuilding = true; + + buildInputs = [ + cmake pkgconfig + cudatoolkit + opencl-clhpp ocl-icd fftw fftwFloat + lapack + mkl + openblas + libGLU_combined + mesa_noglu freeimage + boost.out boost.dev python + #doxygen + ]; +} diff --git a/default.nix b/default.nix index b2b78fb..79bfdb6 100644 --- a/default.nix +++ b/default.nix @@ -1,2 +1,8 @@ -{ pkgs ? import {} }: -pkgs.haskellPackages.callPackage ./pkg.nix {} +{ pkgs ? import {} +}: +with pkgs.haskell.lib; +let + af = pkgs.callPackage ./arrayfire.nix {}; + fire = pkgs.haskellPackages.callCabal2nix "arrayfire" ./. { inherit af; }; +in + enableCabalFlag fire "disable-default-paths" diff --git a/no-download.patch b/no-download.patch new file mode 100644 index 0000000..2b3ac49 --- /dev/null +++ b/no-download.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeModules/build_clBLAS.cmake b/CMakeModules/build_clBLAS.cmake +index 8de529e8..6361b613 100644 +--- a/CMakeModules/build_clBLAS.cmake ++++ b/CMakeModules/build_clBLAS.cmake +@@ -14,8 +14,7 @@ find_package(OpenCL) + + ExternalProject_Add( + clBLAS-ext +- GIT_REPOSITORY https://github.com/arrayfire/clBLAS.git +- GIT_TAG arrayfire-release ++ DOWNLOAD_COMMAND true + BUILD_BYPRODUCTS ${clBLAS_location} + PREFIX "${prefix}" + INSTALL_DIR "${prefix}" +diff --git a/CMakeModules/build_clFFT.cmake b/CMakeModules/build_clFFT.cmake +index 28be38a3..85e3915e 100644 +--- a/CMakeModules/build_clFFT.cmake ++++ b/CMakeModules/build_clFFT.cmake +@@ -20,8 +20,7 @@ ENDIF() + + ExternalProject_Add( + clFFT-ext +- GIT_REPOSITORY https://github.com/arrayfire/clFFT.git +- GIT_TAG arrayfire-release ++ DOWNLOAD_COMMAND true + PREFIX "${prefix}" + INSTALL_DIR "${prefix}" + UPDATE_COMMAND ""