diff options
author | Andrew Childs <lorne@cons.org.nz> | 2021-04-10 13:11:28 +0900 |
---|---|---|
committer | Andrew Childs <lorne@cons.org.nz> | 2021-04-11 09:47:10 +0900 |
commit | 2a9b3b4943bea5d778da184828492e92512db324 (patch) | |
tree | a5dc618dcb779abb80ac71b341dbe6545d10e575 /pkgs/build-support/cc-wrapper | |
parent | 8b59d52ca3b6157f4cac333e6576c76f1fa546e8 (diff) | |
download | nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.tar nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.tar.gz nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.tar.bz2 nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.tar.lz nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.tar.xz nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.tar.zst nixpkgs-2a9b3b4943bea5d778da184828492e92512db324.zip |
cc-wrapper, bintools-wrapper: support MACOSX_DEPLOYMENT_TARGET with roles
In a typical build environment the toolchain will use the value of the MACOSX_DEPLOYMENT_TARGET environment variable to determine the version of macOS to support. When cross compiling there are two distinct toolchains, but they will look at this single environment variable. To avoid contamination, we always set the equivalent command line flag which effectively disables the toolchain's internal handling. Prior to this change, the MACOSX_DEPLOYMENT_TARGET variable was ignored, and the toolchains always used the Nix platform definition (`darwinMinVersion`) unless overridden with command line arguments. This change restores support for MACOSX_DEPLOYMENT_TARGET, and adds nix-specific MACOSX_DEPLOYMENT_TARGET_FOR_BUILD and MACOSX_DEPLOYMENT_TARGET_FOR_TARGET for cross compilation.
Diffstat (limited to 'pkgs/build-support/cc-wrapper')
-rw-r--r-- | pkgs/build-support/cc-wrapper/add-flags.sh | 8 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 24 |
2 files changed, 22 insertions, 10 deletions
diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh index 94589131b70..f7276b04e54 100644 --- a/pkgs/build-support/cc-wrapper/add-flags.sh +++ b/pkgs/build-support/cc-wrapper/add-flags.sh @@ -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 MACOSX_DEPLOYMENT_TARGET ${role_suffixes[@]+"${role_suffixes[@]}"} + + NIX_CFLAGS_COMPILE_BEFORE_@suffixSalt@="-m@darwinPlatformForCC@-version-min=${MACOSX_DEPLOYMENT_TARGET_@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 diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 3d2a142c36d..834c4e6d46a 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -100,6 +100,15 @@ 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 + ); in # Ensure bintools matches @@ -122,6 +131,7 @@ stdenv.mkDerivation { gnugrep_bin = if nativeTools then "" else gnugrep; inherit targetPrefix suffixSalt; + inherit darwinPlatformForCC darwinMinVersion; outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ]; @@ -473,6 +483,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,16 +499,6 @@ stdenv.mkDerivation { substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash '' - + optionalString stdenv.targetPlatform.isDarwin ( - let darwinPlatformForCC = - if (targetPlatform.darwinPlatform == "macos" && isGNU) then "macosx" - else targetPlatform.darwinPlatform; - in '' - echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags - echo "-m${darwinPlatformForCC}-version-min=${targetPlatform.darwinMinVersion}" >> $out/nix-support/cc-cflags-before - '' - ) - ## ## Extra custom steps ## |