core/pkgs/by-name/ll/llvm/common/libclc.nix

76 lines
2.5 KiB
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
lib,
stdenv,
version,
runCommand,
monorepoSrc,
llvm,
buildPackages,
buildLlvmTools,
ninja,
cmake,
python3,
}:
2024-05-02 00:46:19 +00:00
stdenv.mkDerivation rec {
pname = "libclc";
inherit version;
2024-06-30 08:16:52 +00:00
src = runCommand "${pname}-src-${version}" { } ''
2024-05-02 00:46:19 +00:00
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out"
'';
sourceRoot = "${src.name}/${pname}";
2024-06-30 08:16:52 +00:00
outputs = [
"out"
"dev"
2024-05-02 00:46:19 +00:00
];
2024-06-30 08:16:52 +00:00
patches = [ ./libclc/libclc-gnu-install-dirs.patch ];
2024-05-02 00:46:19 +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
2024-06-30 08:16:52 +00:00
postPatch =
''
substituteInPlace CMakeLists.txt \
--replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
--replace 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_SPIRV llvm-spirv PATHS "${
buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; }
}/bin" NO_DEFAULT_PATH )'
''
+ lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
substituteInPlace CMakeLists.txt \
--replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
'';
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
nativeBuildInputs = [
cmake
ninja
python3
];
2024-05-02 00:46:19 +00:00
buildInputs = [ llvm ];
strictDeps = true;
postInstall = ''
install -Dt $dev/bin prepare_builtins
'';
meta = with lib; {
homepage = "http://libclc.llvm.org/";
description = "Implementation of the library requirements of the OpenCL C programming language";
mainProgram = "prepare_builtins";
license = licenses.mit;
platforms = platforms.all;
};
}