useMoldLinker
pkgs.useMoldLinker
Docs pulled from | This Revision | 18 days ago
Contribute
Enhance the ecosystem with your expertise! Contribute to fill the gaps in documentation. Your input can make a difference.
Noogle detected
Implementation
The following is the current implementation of this function.
stdenv:
if stdenv.targetPlatform.isDarwin then
throw "Mold can't be used to emit Mach-O (Darwin) binaries"
else
let
bintools = stdenv.cc.bintools.override {
extraBuildCommands = ''
pushd $out/bin
ln -s ${pkgs.buildPackages.mold}/bin/${stdenv.cc.bintools.targetPrefix}ld.mold ${stdenv.cc.bintools.targetPrefix}ld.mold
'' # Pre-generated configure scripts call the linker binary without the target prefix when cross compiling.
+ lib.optionalString (stdenv.cc.bintools.targetPrefix != "") ''
ln -s ${stdenv.cc.bintools.targetPrefix}ld.mold ld.mold
''
+ ''
popd
'';
};
in
stdenv.override (
old:
{
allowedRequisites = null;
cc = stdenv.cc.override { inherit bintools; };
# gcc >12.1.0 supports '-fuse-ld=mold'
# the wrap ld above in bintools supports gcc <12.1.0 and shouldn't harm >12.1.0
# https://github.com/rui314/mold#how-to-use
}
//
lib.optionalAttrs
(stdenv.cc.isClang || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.version "12"))
{
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
env = (args.env or { }) // {
NIX_CFLAGS_LINK = toString (args.env.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold";
};
});
}
)