9 , spirv-llvm-translator
10 , buildWithPatches ? true
14 addPatches = component: pkg: pkg.overrideAttrs (oldAttrs: {
15 postPatch = oldAttrs.postPatch or "" + ''
16 for p in ${passthru.patchesOut}/${component}/*; do
22 llvmPkgs = llvmPackages_14;
23 inherit (llvmPkgs) llvm;
24 spirv-llvm-translator' = spirv-llvm-translator.override { inherit llvm; };
25 libclang = if buildWithPatches then passthru.libclang else llvmPkgs.libclang;
28 spirv-llvm-translator = spirv-llvm-translator';
29 llvm = addPatches "llvm" llvmPkgs.llvm;
30 libclang = addPatches "clang" llvmPkgs.libclang;
32 clang-unwrapped = libclang.out;
33 clang = llvmPkgs.clang.override {
37 patchesOut = stdenv.mkDerivation {
38 pname = "opencl-clang-patches";
40 # Clang patches assume the root is the llvm root dir
41 # but clang root in nixpkgs is the clang sub-directory
43 for filename in patches/clang/*.patch; do
44 substituteInPlace "$filename" \
45 --replace "a/clang/" "a/" \
46 --replace "b/clang/" "b/"
51 [ -d patches ] && cp -r patches/ $out || mkdir $out
52 mkdir -p $out/clang $out/llvm
57 version = "unstable-2023-06-12";
59 src = fetchFromGitHub {
61 repo = "opencl-clang";
62 # https://github.com/intel/opencl-clang/compare/ocl-open-140
63 rev = "cf95b338d14685e4f3402ab1828bef31d48f1fd6";
64 hash = "sha256-To1RlQX9IJ+1zAwEXaW7ua3VNfjK9mu7pgsRPsfa8g8=";
68 # Build script tries to find Clang OpenCL headers under ${llvm}
69 # Work around it by specifying that directory manually.
70 ./opencl-headers-dir.patch
72 # fix CMake throwing errors
74 url = "https://github.com/intel/opencl-clang/commit/321e3b99c1a8d54c8475f5ae998452069cc5eb71.patch";
75 hash = "sha256-cATbH+AMVtcabhl3EkzAH7w3wGreUV53hQYHVUUEP4g=";
80 # fix not be able to find clang from PATH
81 substituteInPlace cl_headers/CMakeLists.txt \
82 --replace " NO_DEFAULT_PATH" ""
83 '' + lib.optionalString stdenv.isDarwin ''
84 # Uses linker flags that are not supported on Darwin.
85 sed -i -e '/SET_LINUX_EXPORTS_FILE/d' CMakeLists.txt
86 substituteInPlace CMakeLists.txt \
87 --replace '-Wl,--no-undefined' ""
93 pname = "opencl-clang";
96 nativeBuildInputs = [ cmake git llvm.dev ];
98 buildInputs = [ libclang llvm spirv-llvm-translator' ];
101 "-DPREFERRED_LLVM_VERSION=${lib.getVersion llvm}"
102 "-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${lib.getVersion libclang}/include/"
104 "-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF"
105 "-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator'}"
111 homepage = "https://github.com/intel/opencl-clang/";
112 description = "A clang wrapper library with an OpenCL-oriented API and the ability to compile OpenCL C kernels to SPIR-V modules";
113 license = licenses.ncsa;
114 maintainers = with maintainers; [ ];
115 platforms = platforms.all;
116 # error: invalid value 'CL3.0' in '-cl-std=CL3.0'
117 broken = stdenv.isDarwin;