2021-02-05 17:12:51 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2023-10-09 19:29:22 +00:00
|
|
|
, applyPatches
|
2020-04-24 23:36:52 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
|
|
|
, cmake
|
|
|
|
, git
|
2023-10-09 19:29:22 +00:00
|
|
|
, llvmPackages_14
|
2020-04-24 23:36:52 +00:00
|
|
|
, spirv-llvm-translator
|
|
|
|
, buildWithPatches ? true
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-12-17 10:02:37 +00:00
|
|
|
addPatches = component: pkg: pkg.overrideAttrs (oldAttrs: {
|
|
|
|
postPatch = oldAttrs.postPatch or "" + ''
|
|
|
|
for p in ${passthru.patchesOut}/${component}/*; do
|
|
|
|
patch -p1 -i "$p"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
llvmPkgs = llvmPackages_14;
|
|
|
|
inherit (llvmPkgs) llvm;
|
|
|
|
spirv-llvm-translator' = spirv-llvm-translator.override { inherit llvm; };
|
|
|
|
libclang = if buildWithPatches then passthru.libclang else llvmPkgs.libclang;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
passthru = rec {
|
2023-10-09 19:29:22 +00:00
|
|
|
spirv-llvm-translator = spirv-llvm-translator';
|
2021-12-06 16:07:01 +00:00
|
|
|
llvm = addPatches "llvm" llvmPkgs.llvm;
|
2021-05-20 23:08:51 +00:00
|
|
|
libclang = addPatches "clang" llvmPkgs.libclang;
|
|
|
|
|
|
|
|
clang-unwrapped = libclang.out;
|
2020-04-24 23:36:52 +00:00
|
|
|
clang = llvmPkgs.clang.override {
|
|
|
|
cc = clang-unwrapped;
|
|
|
|
};
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
patchesOut = stdenv.mkDerivation {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "opencl-clang-patches";
|
2023-10-09 19:29:22 +00:00
|
|
|
inherit version src;
|
2021-12-06 16:07:01 +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
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
installPhase = ''
|
|
|
|
[ -d patches ] && cp -r patches/ $out || mkdir $out
|
2021-12-06 16:07:01 +00:00
|
|
|
mkdir -p $out/clang $out/llvm
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
version = "unstable-2023-06-12";
|
|
|
|
src = applyPatches {
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "intel";
|
|
|
|
repo = "opencl-clang";
|
|
|
|
# https://github.com/intel/opencl-clang/compare/ocl-open-140
|
|
|
|
rev = "cf95b338d14685e4f3402ab1828bef31d48f1fd6";
|
|
|
|
hash = "sha256-To1RlQX9IJ+1zAwEXaW7ua3VNfjK9mu7pgsRPsfa8g8=";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
patches = [
|
|
|
|
# Build script tries to find Clang OpenCL headers under ${llvm}
|
|
|
|
# Work around it by specifying that directory manually.
|
|
|
|
./opencl-headers-dir.patch
|
|
|
|
|
|
|
|
# fix CMake throwing errors
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/intel/opencl-clang/commit/321e3b99c1a8d54c8475f5ae998452069cc5eb71.patch";
|
|
|
|
hash = "sha256-cATbH+AMVtcabhl3EkzAH7w3wGreUV53hQYHVUUEP4g=";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# fix not be able to find clang from PATH
|
|
|
|
substituteInPlace cl_headers/CMakeLists.txt \
|
|
|
|
--replace " NO_DEFAULT_PATH" ""
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
2021-05-20 23:08:51 +00:00
|
|
|
# Uses linker flags that are not supported on Darwin.
|
2023-10-09 19:29:22 +00:00
|
|
|
sed -i -e '/SET_LINUX_EXPORTS_FILE/d' CMakeLists.txt
|
|
|
|
substituteInPlace CMakeLists.txt \
|
|
|
|
--replace '-Wl,--no-undefined' ""
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
2021-05-20 23:08:51 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = "opencl-clang";
|
|
|
|
inherit version src;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
nativeBuildInputs = [ cmake git llvm.dev ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
buildInputs = [ libclang llvm spirv-llvm-translator' ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
cmakeFlags = [
|
|
|
|
"-DPREFERRED_LLVM_VERSION=${lib.getVersion llvm}"
|
|
|
|
"-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${lib.getVersion libclang}/include/"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
"-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF"
|
|
|
|
"-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator'}"
|
|
|
|
];
|
2022-12-17 10:02:37 +00:00
|
|
|
|
2023-10-09 19:29:22 +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;
|
|
|
|
maintainers = with maintainers; [ ];
|
|
|
|
platforms = platforms.all;
|
|
|
|
# error: invalid value 'CL3.0' in '-cl-std=CL3.0'
|
|
|
|
broken = stdenv.isDarwin;
|
|
|
|
};
|
|
|
|
}
|