{bintools,cc}-wrapper: use a fallback SDK when `DEVELOPER_DIR` is not set

It is unusual to invoke a wrapped compiler without setting
`DEVELOPER_DIR`, but it can happen when a user adds a compiler to their
installed packages or when a package intentionally invokes the compiler
without an environment (such as the GHC binary packages).

+10 -2
+1 -1
pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh
··· 84 84 85 85 # Allow wrapped bintools to do something useful when no `DEVELOPER_DIR` is set, which can happen when 86 86 # the compiler is run outside of a stdenv or intentionally in an environment with no environment variables set. 87 - DEVELOPER_DIR=${DEVELOPER_DIR_@suffixSalt@} 87 + DEVELOPER_DIR=${DEVELOPER_DIR_@suffixSalt@:-@fallback_sdk@} 88 88 89 89 # Darwin looks for frameworks in the SDK located at `DEVELOPER_DIR`. 90 90 extraBefore+=("-F$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks")
+4
pkgs/build-support/bintools-wrapper/default.nix
··· 10 10 , stdenvNoCC 11 11 , runtimeShell 12 12 , bintools ? null, libc ? null, coreutils ? null, gnugrep ? null 13 + , apple-sdk ? null 13 14 , netbsd ? null 14 15 , sharedLibraryLoader ? 15 16 if libc == null then ··· 412 413 inherit dynamicLinker targetPrefix suffixSalt coreutils_bin; 413 414 inherit bintools_bin libc_bin libc_dev libc_lib; 414 415 default_hardening_flags_str = builtins.toString defaultHardeningFlags; 416 + } // lib.optionalAttrs (apple-sdk != null && stdenvNoCC.targetPlatform.isDarwin) { 417 + # Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`. 418 + fallback_sdk = apple-sdk.__spliced.buildTarget or apple-sdk; 415 419 }; 416 420 417 421 meta =
+1 -1
pkgs/build-support/cc-wrapper/add-flags.sh
··· 90 90 91 91 # Allow wrapped compilers to do something useful when no `DEVELOPER_DIR` is set, which can happen when 92 92 # the compiler is run outside of a stdenv or intentionally in an environment with no environment variables set. 93 - DEVELOPER_DIR=${DEVELOPER_DIR_@suffixSalt@} 93 + DEVELOPER_DIR=${DEVELOPER_DIR_@suffixSalt@:-@fallback_sdk@} 94 94 95 95 # xcbuild needs `SDKROOT` to be the name of the SDK, which it sets in its own wrapper, 96 96 # but compilers expect it to point to the absolute path.
+4
pkgs/build-support/cc-wrapper/default.nix
··· 10 10 , stdenvNoCC 11 11 , runtimeShell 12 12 , cc ? null, libc ? null, bintools, coreutils ? null 13 + , apple-sdk ? null 13 14 , zlib ? null 14 15 , nativeTools, noLibc ? false, nativeLibc, nativePrefix ? "" 15 16 , propagateDoc ? cc != null && cc ? man ··· 749 750 inherit libc_bin libc_dev libc_lib; 750 751 inherit darwinPlatformForCC darwinMinVersion darwinMinVersionVariable; 751 752 default_hardening_flags_str = builtins.toString defaultHardeningFlags; 753 + } // lib.optionalAttrs (apple-sdk != null && stdenvNoCC.targetPlatform.isDarwin) { 754 + # Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`. 755 + fallback_sdk = apple-sdk.__spliced.buildTarget or apple-sdk; 752 756 }; 753 757 754 758 meta =