bintools-wrapper: default platform versions for darwin

Instead of always supplying flags, apply the flags as defaults. Use
clang's native flags instead of lifting the linker flags from binutils
with `-Wl,`.

If a project is using clang to drive linking, make clang do the right
thing with MACOSX_DEPLOYMENT_TARGET. This can be overridden by command
line arguments. This will cause modern clang to pass
`-platform_version 10.12 0.0.0`, since it doesn't know about the SDK
settings. Older versions of clang will pass down `-macos_version_min`
flags with no sdk version.

At the linker layer, apply a default value for anything left
ambiguous. If nothing is specified, pass a full
`-platform_version`. If only `-macos_version_min` is specified, then
lock down the sdk_version explicitly with `-sdk_version`. If a min
version and sdk version is passed, do nothing.
This commit is contained in:
Andrew Childs
2021-04-11 09:47:09 +09:00
parent 44f09ccabf
commit 6605fadc68
4 changed files with 100 additions and 5 deletions
@@ -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,20 @@ 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) darwinMinVersion darwinPlatform darwinSdkVersion;
in ''
export darwinPlatform=${darwinPlatform}
export darwinMinVersion=${darwinMinVersion}
export darwinSdkVersion=${darwinSdkVersion}
substituteAll ${./add-darwin-ldflags-before.sh} $out/nix-support/add-local-ldflags-before.sh
''
)
##
## Extra custom steps
##