nixpkgs/pkgs/development/libraries/opencl-clang/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.0 KiB
Nix
Raw Normal View History

{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, cmake
, git
2021-10-23 20:24:13 +00:00
, llvmPackages_11
, spirv-llvm-translator
, buildWithPatches ? true
}:
let
2021-10-23 20:24:13 +00:00
llvmPkgs = llvmPackages_11 // {
inherit spirv-llvm-translator;
};
2022-11-28 04:22:45 +00:00
addPatches = component: pkg: pkg.overrideAttrs (oldAttrs: {
postPatch = oldAttrs.postPatch or "" + ''
for p in ${passthru.patchesOut}/${component}/*; do
patch -p1 -i "$p"
done
'';
});
passthru = rec {
2022-11-28 04:22:45 +00:00
spirv-llvm-translator = llvmPkgs.spirv-llvm-translator.override { llvm = llvmPackages_11.llvm; };
2021-10-23 20:24:13 +00:00
llvm = addPatches "llvm" llvmPkgs.llvm;
libclang = addPatches "clang" llvmPkgs.libclang;
clang-unwrapped = libclang.out;
clang = llvmPkgs.clang.override {
cc = clang-unwrapped;
};
2022-11-28 04:22:45 +00:00
patchesOut = stdenv.mkDerivation {
pname = "opencl-clang-patches";
inherit (library) version src patches;
2021-10-23 20:24:13 +00:00
# Clang patches assume the root is the llvm root dir
# but clang root in nixpkgs is the clang sub-directory
postPatch = ''
for filename in patches/clang/*.patch; do
substituteInPlace "$filename" \
--replace "a/clang/" "a/" \
--replace "b/clang/" "b/"
done
'';
installPhase = ''
[ -d patches ] && cp -r patches/ $out || mkdir $out
2021-10-23 20:24:13 +00:00
mkdir -p $out/clang $out/llvm
'';
};
};
library = let
2022-11-28 04:22:45 +00:00
inherit (llvmPackages_11) llvm;
inherit (if buildWithPatches then passthru else llvmPkgs) libclang spirv-llvm-translator;
in
2022-11-28 04:22:45 +00:00
stdenv.mkDerivation {
pname = "opencl-clang";
2022-05-05 12:43:39 +00:00
version = "unstable-2022-03-16";
src = fetchFromGitHub {
owner = "intel";
repo = "opencl-clang";
2022-05-05 12:43:39 +00:00
rev = "bbdd1587f577397a105c900be114b56755d1f7dc";
sha256 = "sha256-qEZoQ6h4XAvSnJ7/gLXBb1qrzeYa6Jp6nij9VFo8MwQ=";
};
patches = [
2022-11-28 04:22:45 +00:00
# Build script tries to find Clang OpenCL headers under ${llvm}
# Work around it by specifying that directory manually.
./opencl-headers-dir.patch
];
2021-05-18 09:10:39 +00:00
# Uses linker flags that are not supported on Darwin.
postPatch = lib.optionalString stdenv.isDarwin ''
sed -i -e '/SET_LINUX_EXPORTS_FILE/d' CMakeLists.txt
substituteInPlace CMakeLists.txt \
--replace '-Wl,--no-undefined' ""
'';
2021-05-09 00:26:37 +00:00
nativeBuildInputs = [ cmake git llvm.dev ];
buildInputs = [ libclang llvm spirv-llvm-translator ];
cmakeFlags = [
2022-11-28 04:22:45 +00:00
"-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}"
];
2022-11-28 04:22:45 +00:00
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;
2022-11-28 04:22:45 +00:00
maintainers = with maintainers; [ SuperSandro2000 ];
};
};
in
library