forked from rarias/jungle
200 lines
5.0 KiB
Nix
200 lines
5.0 KiB
Nix
{
|
|
stdenv,
|
|
stdenvNoCC,
|
|
lib,
|
|
symlinkJoin,
|
|
autoPatchelfHook,
|
|
wrapCCWith,
|
|
overrideCC,
|
|
gcc,
|
|
hwloc,
|
|
libelf,
|
|
libffi_3_3,
|
|
libpsm2,
|
|
libuuid,
|
|
libxml2,
|
|
numactl,
|
|
ocl-icd,
|
|
openssl,
|
|
python3,
|
|
rdma-core,
|
|
ucx,
|
|
zlib,
|
|
writeTextFile,
|
|
}:
|
|
|
|
lib.makeOverridable (
|
|
{
|
|
unpatched,
|
|
components ? { },
|
|
extraPackages ? components.extraPackages or [ ],
|
|
}:
|
|
|
|
let
|
|
inherit (builtins)
|
|
attrValues
|
|
filter
|
|
mapAttrs
|
|
removeAttrs
|
|
;
|
|
|
|
__components = removeAttrs components [ "extraPackages" ];
|
|
_components = __components;
|
|
# _components = lib.traceSeqN 2 {
|
|
# inherit unpatched __components;
|
|
# deps = builtins.map (x: "${x.pname}-${x.version}") unpatched.deps;
|
|
# } __components;
|
|
|
|
wrapIntel =
|
|
cc:
|
|
let
|
|
targetConfig = stdenv.targetPlatform.config;
|
|
in
|
|
(wrapCCWith {
|
|
inherit cc;
|
|
|
|
nixSupport = {
|
|
cc-ldflags = [
|
|
"-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}"
|
|
"-L${gcc.cc.lib}/lib"
|
|
"-L${cc}/lib"
|
|
];
|
|
cc-cflags = [
|
|
"--gcc-toolchain=${gcc.cc}"
|
|
"-isystem \"${cc.original}/lib/clang/*/include\""
|
|
"-isystem ${cc}/include"
|
|
"-isystem ${cc}/include/intel64"
|
|
"-isystem ${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}/include"
|
|
];
|
|
libcxx-cxxflags = [
|
|
# "--gcc-toolchain=${gcc.cc}"
|
|
"-isystem ${gcc.cc}/include/c++/${gcc.version}"
|
|
"-isystem ${gcc.cc}/include/c++/${gcc.version}/${targetConfig}"
|
|
];
|
|
};
|
|
|
|
extraBuildCommands = ''
|
|
# FIXME: We should find a better way to modify the PATH instead of using
|
|
# this ugly hack. See https://jungle.bsc.es/git/rarias/bscpkgs/issues/9
|
|
echo 'path_backup="${gcc.cc}/bin:$path_backup"' >>$out/nix-support/cc-wrapper-hook
|
|
|
|
# Disable hardening by default
|
|
echo "" > $out/nix-support/add-hardening.sh
|
|
|
|
wrap icx $wrapper $ccPath/icx
|
|
wrap icpx $wrapper $ccPath/icpx
|
|
wrap ifx $wrapper $ccPath/ifx
|
|
|
|
ln -s $out/bin/icpx $out/bin/c++
|
|
ln -s $out/bin/icx $out/bin/cc
|
|
|
|
ln -s $ccPath/sycl-ls $out/bin/sycl-ls
|
|
ln -s $ccPath/sycl-trace $out/bin/sycl-trace
|
|
|
|
sed -i 's/.*isCxx=0/isCxx=1/' $out/bin/icpx
|
|
|
|
# Use this to detect when a compiler subprocess is called
|
|
# from icpx (--fsycl-host-compiler)
|
|
echo 'export NIX_CC_WRAPPER_INTEL=1' >>$out/nix-support/cc-wrapper-hook
|
|
|
|
# oneMath looks for sycl libraries in bin/../lib
|
|
ln -s ${cc}/lib $out/lib
|
|
ln -s ${cc}/include $out/include
|
|
'';
|
|
}).overrideAttrs
|
|
(old: {
|
|
installPhase = old.installPhase + ''
|
|
export named_cc="icx"
|
|
export named_cxx="icpx"
|
|
export named_fc="ifx"
|
|
'';
|
|
});
|
|
|
|
in
|
|
stdenvNoCC.mkDerivation (finalAttrs: {
|
|
pname = lib.removeSuffix "-extracted" unpatched.pname;
|
|
inherit (unpatched) version;
|
|
src = unpatched;
|
|
|
|
phases = [
|
|
"installPhase"
|
|
"fixupPhase"
|
|
];
|
|
buildInputs = [
|
|
libffi_3_3
|
|
libelf
|
|
libxml2
|
|
hwloc
|
|
numactl
|
|
libuuid
|
|
libpsm2
|
|
zlib
|
|
ocl-icd
|
|
rdma-core
|
|
ucx
|
|
openssl
|
|
python3
|
|
stdenv.cc.cc.lib
|
|
]
|
|
++ extraPackages;
|
|
|
|
autoPatchelfIgnoreMissingDeps = [
|
|
"libhwloc.so.5"
|
|
"libcuda.so.1"
|
|
"libze_loader.so.1"
|
|
];
|
|
|
|
# There are broken symlinks that go outside packages, ignore them
|
|
dontCheckForBrokenSymlinks = true;
|
|
|
|
nativeBuildInputs = [ autoPatchelfHook ];
|
|
installPhase = ''
|
|
cp -r $src/opt/intel/oneapi/ $out
|
|
'';
|
|
|
|
passthru =
|
|
let
|
|
pkgs = mapAttrs (
|
|
folder: version:
|
|
let
|
|
original = "${finalAttrs.finalPackage}/${folder}/${version}";
|
|
|
|
etc-vendors = writeTextFile {
|
|
name = "intel-ocl-icd";
|
|
text = "${original}/lib/libintelocl.so";
|
|
destination = "/etc/OpenCL/vendors/intel.icd";
|
|
};
|
|
in
|
|
symlinkJoin {
|
|
pname = "intel-${folder}";
|
|
inherit version;
|
|
paths = [ original ] ++ lib.optionals (folder == "compiler") [ etc-vendors ];
|
|
passthru = { inherit original; };
|
|
}
|
|
) _components;
|
|
in
|
|
pkgs
|
|
// {
|
|
inherit unpatched;
|
|
pkgs = lib.recurseIntoAttrs pkgs;
|
|
components = _components;
|
|
|
|
# This contains all packages properly symlinked into toplevel directories
|
|
# in $out.
|
|
#
|
|
# NOTE: there are clashes with packages that have symlinks outside their
|
|
# scope (libtcm and env/vars.sh)
|
|
all = symlinkJoin {
|
|
pname = finalAttrs.finalPackage.pname + "-symlinked";
|
|
inherit (finalAttrs.finalPackage) version;
|
|
paths = filter lib.isDerivation (attrValues finalAttrs.finalPackage.pkgs);
|
|
};
|
|
|
|
stdenv = overrideCC stdenv finalAttrs.finalPackage.cc;
|
|
|
|
cc = wrapIntel finalAttrs.finalPackage.pkgs.compiler;
|
|
};
|
|
|
|
})
|
|
)
|