Merge pull request #111988 from thefloweringash/darwin-platform-versions
Darwin platform versions
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
# Unconditionally adding in platform version flags will result in warnings that
|
||||
# will be treated as errors by some packages. Add any missing flags here.
|
||||
|
||||
# There are two things to be configured: the "platform version" (oldest
|
||||
# supported version of macos, ios, etc), and the "sdk version".
|
||||
#
|
||||
# The modern way of configuring these is to use:
|
||||
# -platform_version $platform $platform_version $sdk_version"
|
||||
#
|
||||
# The old way is still supported, and uses flags like:
|
||||
# -${platform}_version_min $platform_version
|
||||
# -sdk_version $sdk_version
|
||||
#
|
||||
# If both styles are specified ld will combine them. If multiple versions are
|
||||
# specified for the same platform, ld will emit an error.
|
||||
#
|
||||
# The following adds flags for whichever properties have not already been
|
||||
# provided.
|
||||
|
||||
havePlatformVersionFlag=
|
||||
haveDarwinSDKVersion=
|
||||
haveDarwinPlatformVersion=
|
||||
|
||||
# Roles will set by add-flags.sh, but add-flags.sh can be skipped when the
|
||||
# cc-wrapper has added the linker flags. Both the cc-wrapper and the binutils
|
||||
# wrapper mangle the same variable (MACOSX_DEPLOYMENT_TARGET), so if roles are
|
||||
# empty due to being run through the cc-wrapper then the mangle here is a no-op
|
||||
# and we still do the right thing.
|
||||
#
|
||||
# To be robust, make sure we always have the correct set of roles.
|
||||
accumulateRoles
|
||||
|
||||
mangleVarSingle @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
|
||||
|
||||
n=0
|
||||
nParams=${#params[@]}
|
||||
while (( n < nParams )); do
|
||||
p=${params[n]}
|
||||
case "$p" in
|
||||
# the current platform
|
||||
-@darwinPlatform@_version_min)
|
||||
haveDarwinPlatformVersion=1
|
||||
;;
|
||||
|
||||
# legacy aliases
|
||||
-macosx_version_min|-iphoneos_version_min|-iosmac_version_min|-uikitformac_version_min)
|
||||
haveDarwinPlatformVersion=1
|
||||
;;
|
||||
|
||||
-sdk_version)
|
||||
haveDarwinSDKVersion=1
|
||||
;;
|
||||
|
||||
-platform_version)
|
||||
havePlatformVersionFlag=1
|
||||
|
||||
# If clang can't determine the sdk version it will pass 0.0.0. This
|
||||
# has runtime effects so we override this to use the known sdk
|
||||
# version.
|
||||
if [ "${params[n+3]-}" = 0.0.0 ]; then
|
||||
params[n+3]=@darwinSdkVersion@
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
n=$((n + 1))
|
||||
done
|
||||
|
||||
# If the caller has set -platform_version, trust they're doing the right thing.
|
||||
# This will be the typical case for clang in nixpkgs.
|
||||
if [ ! "$havePlatformVersionFlag" ]; then
|
||||
if [ ! "$haveDarwinSDKVersion" ] && [ ! "$haveDarwinPlatformVersion" ]; then
|
||||
# Nothing provided. Use the modern "-platform_version" to set both.
|
||||
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 "${@darwinMinVersionVariable@_@suffixSalt@:-@darwinMinVersion@}")
|
||||
fi
|
||||
fi
|
||||
@@ -252,11 +252,6 @@ stdenv.mkDerivation {
|
||||
fi
|
||||
'')
|
||||
|
||||
# Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID.
|
||||
+ optionalString stdenv.targetPlatform.isMacOS ''
|
||||
echo "-sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before
|
||||
''
|
||||
|
||||
##
|
||||
## User env support
|
||||
##
|
||||
@@ -310,6 +305,13 @@ stdenv.mkDerivation {
|
||||
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/libc-ldflags
|
||||
''
|
||||
|
||||
###
|
||||
### Remove LC_UUID
|
||||
###
|
||||
+ optionalString (stdenv.targetPlatform.isDarwin && !(stdenv.cc.bintools.bintools.isGNU or false)) ''
|
||||
echo "-no_uuid" >> $out/nix-support/libc-ldflags-before
|
||||
''
|
||||
|
||||
+ ''
|
||||
for flags in "$out/nix-support"/*flags*; do
|
||||
substituteInPlace "$flags" --replace $'\n' ' '
|
||||
@@ -320,6 +322,23 @@ stdenv.mkDerivation {
|
||||
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
|
||||
''
|
||||
|
||||
###
|
||||
### Ensure consistent LC_VERSION_MIN_MACOSX
|
||||
###
|
||||
+ optionalString stdenv.targetPlatform.isDarwin (
|
||||
let
|
||||
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
|
||||
''
|
||||
)
|
||||
|
||||
##
|
||||
## Extra custom steps
|
||||
##
|
||||
|
||||
@@ -78,6 +78,14 @@ fi
|
||||
|
||||
extraAfter+=($NIX_LDFLAGS_AFTER_@suffixSalt@)
|
||||
|
||||
# These flags *must not* be pulled up to -Wl, flags, so they can't go in
|
||||
# add-flags.sh. They must always be set, so must not be disabled by
|
||||
# NIX_LDFLAGS_SET.
|
||||
if [ -e @out@/nix-support/add-local-ldflags-before.sh ]; then
|
||||
source @out@/nix-support/add-local-ldflags-before.sh
|
||||
fi
|
||||
|
||||
|
||||
# Specify the target emulation if nothing is passed in ("-m" overrides this
|
||||
# environment variable). Ensures we never blindly fallback on targeting the host
|
||||
# platform.
|
||||
|
||||
@@ -65,5 +65,13 @@ if [ -e @out@/nix-support/cc-cflags-before ]; then
|
||||
NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="$(< @out@/nix-support/cc-cflags-before) $NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@"
|
||||
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 @darwinMinVersionVariable@ ${role_suffixes[@]+"${role_suffixes[@]}"}
|
||||
|
||||
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.
|
||||
export NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@=1
|
||||
|
||||
@@ -100,6 +100,18 @@ let
|
||||
else
|
||||
false;
|
||||
|
||||
|
||||
darwinPlatformForCC = optionalString stdenv.targetPlatform.isDarwin (
|
||||
if (targetPlatform.darwinPlatform == "macos" && isGNU) then "macosx"
|
||||
else targetPlatform.darwinPlatform
|
||||
);
|
||||
|
||||
darwinMinVersion = optionalString stdenv.targetPlatform.isDarwin (
|
||||
stdenv.targetPlatform.darwinMinVersion
|
||||
);
|
||||
|
||||
darwinMinVersionVariable = optionalString stdenv.targetPlatform.isDarwin
|
||||
stdenv.targetPlatform.darwinMinVersionVariable;
|
||||
in
|
||||
|
||||
# Ensure bintools matches
|
||||
@@ -122,6 +134,7 @@ stdenv.mkDerivation {
|
||||
gnugrep_bin = if nativeTools then "" else gnugrep;
|
||||
|
||||
inherit targetPrefix suffixSalt;
|
||||
inherit darwinPlatformForCC darwinMinVersion darwinMinVersionVariable;
|
||||
|
||||
outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ];
|
||||
|
||||
@@ -473,6 +486,10 @@ stdenv.mkDerivation {
|
||||
done
|
||||
''
|
||||
|
||||
+ optionalString stdenv.targetPlatform.isDarwin ''
|
||||
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags
|
||||
''
|
||||
|
||||
# There are a few tools (to name one libstdcxx5) which do not work
|
||||
# well with multi line flags, so make the flags single line again
|
||||
+ ''
|
||||
@@ -485,10 +502,6 @@ stdenv.mkDerivation {
|
||||
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
|
||||
''
|
||||
|
||||
+ optionalString stdenv.targetPlatform.isDarwin ''
|
||||
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags
|
||||
''
|
||||
|
||||
##
|
||||
## Extra custom steps
|
||||
##
|
||||
|
||||
@@ -49,6 +49,35 @@ mangleVarBool() {
|
||||
done
|
||||
}
|
||||
|
||||
# Combine a singular value from all roles. If multiple roles are being served,
|
||||
# and the value differs in these roles then the request is impossible to
|
||||
# satisfy and we abort immediately.
|
||||
mangleVarSingle() {
|
||||
local var="$1"
|
||||
shift
|
||||
local -a role_suffixes=("$@")
|
||||
|
||||
local outputVar="${var}_@suffixSalt@"
|
||||
for suffix in "${role_suffixes[@]}"; do
|
||||
local inputVar="${var}${suffix}"
|
||||
if [ -v "$inputVar" ]; then
|
||||
if [ -v "$outputVar" ]; then
|
||||
if [ "${!outputVar}" != "${!inputVar}" ]; then
|
||||
{
|
||||
echo "Multiple conflicting values defined for $outputVar"
|
||||
echo "Existing value is ${!outputVar}"
|
||||
echo "Attempting to set to ${!inputVar} via $inputVar"
|
||||
} >&2
|
||||
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
declare -gx ${outputVar}="${!inputVar}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
skip () {
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "skipping impure path $1" >&2
|
||||
|
||||
Reference in New Issue
Block a user