1{ lib, stdenv, fetchFromGitHub, ninja, cmake, python3, llvmPackages, spirv-llvm-translator }:
2
3let
4 llvm = llvmPackages.llvm;
5 clang-unwrapped = llvmPackages.clang-unwrapped;
6in
7
8stdenv.mkDerivation rec {
9 pname = "libclc";
10 version = "12.0.1";
11
12 src = fetchFromGitHub {
13 owner = "llvm";
14 repo = "llvm-project";
15 rev = "llvmorg-${version}";
16 sha256 = "08s5w2db9imb2yaqsvxs6pg21csi1cf6wa35rf8x6q07mam7j8qv";
17 };
18 sourceRoot = "source/libclc";
19
20 # cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
21 postPatch = ''
22 substituteInPlace CMakeLists.txt \
23 --replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_BINDIR} NO_DEFAULT_PATH )' \
24 'find_program( LLVM_CLANG clang PATHS "${clang-unwrapped}/bin" NO_DEFAULT_PATH )' \
25 --replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_BINDIR} NO_DEFAULT_PATH )' \
26 'find_program( LLVM_SPIRV llvm-spirv PATHS "${spirv-llvm-translator}/bin" NO_DEFAULT_PATH )'
27 '';
28
29 nativeBuildInputs = [ cmake ninja python3 spirv-llvm-translator ];
30 buildInputs = [ llvm clang-unwrapped ];
31 strictDeps = true;
32 cmakeFlags = [
33 "-DCMAKE_INSTALL_INCLUDEDIR=include"
34 ];
35
36 meta = with lib; {
37 broken = stdenv.isDarwin;
38 homepage = "http://libclc.llvm.org/";
39 description = "Implementation of the library requirements of the OpenCL C programming language";
40 license = licenses.mit;
41 platforms = platforms.all;
42 };
43}