lol
1{ lib, stdenv, version, runCommand, monorepoSrc, llvm, buildPackages, buildLlvmTools, ninja, cmake, python3 }:
2
3stdenv.mkDerivation rec {
4 pname = "libclc";
5 inherit version;
6
7 src = runCommand "${pname}-src-${version}" {} ''
8 mkdir -p "$out"
9 cp -r ${monorepoSrc}/cmake "$out"
10 cp -r ${monorepoSrc}/${pname} "$out"
11 '';
12
13 sourceRoot = "${src.name}/${pname}";
14
15 outputs = [ "out" "dev" ];
16
17 patches = [
18 ./libclc/libclc-gnu-install-dirs.patch
19 ];
20
21 # cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
22 postPatch = ''
23 substituteInPlace CMakeLists.txt \
24 --replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
25 'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
26 --replace 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
27 'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
28 --replace 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
29 'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
30 --replace 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
31 'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
32 --replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
33 'find_program( LLVM_SPIRV llvm-spirv PATHS "${buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; }}/bin" NO_DEFAULT_PATH )'
34 '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
35 substituteInPlace CMakeLists.txt \
36 --replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
37 '';
38
39 nativeBuildInputs = [ cmake ninja python3 ];
40 buildInputs = [ llvm ];
41 strictDeps = true;
42
43 postInstall = ''
44 install -Dt $dev/bin prepare_builtins
45 '';
46
47 meta = with lib; {
48 homepage = "http://libclc.llvm.org/";
49 description = "Implementation of the library requirements of the OpenCL C programming language";
50 mainProgram = "prepare_builtins";
51 license = licenses.mit;
52 platforms = platforms.all;
53 };
54}