2024-09-15 19:26:47 -07:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
version,
|
|
|
|
runCommand,
|
|
|
|
monorepoSrc,
|
|
|
|
llvm,
|
|
|
|
buildPackages,
|
|
|
|
buildLlvmTools,
|
|
|
|
ninja,
|
|
|
|
cmake,
|
|
|
|
python3,
|
|
|
|
release_version,
|
|
|
|
getVersionFile,
|
|
|
|
}:
|
2024-08-24 20:05:35 -07:00
|
|
|
let
|
2024-09-15 19:26:47 -07:00
|
|
|
spirv-llvm-translator = buildPackages.spirv-llvm-translator.override {
|
|
|
|
inherit (buildLlvmTools) llvm;
|
|
|
|
};
|
2024-11-04 10:13:20 -08:00
|
|
|
|
|
|
|
# The build requires an unwrapped clang but wrapped clang++ thus we need to
|
|
|
|
# split the unwrapped clang out to prevent the build from finding the
|
|
|
|
# unwrapped clang++
|
|
|
|
clang-only = runCommand "clang-only" { } ''
|
|
|
|
mkdir -p "$out"/bin
|
|
|
|
ln -s "${lib.getExe' buildLlvmTools.clang.cc "clang"}" "$out"/bin
|
|
|
|
'';
|
2024-08-24 20:05:35 -07:00
|
|
|
in
|
2025-03-30 21:37:21 -07:00
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2021-07-20 17:25:02 +02:00
|
|
|
pname = "libclc";
|
2023-10-28 14:24:04 +03:00
|
|
|
inherit version;
|
2015-03-28 13:54:27 -07:00
|
|
|
|
2025-03-30 21:37:21 -07:00
|
|
|
src = runCommand "libclc-src-${version}" { inherit (monorepoSrc) passthru; } (
|
2024-10-11 11:41:49 +02:00
|
|
|
''
|
|
|
|
mkdir -p "$out"
|
|
|
|
''
|
|
|
|
+ lib.optionalString (lib.versionAtLeast release_version "14") ''
|
|
|
|
cp -r ${monorepoSrc}/cmake "$out"
|
|
|
|
''
|
|
|
|
+ ''
|
2025-03-30 21:37:21 -07:00
|
|
|
cp -r ${monorepoSrc}/libclc "$out"
|
2024-10-11 11:41:49 +02:00
|
|
|
''
|
|
|
|
);
|
2023-10-28 14:24:04 +03:00
|
|
|
|
2025-03-30 21:37:21 -07:00
|
|
|
sourceRoot = "${finalAttrs.src.name}/libclc";
|
2015-03-28 13:54:27 -07:00
|
|
|
|
2024-09-15 19:26:47 -07:00
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
"dev"
|
|
|
|
];
|
2023-05-10 12:11:25 +00:00
|
|
|
|
2024-09-15 19:26:47 -07:00
|
|
|
patches =
|
2025-03-30 21:38:45 -07:00
|
|
|
[ ./libclc-gnu-install-dirs.patch ]
|
2024-09-15 19:26:47 -07:00
|
|
|
# LLVM 19 changes how host tools are looked up.
|
2024-08-24 20:05:35 -07:00
|
|
|
# Need to remove NO_DEFAULT_PATH and the PATHS arguments for find_program
|
|
|
|
# so CMake can actually find the tools in nativeBuildInputs.
|
|
|
|
# https://github.com/llvm/llvm-project/pull/105969
|
2024-09-15 19:26:47 -07:00
|
|
|
++ lib.optional (lib.versionAtLeast release_version "19") (
|
|
|
|
getVersionFile "libclc/use-default-paths.patch"
|
|
|
|
);
|
2023-06-03 12:37:17 -07:00
|
|
|
|
2021-07-20 17:25:02 +02: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-09-15 19:26:47 -07:00
|
|
|
postPatch =
|
|
|
|
lib.optionalString (lib.versionOlder release_version "19") ''
|
|
|
|
substituteInPlace CMakeLists.txt \
|
2024-11-15 09:49:12 +00:00
|
|
|
--replace-fail 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2024-09-15 19:26:47 -07:00
|
|
|
'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
|
2024-11-15 09:49:12 +00:00
|
|
|
--replace-fail 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2024-09-15 19:26:47 -07:00
|
|
|
'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
|
2024-11-15 09:49:12 +00:00
|
|
|
--replace-fail 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2024-09-15 19:26:47 -07:00
|
|
|
'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
|
2024-11-15 09:49:12 +00:00
|
|
|
--replace-fail 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2024-09-15 19:26:47 -07:00
|
|
|
'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
|
2024-11-15 09:49:12 +00:00
|
|
|
--replace-fail 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
|
2024-09-15 19:26:47 -07:00
|
|
|
'find_program( LLVM_SPIRV llvm-spirv PATHS "${spirv-llvm-translator}/bin" NO_DEFAULT_PATH )'
|
|
|
|
''
|
2024-12-19 21:46:21 -05:00
|
|
|
+ lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) (
|
|
|
|
if (lib.versionOlder release_version "19") then
|
|
|
|
''
|
|
|
|
substituteInPlace CMakeLists.txt \
|
2024-12-26 10:09:36 +03:00
|
|
|
--replace-fail 'COMMAND prepare_builtins' \
|
|
|
|
'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
|
2024-12-19 21:46:21 -05:00
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
substituteInPlace CMakeLists.txt \
|
|
|
|
--replace-fail 'set( prepare_builtins_exe prepare_builtins )' \
|
|
|
|
'set( prepare_builtins_exe ${buildLlvmTools.libclc.dev}/bin/prepare_builtins )'
|
|
|
|
''
|
|
|
|
);
|
2015-03-28 13:54:27 -07:00
|
|
|
|
2024-09-15 19:26:47 -07:00
|
|
|
nativeBuildInputs =
|
|
|
|
[
|
|
|
|
cmake
|
|
|
|
ninja
|
|
|
|
python3
|
|
|
|
]
|
|
|
|
++ lib.optional (lib.versionAtLeast release_version "19") [
|
2024-11-04 10:13:20 -08:00
|
|
|
clang-only
|
2024-09-15 19:26:47 -07:00
|
|
|
buildLlvmTools.llvm
|
|
|
|
spirv-llvm-translator
|
|
|
|
];
|
2023-10-28 14:24:04 +03:00
|
|
|
buildInputs = [ llvm ];
|
2021-07-20 17:25:02 +02:00
|
|
|
strictDeps = true;
|
2020-02-14 18:31:53 +01:00
|
|
|
|
2023-05-10 12:11:25 +00:00
|
|
|
postInstall = ''
|
|
|
|
install -Dt $dev/bin prepare_builtins
|
|
|
|
'';
|
|
|
|
|
2021-01-22 00:00:13 +07:00
|
|
|
meta = with lib; {
|
2020-03-31 21:11:51 -04:00
|
|
|
homepage = "http://libclc.llvm.org/";
|
2015-05-13 15:32:32 +02:00
|
|
|
description = "Implementation of the library requirements of the OpenCL C programming language";
|
2024-03-19 03:14:51 +01:00
|
|
|
mainProgram = "prepare_builtins";
|
2015-03-28 13:54:27 -07:00
|
|
|
license = licenses.mit;
|
|
|
|
platforms = platforms.all;
|
|
|
|
};
|
2025-03-30 21:37:21 -07:00
|
|
|
})
|