From 71e11c779bdf5a0eb50f215bac7df585e2af8ab1 Mon Sep 17 00:00:00 2001 From: Craig Hall Date: Sat, 27 Jul 2019 18:33:55 +0100 Subject: [PATCH] opencl-clang: init at unstable-2019-08-16 --- .../libraries/opencl-clang/default.nix | 97 +++++++++++++++++++ .../opencl-clang/opencl-headers-dir.patch | 25 +++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 124 insertions(+) create mode 100644 pkgs/development/libraries/opencl-clang/default.nix create mode 100644 pkgs/development/libraries/opencl-clang/opencl-headers-dir.patch diff --git a/pkgs/development/libraries/opencl-clang/default.nix b/pkgs/development/libraries/opencl-clang/default.nix new file mode 100644 index 000000000000..50794863defb --- /dev/null +++ b/pkgs/development/libraries/opencl-clang/default.nix @@ -0,0 +1,97 @@ +{ stdenv +, fetchFromGitHub +, fetchpatch +, cmake +, git + +, llvmPackages_8 +, spirv-llvm-translator + +, buildWithPatches ? true +}: + +let + llvmPkgs = llvmPackages_8 // { + inherit spirv-llvm-translator; + }; + + inherit (stdenv.lib) getVersion; + + addPatches = component: pkg: + with builtins; with stdenv.lib; + let path = "${passthru.patchesOut}/${component}"; + in pkg.overrideAttrs (super: { + postPatch = (if super ? postPatch then super.postPatch + "\n" else "") + '' + for p in ${path}/* + do + patch -p1 -i "$p" + done + ''; + }); + + passthru = rec { + + clang-unwrapped = addPatches "clang" llvmPkgs.clang-unwrapped; + + clang = llvmPkgs.clang.override { + cc = clang-unwrapped; + }; + + patchesOut = stdenv.mkDerivation rec { + pname = "opencl-clang-patches"; + inherit (lib) version src patches; + installPhase = '' + [ -d patches ] && cp -r patches/ $out || mkdir $out + mkdir -p $out/clang $out/spirv + ''; + }; + + spirv-llvm-translator = addPatches "spirv" llvmPkgs.spirv-llvm-translator; + + }; + + lib = let + inherit (llvmPkgs) llvm; + inherit (if buildWithPatches then passthru else llvmPkgs) clang-unwrapped spirv-llvm-translator; + in + stdenv.mkDerivation rec { + pname = "opencl-clang"; + version = "unstable-2019-08-16"; + + inherit passthru; + + src = fetchFromGitHub { + owner = "intel"; + repo = "opencl-clang"; + rev = "94af090661d7c953c516c97a25ed053c744a0737"; + sha256 = "05cg89m62nqjqm705h7gpdz4jd4hiczg8944dcjsvaybrqv3hcm5"; + }; + + patches = [ + # Build script tries to find Clang OpenCL headers under ${llvm} + # Work around it by specifying that directory manually. + ./opencl-headers-dir.patch + ]; + + nativeBuildInputs = [ cmake git ]; + + buildInputs = [ clang-unwrapped llvm spirv-llvm-translator ]; + + cmakeFlags = [ + "-DPREFERRED_LLVM_VERSION=${getVersion llvm}" + "-DOPENCL_HEADERS_DIR=${clang-unwrapped}/lib/clang/${getVersion clang-unwrapped}/include/" + + "-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF" + "-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator}" + ]; + + meta = with stdenv.lib; { + homepage = https://github.com/intel/opencl-clang/; + description = "A clang wrapper library with an OpenCL-oriented API and the ability to compile OpenCL C kernels to SPIR-V modules"; + license = licenses.ncsa; + platforms = platforms.all; + maintainers = with maintainers; [ gloaming ]; + }; + }; +in + lib diff --git a/pkgs/development/libraries/opencl-clang/opencl-headers-dir.patch b/pkgs/development/libraries/opencl-clang/opencl-headers-dir.patch new file mode 100644 index 000000000000..70343b8ee197 --- /dev/null +++ b/pkgs/development/libraries/opencl-clang/opencl-headers-dir.patch @@ -0,0 +1,25 @@ +diff --git a/cl_headers/CMakeLists.txt b/cl_headers/CMakeLists.txt +index 3dd2ea4..aeae6e9 100644 +--- a/cl_headers/CMakeLists.txt ++++ b/cl_headers/CMakeLists.txt +@@ -11,12 +11,14 @@ add_custom_command( + ) + endfunction(copy_file) + +-if(USE_PREBUILT_LLVM) +- set(OPENCL_HEADERS_DIR +- "${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}/include/") +-else(USE_PREBUILT_LLVM) +- set(OPENCL_HEADERS_DIR "${CLANG_SOURCE_DIR}/lib/Headers") +-endif(USE_PREBUILT_LLVM) ++if(NOT DEFINED OPENCL_HEADERS_DIR) ++ if(USE_PREBUILT_LLVM) ++ set(OPENCL_HEADERS_DIR ++ "${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}/include/") ++ else(USE_PREBUILT_LLVM) ++ set(OPENCL_HEADERS_DIR "${CLANG_SOURCE_DIR}/lib/Headers") ++ endif(USE_PREBUILT_LLVM) ++endif() + copy_file(${OPENCL_HEADERS_DIR}/opencl-c.h opencl-c.h) + + add_custom_target ( diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 31f4bb65fb0e..ca45f07f29bc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12599,6 +12599,8 @@ in lzo = callPackage ../development/libraries/lzo { }; + opencl-clang = callPackage ../development/libraries/opencl-clang { }; + mapnik = callPackage ../development/libraries/mapnik { }; marisa = callPackage ../development/libraries/marisa {};