From 6c4ce7960ebcd5559bedb68bef4acf32b44321d1 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Sat, 10 Apr 2021 18:06:25 +0900 Subject: [PATCH] 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 https://github.com/tpoechtrager/cctools-port/blob/236a426c1205a3bfcf0dbb2e2faf2296f0a100e5/cctools/ld64/src/ld/PlatformSupport.cpp#L54-L55 --- lib/systems/default.nix | 4 ++++ .../bintools-wrapper/add-darwin-ldflags-before.sh | 6 +++--- pkgs/build-support/bintools-wrapper/default.nix | 5 ++++- pkgs/build-support/cc-wrapper/add-flags.sh | 4 ++-- pkgs/build-support/cc-wrapper/default.nix | 5 ++++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index d16b19c03caa..21b00374da47 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -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 { diff --git a/pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh b/pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh index 318311e1be9d..bd3edda3f2e7 100644 --- a/pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh +++ b/pkgs/build-support/bintools-wrapper/add-darwin-ldflags-before.sh @@ -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 diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 77185e800e3e..859e37905949 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -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 '' ) diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh index f7276b04e549..a6e991914e6b 100644 --- a/pkgs/build-support/cc-wrapper/add-flags.sh +++ b/pkgs/build-support/cc-wrapper/add-flags.sh @@ -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. diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 834c4e6d46a7..db751593701e 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -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" ];