Refactor intel wrapper logic into single function

This commit is contained in:
Aleix Boné 2025-12-10 17:32:46 +01:00
parent 92d12c5f69
commit 16a8f84727
No known key found for this signature in database

View File

@ -45,21 +45,14 @@ lib.makeOverridable (
# } __components;
wrapIntel =
{
cc,
nixSupport ? { },
extraBuildCommands ? "",
extraInstall ? "",
...
}@args:
cc:
let
targetConfig = stdenv.targetPlatform.config;
in
(
wrapCCWith {
(wrapCCWith {
inherit cc;
nixSupport = lib.mergeAttrsConcatenateValues {
nixSupport = {
cc-ldflags = [
"-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}"
"-L${gcc.cc.lib}/lib"
@ -77,7 +70,7 @@ lib.makeOverridable (
"-isystem ${gcc.cc}/include/c++/${gcc.version}"
"-isystem ${gcc.cc}/include/c++/${gcc.version}/${targetConfig}"
];
} nixSupport;
};
extraBuildCommands = ''
# FIXME: We should find a better way to modify the PATH instead of using
@ -86,18 +79,31 @@ lib.makeOverridable (
# Disable hardening by default
echo "" > $out/nix-support/add-hardening.sh
''
+ extraBuildCommands;
}
// (removeAttrs args [
"cc"
"extraBuildCommands"
"extraInstall"
"nixSupport"
])
).overrideAttrs
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
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 + extraInstall;
installPhase = old.installPhase + ''
export named_cc="icx"
export named_cxx="icpx"
export named_fc="ifx"
'';
});
in
@ -176,33 +182,7 @@ lib.makeOverridable (
stdenv = overrideCC stdenv finalAttrs.finalPackage.cc;
cc = wrapIntel {
cc = finalAttrs.finalPackage.pkgs.compiler;
extraBuildCommands = ''
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
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 ${finalAttrs.finalPackage.pkgs.compiler}/lib $out/lib
ln -s ${finalAttrs.finalPackage.pkgs.compiler}/include $out/include
'';
extraInstall = ''
export named_cc="icx"
export named_cxx="icpx"
export named_fc="ifx"
'';
};
cc = wrapIntel finalAttrs.finalPackage.pkgs.compiler;
};
})