stdenv: throw when using mold for targeting darwin (#338984)

authored by Artturin and committed by GitHub d60e6bf8 2349afa4

+21 -19
+21 -19
pkgs/stdenv/adapters.nix
··· 261 261 in 262 262 overrideCC targetStdenv cc; 263 263 264 - useMoldLinker = stdenv: let 265 - bintools = stdenv.cc.bintools.override { 266 - extraBuildCommands = '' 267 - wrap ${stdenv.cc.bintools.targetPrefix}ld.mold ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold 268 - wrap ${stdenv.cc.bintools.targetPrefix}ld ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold 269 - ''; 270 - }; 271 - in stdenv.override (old: { 272 - allowedRequisites = null; 273 - cc = stdenv.cc.override { inherit bintools; }; 274 - # gcc >12.1.0 supports '-fuse-ld=mold' 275 - # the wrap ld above in bintools supports gcc <12.1.0 and shouldn't harm >12.1.0 276 - # https://github.com/rui314/mold#how-to-use 277 - } // lib.optionalAttrs (stdenv.cc.isClang || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.version "12")) { 278 - mkDerivationFromStdenv = extendMkDerivationArgs old (args: { 279 - NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold"; 280 - }); 281 - }); 282 - 264 + useMoldLinker = stdenv: 265 + if stdenv.targetPlatform.isDarwin 266 + then throw "Mold can't be used to emit Mach-O (Darwin) binaries" 267 + else let 268 + bintools = stdenv.cc.bintools.override { 269 + extraBuildCommands = '' 270 + wrap ${stdenv.cc.bintools.targetPrefix}ld.mold ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold 271 + wrap ${stdenv.cc.bintools.targetPrefix}ld ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold 272 + ''; 273 + }; 274 + in stdenv.override (old: { 275 + allowedRequisites = null; 276 + cc = stdenv.cc.override { inherit bintools; }; 277 + # gcc >12.1.0 supports '-fuse-ld=mold' 278 + # the wrap ld above in bintools supports gcc <12.1.0 and shouldn't harm >12.1.0 279 + # https://github.com/rui314/mold#how-to-use 280 + } // lib.optionalAttrs (stdenv.cc.isClang || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.version "12")) { 281 + mkDerivationFromStdenv = extendMkDerivationArgs old (args: { 282 + NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold"; 283 + }); 284 + }); 283 285 284 286 /* Modify a stdenv so that it builds binaries optimized specifically 285 287 for the machine they are built on.