2023-11-16 04:20:00 +00:00
|
|
|
{ lib, stdenv, version, runCommand, monorepoSrc, llvm, buildPackages, buildLlvmTools, ninja, cmake, python3 }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-07-21 07:28:18 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "libclc";
|
2023-11-16 04:20:00 +00:00
|
|
|
inherit version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
src = runCommand "${pname}-src-${version}" {} ''
|
|
|
|
mkdir -p "$out"
|
|
|
|
cp -r ${monorepoSrc}/cmake "$out"
|
|
|
|
cp -r ${monorepoSrc}/${pname} "$out"
|
|
|
|
'';
|
|
|
|
|
|
|
|
sourceRoot = "${src.name}/${pname}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
|
|
|
patches = [
|
2024-01-02 11:29:13 +00:00
|
|
|
./libclc/libclc-gnu-install-dirs.patch
|
2023-07-15 17:15:38 +00:00
|
|
|
];
|
|
|
|
|
2021-07-21 07:28:18 +00:00
|
|
|
# cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
|
2020-04-24 23:36:52 +00:00
|
|
|
postPatch = ''
|
2021-07-21 07:28:18 +00:00
|
|
|
substituteInPlace CMakeLists.txt \
|
2023-07-15 17:15:38 +00:00
|
|
|
--replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2023-11-16 04:20:00 +00:00
|
|
|
'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
|
2023-07-15 17:15:38 +00:00
|
|
|
--replace 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2023-11-16 04:20:00 +00:00
|
|
|
'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
|
2023-07-15 17:15:38 +00:00
|
|
|
--replace 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2023-11-16 04:20:00 +00:00
|
|
|
'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
|
2023-07-15 17:15:38 +00:00
|
|
|
--replace 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2023-11-16 04:20:00 +00:00
|
|
|
'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
|
2023-07-15 17:15:38 +00:00
|
|
|
--replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2024-01-02 11:29:13 +00:00
|
|
|
'find_program( LLVM_SPIRV llvm-spirv PATHS "${buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; }}/bin" NO_DEFAULT_PATH )'
|
2023-07-15 17:15:38 +00:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
|
|
|
|
substituteInPlace CMakeLists.txt \
|
2024-01-02 11:29:13 +00:00
|
|
|
--replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
nativeBuildInputs = [ cmake ninja python3 ];
|
2023-11-16 04:20:00 +00:00
|
|
|
buildInputs = [ llvm ];
|
2021-07-21 07:28:18 +00:00
|
|
|
strictDeps = true;
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
install -Dt $dev/bin prepare_builtins
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "http://libclc.llvm.org/";
|
|
|
|
description = "Implementation of the library requirements of the OpenCL C programming language";
|
2024-04-21 15:54:59 +00:00
|
|
|
mainProgram = "prepare_builtins";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.mit;
|
|
|
|
platforms = platforms.all;
|
|
|
|
};
|
|
|
|
}
|