Skip to content

Instantly share code, notes, and snippets.

@xddxdd
Created June 4, 2024 05:56
Show Gist options
  • Save xddxdd/3627283c38e3db9a5e7f18d25d3a0bcb to your computer and use it in GitHub Desktop.
Save xddxdd/3627283c38e3db9a5e7f18d25d3a0bcb to your computer and use it in GitHub Desktop.
Nix pocl package
{
lib,
stdenv,
fetchFromGitHub,
nix-update-script,
cmake,
pkg-config,
hwloc,
llvmPackages_16,
lttng-ust,
ocl-icd,
python3,
runCommand,
makeWrapper,
}:
# Modified from https://github.com/NixOS/nixpkgs/pull/261736
let
llvmPackages = llvmPackages_16;
clang = llvmPackages.clangUseLLVM;
clangWrapped = runCommand "clang-pocl" { nativeBuildInputs = [ makeWrapper ]; } ''
mkdir -p $out/bin
cp -r ${clang}/bin/* $out/bin/
LIBGCC_DIR=$(dirname $(find ${stdenv.cc.cc}/lib/ -name libgcc.a))
for F in ${clang}/bin/ld*; do
BASENAME=$(basename "$F")
rm -f $out/bin/$BASENAME
makeWrapper ${clang}/bin/$BASENAME $out/bin/$BASENAME \
--add-flags "-L$LIBGCC_DIR" \
--add-flags "-L${stdenv.cc.cc.lib}/lib"
done
'';
in
stdenv.mkDerivation (finalAttrs: {
pname = "pocl";
version = "4.0";
src = fetchFromGitHub {
owner = "pocl";
repo = "pocl";
rev = "v${finalAttrs.version}";
sha256 = "sha256-Uo4Np4io1s/NMK+twX36PLBFP0j5j/0NkkBvS2Zv9ng=";
};
cmakeFlags = [
"-DKERNELLIB_HOST_CPU_VARIANTS=distro"
# avoid the runtime linker pulling in a different llvm e.g. from graphics drivers
"-DLLVM_STATIC=ON"
"-DENABLE_POCL_BUILDING=OFF"
"-DPOCL_ICD_ABSOLUTE_PATH=ON"
"-DENABLE_ICD=ON"
"-DCLANG=${clangWrapped}/bin/clang"
"-DCLANGXX=${clangWrapped}/bin/clang++"
];
nativeBuildInputs = [
cmake
pkg-config
clangWrapped
python3
];
buildInputs = [
hwloc
llvmPackages.llvm
llvmPackages.libclang
lttng-ust
ocl-icd
];
passthru.updateScript = nix-update-script { };
meta = with lib; {
description = "A portable open source (MIT-licensed) implementation of the OpenCL standard";
homepage = "http://portablecl.org";
license = licenses.mit;
maintainers = with maintainers; [
jansol
xddxdd
];
platforms = platforms.linux ++ platforms.darwin;
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment