bintools-wrapper, cc-wrapper: parameterize darwin min version variable

These variables are the ones that the standard toolchain uses, so we
should use those and not always use MACOSX_DEPLOYMENT_TARGET.

See 236a426c12/cctools/ld64/src/ld/PlatformSupport.cpp (L54-L55)
This commit is contained in:
Andrew Childs 2021-04-10 18:06:25 +09:00
parent 2a9b3b4943
commit 6c4ce7960e
5 changed files with 17 additions and 7 deletions

View file

@ -120,6 +120,10 @@ rec {
# platforms define the old name "sdkVer".
darwinSdkVersion = final.sdkVer or "10.12";
darwinMinVersion = final.darwinSdkVersion;
darwinMinVersionVariable =
if final.isMacOS then "MACOSX_DEPLOYMENT_TARGET"
else if final.isiOS then "IPHONEOS_DEPLOYMENT_TARGET"
else null;
emulator = pkgs: let
qemu-user = pkgs.qemu.override {

View file

@ -21,7 +21,7 @@ havePlatformVersionFlag=
haveDarwinSDKVersion=
haveDarwinPlatformVersion=
mangleVarSingle MACOSX_DEPLOYMENT_TARGET ${role_suffixes[@]+"${role_suffixes[@]}"}
mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
n=0
nParams=${#params[@]}
@ -61,12 +61,12 @@ done
if [ ! "$havePlatformVersionFlag" ]; then
if [ ! "$haveDarwinSDKVersion" ] && [ ! "$haveDarwinPlatformVersion" ]; then
# Nothing provided. Use the modern "-platform_version" to set both.
extraBefore+=(-platform_version @darwinPlatform@ "${MACOSX_DEPLOYMENT_TARGET_@suffixSalt@:-@darwinMinVersion@}" @darwinSdkVersion@)
extraBefore+=(-platform_version @darwinPlatform@ "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}" @darwinSdkVersion@)
elif [ ! "$haveDarwinSDKVersion" ]; then
# Add missing sdk version
extraBefore+=(-sdk_version @darwinSdkVersion@)
elif [ ! "$haveDarwinPlatformVersion" ]; then
# Add missing platform version
extraBefore+=(-@darwinPlatform@_version_min "${MACOSX_DEPLOYMENT_TARGET_@suffixSalt@:-@darwinMinVersion@}")
extraBefore+=(-@darwinPlatform@_version_min "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}")
fi
fi

View file

@ -327,11 +327,14 @@ stdenv.mkDerivation {
###
+ optionalString stdenv.targetPlatform.isDarwin (
let
inherit (stdenv.targetPlatform) darwinMinVersion darwinPlatform darwinSdkVersion;
inherit (stdenv.targetPlatform)
darwinPlatform darwinSdkVersion
darwinMinVersion darwinMinVersionVariable;
in ''
export darwinPlatform=${darwinPlatform}
export darwinMinVersion=${darwinMinVersion}
export darwinSdkVersion=${darwinSdkVersion}
export darwinMinVersionVariable=${darwinMinVersionVariable}
substituteAll ${./add-darwin-ldflags-before.sh} $out/nix-support/add-local-ldflags-before.sh
''
)

View file

@ -68,9 +68,9 @@ fi
# Only add darwin min version flag if a default darwin min version is set,
# which is a signal that we're targetting darwin.
if [ "@darwinMinVersion@" ]; then
mangleVarSingle MACOSX_DEPLOYMENT_TARGET ${role_suffixes[@]+"${role_suffixes[@]}"}
mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="-m@darwinPlatformForCC@-version-min=${MACOSX_DEPLOYMENT_TARGET_@suffixSalt@:-@darwinMinVersion@} $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="-m@darwinPlatformForCC@-version-min=${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@} $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
fi
# That way forked processes will not extend these environment variables again.

View file

@ -109,6 +109,9 @@ let
darwinMinVersion = optionalString stdenv.targetPlatform.isDarwin (
stdenv.targetPlatform.darwinMinVersion
);
darwinMinVersionVariable = optionalString stdenv.targetPlatform.isDarwin
stdenv.targetPlatform.darwinMinVersionVariable;
in
# Ensure bintools matches
@ -131,7 +134,7 @@ stdenv.mkDerivation {
gnugrep_bin = if nativeTools then "" else gnugrep;
inherit targetPrefix suffixSalt;
inherit darwinPlatformForCC darwinMinVersion;
inherit darwinPlatformForCC darwinMinVersion darwinMinVersionVariable;
outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ];