opencl-clang: simplify, cleanup, adopt
This commit is contained in:
@@ -4,10 +4,8 @@
|
||||
, fetchpatch
|
||||
, cmake
|
||||
, git
|
||||
|
||||
, llvmPackages_11
|
||||
, spirv-llvm-translator
|
||||
|
||||
, buildWithPatches ? true
|
||||
}:
|
||||
|
||||
@@ -16,32 +14,25 @@ let
|
||||
inherit spirv-llvm-translator;
|
||||
};
|
||||
|
||||
inherit (lib) getVersion;
|
||||
|
||||
addPatches = component: pkg:
|
||||
with builtins; with 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
|
||||
'';
|
||||
});
|
||||
addPatches = component: pkg: pkg.overrideAttrs (oldAttrs: {
|
||||
postPatch = oldAttrs.postPatch or "" + ''
|
||||
for p in ${passthru.patchesOut}/${component}/*; do
|
||||
patch -p1 -i "$p"
|
||||
done
|
||||
'';
|
||||
});
|
||||
|
||||
passthru = rec {
|
||||
spirv-llvm-translator = llvmPkgs.spirv-llvm-translator;
|
||||
spirv-llvm-translator = llvmPkgs.spirv-llvm-translator.override { llvm = llvmPackages_11.llvm; };
|
||||
llvm = addPatches "llvm" llvmPkgs.llvm;
|
||||
libclang = addPatches "clang" llvmPkgs.libclang;
|
||||
|
||||
clang-unwrapped = libclang.out;
|
||||
|
||||
clang = llvmPkgs.clang.override {
|
||||
cc = clang-unwrapped;
|
||||
};
|
||||
|
||||
patchesOut = stdenv.mkDerivation rec {
|
||||
patchesOut = stdenv.mkDerivation {
|
||||
pname = "opencl-clang-patches";
|
||||
inherit (library) version src patches;
|
||||
# Clang patches assume the root is the llvm root dir
|
||||
@@ -62,14 +53,13 @@ let
|
||||
};
|
||||
|
||||
library = let
|
||||
inherit (llvmPkgs) llvm;
|
||||
inherit (llvmPackages_11) llvm;
|
||||
inherit (if buildWithPatches then passthru else llvmPkgs) libclang spirv-llvm-translator;
|
||||
in
|
||||
stdenv.mkDerivation rec {
|
||||
stdenv.mkDerivation {
|
||||
pname = "opencl-clang";
|
||||
version = "unstable-2022-03-16";
|
||||
|
||||
inherit passthru;
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "intel";
|
||||
@@ -79,8 +69,8 @@ let
|
||||
};
|
||||
|
||||
patches = [
|
||||
# Build script tries to find Clang OpenCL headers under ${llvm}
|
||||
# Work around it by specifying that directory manually.
|
||||
# Build script tries to find Clang OpenCL headers under ${llvm}
|
||||
# Work around it by specifying that directory manually.
|
||||
./opencl-headers-dir.patch
|
||||
];
|
||||
|
||||
@@ -96,19 +86,21 @@ let
|
||||
buildInputs = [ libclang llvm spirv-llvm-translator ];
|
||||
|
||||
cmakeFlags = [
|
||||
"-DPREFERRED_LLVM_VERSION=${getVersion llvm}"
|
||||
"-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${getVersion libclang}/include/"
|
||||
"-DPREFERRED_LLVM_VERSION=${lib.getVersion llvm}"
|
||||
"-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${lib.getVersion libclang}/include/"
|
||||
|
||||
"-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF"
|
||||
"-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator}"
|
||||
];
|
||||
|
||||
inherit passthru;
|
||||
|
||||
meta = with 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 ];
|
||||
maintainers = with maintainers; [ SuperSandro2000 ];
|
||||
};
|
||||
};
|
||||
in
|
||||
|
||||
Reference in New Issue
Block a user