{bintools,cc}-wrapper: set up Darwin SDK paths

Some compilers may know to check these paths when `SDKROOT` is set, but
it’s not assumed they do. `SDKROOT` is instead derived from the
`DEVELOPER_DIR`, and `NIX_CFLAGS_COMPILE` is set up with the sysroot and
necessary framework and include search paths.

+27 -1
+10
pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh
··· 79 79 extraBefore+=(-@darwinPlatform@_version_min "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}") 80 80 fi 81 81 fi 82 + 83 + mangleVarSingle DEVELOPER_DIR ${role_suffixes[@]+"${role_suffixes[@]}"} 84 + 85 + # Allow wrapped bintools to do something useful when no `DEVELOPER_DIR` is set, which can happen when 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@} 88 + 89 + # Darwin looks for frameworks in the SDK located at `DEVELOPER_DIR`. 90 + extraBefore+=("-F$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks") 91 + extraBefore+=("-L$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib")
+17 -1
pkgs/build-support/cc-wrapper/add-flags.sh
··· 78 78 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="$(< @out@/nix-support/cc-cflags-before) $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@" 79 79 fi 80 80 81 - # Only add darwin min version flag if a default darwin min version is set, 81 + # Only add darwin min version flag and set up `DEVELOPER_DIR` if a default darwin min version is set, 82 82 # which is a signal that we're targetting darwin. 83 83 if [ "@darwinMinVersion@" ]; then 84 84 mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"} 85 85 86 86 NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="-m@darwinPlatformForCC@-version-min=${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@} $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@" 87 + 88 + # `DEVELOPER_DIR` is used to dynamically locate libSystem (and the SDK frameworks) based on the SDK at that path. 89 + mangleVarSingle DEVELOPER_DIR ${role_suffixes[@]+"${role_suffixes[@]}"} 90 + 91 + # Allow wrapped compilers to do something useful when no `DEVELOPER_DIR` is set, which can happen when 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@} 94 + 95 + # xcbuild needs `SDKROOT` to be the name of the SDK, which it sets in its own wrapper, 96 + # but compilers expect it to point to the absolute path. 97 + SDKROOT="$DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" 98 + 99 + # Set up various library paths since compilers may not support (or may have disabled) finding them in the sysroot. 100 + NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@+=" -isysroot $SDKROOT" 101 + NIX_CFLAGS_COMPILE_@suffixSalt@+=" -idirafter $SDKROOT/usr/include" 102 + NIX_CFLAGS_COMPILE_@suffixSalt@+=" -iframework $SDKROOT/System/Library/Frameworks" 87 103 fi 88 104 89 105 # That way forked processes will not extend these environment variables again.