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,59 +45,65 @@ lib.makeOverridable (
# } __components; # } __components;
wrapIntel = wrapIntel =
{ cc:
cc,
nixSupport ? { },
extraBuildCommands ? "",
extraInstall ? "",
...
}@args:
let let
targetConfig = stdenv.targetPlatform.config; targetConfig = stdenv.targetPlatform.config;
in in
( (wrapCCWith {
wrapCCWith { inherit cc;
inherit cc;
nixSupport = lib.mergeAttrsConcatenateValues { nixSupport = {
cc-ldflags = [ cc-ldflags = [
"-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}"
"-L${gcc.cc.lib}/lib" "-L${gcc.cc.lib}/lib"
"-L${cc}/lib" "-L${cc}/lib"
]; ];
cc-cflags = [ cc-cflags = [
"--gcc-toolchain=${gcc.cc}" "--gcc-toolchain=${gcc.cc}"
"-isystem \"${cc.original}/lib/clang/*/include\"" "-isystem \"${cc.original}/lib/clang/*/include\""
"-isystem ${cc}/include" "-isystem ${cc}/include"
"-isystem ${cc}/include/intel64" "-isystem ${cc}/include/intel64"
"-isystem ${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}/include" "-isystem ${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}/include"
]; ];
libcxx-cxxflags = [ libcxx-cxxflags = [
# "--gcc-toolchain=${gcc.cc}" # "--gcc-toolchain=${gcc.cc}"
"-isystem ${gcc.cc}/include/c++/${gcc.version}" "-isystem ${gcc.cc}/include/c++/${gcc.version}"
"-isystem ${gcc.cc}/include/c++/${gcc.version}/${targetConfig}" "-isystem ${gcc.cc}/include/c++/${gcc.version}/${targetConfig}"
]; ];
} nixSupport; };
extraBuildCommands = '' extraBuildCommands = ''
# FIXME: We should find a better way to modify the PATH instead of using # 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 # 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 echo 'path_backup="${gcc.cc}/bin:$path_backup"' >>$out/nix-support/cc-wrapper-hook
# Disable hardening by default # Disable hardening by default
echo "" > $out/nix-support/add-hardening.sh echo "" > $out/nix-support/add-hardening.sh
''
+ extraBuildCommands; wrap icx $wrapper $ccPath/icx
} wrap icpx $wrapper $ccPath/icpx
// (removeAttrs args [ wrap ifx $wrapper $ccPath/ifx
"cc"
"extraBuildCommands" ln -s $out/bin/icpx $out/bin/c++
"extraInstall" ln -s $out/bin/icx $out/bin/cc
"nixSupport"
]) sed -i 's/.*isCxx=0/isCxx=1/' $out/bin/icpx
).overrideAttrs
# 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: { (old: {
installPhase = old.installPhase + extraInstall; installPhase = old.installPhase + ''
export named_cc="icx"
export named_cxx="icpx"
export named_fc="ifx"
'';
}); });
in in
@ -176,33 +182,7 @@ lib.makeOverridable (
stdenv = overrideCC stdenv finalAttrs.finalPackage.cc; stdenv = overrideCC stdenv finalAttrs.finalPackage.cc;
cc = wrapIntel { cc = wrapIntel finalAttrs.finalPackage.pkgs.compiler;
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"
'';
};
}; };
}) })