From 0884027ef56c0e7cac94e1c0a42c2a1610c8ef5c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 11 Apr 2018 14:00:13 -0400 Subject: Revert "Revert "Merge pull request #28029 from cstrahan/hardening-fix"" This reverts commit 6c064e6b1f34a8416f990db0cc617a7195f71588, reapplying PR #28029 which was supposed to have gone to staging all along. --- pkgs/build-support/bintools-wrapper/add-flags.sh | 5 +- .../bintools-wrapper/add-hardening.sh | 87 ++++++++++++---------- pkgs/build-support/bintools-wrapper/ld-wrapper.sh | 4 +- pkgs/build-support/bintools-wrapper/setup-hook.sh | 4 + 4 files changed, 55 insertions(+), 45 deletions(-) (limited to 'pkgs/build-support/bintools-wrapper') diff --git a/pkgs/build-support/bintools-wrapper/add-flags.sh b/pkgs/build-support/bintools-wrapper/add-flags.sh index 7d118d20fc68..a97809258954 100644 --- a/pkgs/build-support/bintools-wrapper/add-flags.sh +++ b/pkgs/build-support/bintools-wrapper/add-flags.sh @@ -5,6 +5,7 @@ var_templates_list=( NIX+LDFLAGS_BEFORE NIX+LDFLAGS_AFTER NIX+LDFLAGS_HARDEN + NIX+HARDENING_ENABLE ) var_templates_bool=( NIX+SET_BUILD_ID @@ -23,10 +24,10 @@ if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then fi for var in "${var_templates_list[@]}"; do - mangleVarList "$var" "${role_infixes[@]}" + mangleVarList "$var" ${role_infixes[@]+"${role_infixes[@]}"} done for var in "${var_templates_bool[@]}"; do - mangleVarBool "$var" "${role_infixes[@]}" + mangleVarBool "$var" ${role_infixes[@]+"${role_infixes[@]}"} done if [ -e @out@/nix-support/libc-ldflags ]; then diff --git a/pkgs/build-support/bintools-wrapper/add-hardening.sh b/pkgs/build-support/bintools-wrapper/add-hardening.sh index 5282d17fce27..a15be821659f 100644 --- a/pkgs/build-support/bintools-wrapper/add-hardening.sh +++ b/pkgs/build-support/bintools-wrapper/add-hardening.sh @@ -1,53 +1,58 @@ -hardeningFlags=(relro bindnow) -# Intentionally word-split in case 'hardeningEnable' is defined in -# Nix. Also, our bootstrap tools version of bash is old enough that -# undefined arrays trip `set -u`. -if [[ -v hardeningEnable[@] ]]; then - hardeningFlags+=(${hardeningEnable[@]}) -fi -hardeningLDFlags=() +declare -a hardeningLDFlags=() + +declare -A hardeningEnableMap=() -declare -A hardeningDisableMap +# Intentionally word-split in case 'NIX_HARDENING_ENABLE' is defined in Nix. The +# array expansion also prevents undefined variables from causing trouble with +# `set -u`. +for flag in ${NIX_@infixSalt@_HARDENING_ENABLE-}; do + hardeningEnableMap["$flag"]=1 +done -# Intentionally word-split in case 'hardeningDisable' is defined in Nix. -for flag in ${hardeningDisable[@]:-IGNORED_KEY} @hardening_unsupported_flags@ -do - hardeningDisableMap[$flag]=1 +# Remove unsupported flags. +for flag in @hardening_unsupported_flags@; do + unset -v hardeningEnableMap["$flag"] done if (( "${NIX_DEBUG:-0}" >= 1 )); then + declare -a allHardeningFlags=(pie relro bindnow) + declare -A hardeningDisableMap=() + + # Determine which flags were effectively disabled so we can report below. + for flag in "${allHardeningFlags[@]}"; do + if [[ -z "${hardeningEnableMap[$flag]-}" ]]; then + hardeningDisableMap[$flag]=1 + fi + done + printf 'HARDENING: disabled flags:' >&2 (( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2 echo >&2 -fi -if [[ -z "${hardeningDisableMap[all]:-}" ]]; then - if (( "${NIX_DEBUG:-0}" >= 1 )); then + if (( "${#hardeningEnableMap[@]}" )); then echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2; fi - for flag in "${hardeningFlags[@]}" - do - if [[ -z "${hardeningDisableMap[$flag]:-}" ]]; then - case $flag in - pie) - if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then - if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi - hardeningLDFlags+=('-pie') - fi - ;; - relro) - if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling relro >&2; fi - hardeningLDFlags+=('-z' 'relro') - ;; - bindnow) - if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling bindnow >&2; fi - hardeningLDFlags+=('-z' 'now') - ;; - *) - # Ignore unsupported. Checked in Nix that at least *some* - # tool supports each flag. - ;; - esac - fi - done fi + +for flag in "${!hardeningEnableMap[@]}"; do + case $flag in + pie) + if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then + if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi + hardeningLDFlags+=('-pie') + fi + ;; + relro) + if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling relro >&2; fi + hardeningLDFlags+=('-z' 'relro') + ;; + bindnow) + if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling bindnow >&2; fi + hardeningLDFlags+=('-z' 'now') + ;; + *) + # Ignore unsupported. Checked in Nix that at least *some* + # tool supports each flag. + ;; + esac +done diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index 991ed0fe263c..672a3dcbe385 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -57,8 +57,8 @@ fi source @out@/nix-support/add-hardening.sh -extraAfter=("${hardeningLDFlags[@]}") -extraBefore=() +extraAfter=() +extraBefore=(${hardeningLDFlags[@]+"${hardeningLDFlags[@]}"}) if [ -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ]; then extraAfter+=($NIX_@infixSalt@_LDFLAGS) diff --git a/pkgs/build-support/bintools-wrapper/setup-hook.sh b/pkgs/build-support/bintools-wrapper/setup-hook.sh index 48a00b0b9b07..831ee9b03872 100644 --- a/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -83,6 +83,10 @@ do fi done +# If unset, assume the default hardening flags. +: ${NIX_HARDENING_ENABLE="fortify stackprotector pic strictoverflow format relro bindnow"} +export NIX_HARDENING_ENABLE + # No local scope in sourced file unset -v role_pre role_post cmd upper_case set +u -- cgit 1.4.1 From 4707dc6454904bee0bacd3a53829bcc76b4f0667 Mon Sep 17 00:00:00 2001 From: Piotr Bogdan Date: Sat, 14 Apr 2018 15:16:34 +0100 Subject: {cc,bintools}-wrapper: fix removal of unsupported hardening flags --- pkgs/build-support/bintools-wrapper/add-hardening.sh | 2 +- pkgs/build-support/cc-wrapper/add-hardening.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support/bintools-wrapper') diff --git a/pkgs/build-support/bintools-wrapper/add-hardening.sh b/pkgs/build-support/bintools-wrapper/add-hardening.sh index a15be821659f..b7180870860a 100644 --- a/pkgs/build-support/bintools-wrapper/add-hardening.sh +++ b/pkgs/build-support/bintools-wrapper/add-hardening.sh @@ -11,7 +11,7 @@ done # Remove unsupported flags. for flag in @hardening_unsupported_flags@; do - unset -v hardeningEnableMap["$flag"] + unset -v "hardeningEnableMap[$flag]" done if (( "${NIX_DEBUG:-0}" >= 1 )); then diff --git a/pkgs/build-support/cc-wrapper/add-hardening.sh b/pkgs/build-support/cc-wrapper/add-hardening.sh index 026e48671447..fc40fe7408b6 100644 --- a/pkgs/build-support/cc-wrapper/add-hardening.sh +++ b/pkgs/build-support/cc-wrapper/add-hardening.sh @@ -11,7 +11,7 @@ done # Remove unsupported flags. for flag in @hardening_unsupported_flags@; do - unset -v hardeningEnableMap["$flag"] + unset -v "hardeningEnableMap[$flag]" done if (( "${NIX_DEBUG:-0}" >= 1 )); then -- cgit 1.4.1 From 82dd4501f405800202b0485c1bab5575f30be80a Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Sun, 15 Apr 2018 00:00:01 +0000 Subject: bintools-wrapper, cc-wrapper: don't add `targetPrefix` the second time ... binutils and gcc add it already anyway. Without this it's easy to get cross-toolchain paths longer than 256 chars and nix-daemon will then fail to commit them to /nix/store on XFS. --- pkgs/build-support/bintools-wrapper/default.nix | 2 +- pkgs/build-support/cc-wrapper/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support/bintools-wrapper') diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 5c0436b73ddf..a4e2ecb63b81 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -74,7 +74,7 @@ in stdenv.mkDerivation { name = targetPrefix - + (if name != "" then name else "${bintoolsName}-wrapper") + + (if name != "" then name else stdenv.lib.removePrefix targetPrefix "${bintoolsName}-wrapper") + (stdenv.lib.optionalString (bintools != null && bintoolsVersion != "") "-${bintoolsVersion}"); preferLocalBuild = true; diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 43cd87fb4597..700e7547b7ae 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -71,7 +71,7 @@ assert nativePrefix == bintools.nativePrefix; stdenv.mkDerivation { name = targetPrefix - + (if name != "" then name else "${ccName}-wrapper") + + (if name != "" then name else stdenv.lib.removePrefix targetPrefix "${ccName}-wrapper") + (stdenv.lib.optionalString (cc != null && ccVersion != "") "-${ccVersion}"); preferLocalBuild = true; -- cgit 1.4.1 From 2110c0bd3009279ceec291f07bfbf063cb5ba6a0 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 7 May 2018 13:07:19 -0400 Subject: treewide: Use pkgs/build-support/roles.bash to remove copy pasta Also fix some setup hooks that unnecessarily used environment hooks, which revolted in the same variable being modified too many times. --- pkgs/build-support/bintools-wrapper/default.nix | 7 +- pkgs/build-support/bintools-wrapper/setup-hook.sh | 38 +++-------- pkgs/build-support/cc-wrapper/default.nix | 7 +- pkgs/build-support/cc-wrapper/setup-hook.sh | 49 +++----------- pkgs/build-support/setup-hooks/role.bash | 75 ++++++++++++++++++++++ pkgs/development/compilers/gcc/libstdc++-hook.sh | 16 ++--- .../compilers/llvm/3.5/libc++/default.nix | 5 +- .../compilers/llvm/3.5/libc++/setup-hook.sh | 16 ++--- .../compilers/llvm/3.7/libc++/default.nix | 5 +- .../compilers/llvm/3.7/libc++/setup-hook.sh | 16 ++--- .../compilers/llvm/3.8/libc++/default.nix | 5 +- .../compilers/llvm/3.8/libc++/setup-hook.sh | 16 ++--- .../compilers/llvm/3.9/libc++/default.nix | 5 +- .../compilers/llvm/3.9/libc++/setup-hook.sh | 16 ++--- .../compilers/llvm/4/libc++/default.nix | 5 +- .../compilers/llvm/4/libc++/setup-hook.sh | 16 ++--- .../compilers/llvm/5/libc++/default.nix | 5 +- .../compilers/llvm/5/libc++/setup-hook.sh | 16 ++--- .../compilers/llvm/6/libc++/default.nix | 5 +- .../compilers/llvm/6/libc++/setup-hook.sh | 16 ++--- pkgs/development/libraries/gettext/default.nix | 5 +- .../libraries/gettext/gettext-setup-hook.sh | 23 ++----- pkgs/development/libraries/libiconv/default.nix | 5 +- pkgs/development/libraries/libiconv/setup-hook.sh | 18 +----- pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh | 22 ++----- pkgs/os-specific/bsd/netbsd/default.nix | 10 ++- pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh | 18 +----- pkgs/os-specific/linux/musl/fts-setup-hook.sh | 19 +----- pkgs/os-specific/linux/musl/fts.nix | 5 +- 29 files changed, 203 insertions(+), 261 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/role.bash (limited to 'pkgs/build-support/bintools-wrapper') diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 47301bbdde69..c0aea2d11312 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -190,7 +190,12 @@ stdenv.mkDerivation { depsTargetTargetPropagated = extraPackages; - setupHook = ./setup-hook.sh; + wrapperName = "BINTOOLS_WRAPPER"; + + setupHooks = [ + ../setup-hooks/role.bash + ./setup-hook.sh + ]; postFixup = '' diff --git a/pkgs/build-support/bintools-wrapper/setup-hook.sh b/pkgs/build-support/bintools-wrapper/setup-hook.sh index 48a00b0b9b07..dbe0a0572a48 100644 --- a/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -11,44 +11,22 @@ set -u [[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0 bintoolsWrapper_addLDVars () { - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "bintools-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac + # See ../setup-hooks/role.bash + local role_post role_pre + getTargetRoleEnvHook if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then - export NIX_${role}LDFLAGS+=" -L$1/lib64" + export NIX_${role_pre}LDFLAGS+=" -L$1/lib64" fi if [[ -d "$1/lib" ]]; then - export NIX_${role}LDFLAGS+=" -L$1/lib" + export NIX_${role_pre}LDFLAGS+=" -L$1/lib" fi } -case $targetOffset in - -1) - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD=1 - role_pre='BUILD_' - role_post='_FOR_BUILD' - ;; - 0) - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST=1 - role_pre='' - role_post='' - ;; - 1) - export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET=1 - role_pre='TARGET_' - role_post='_FOR_TARGET' - ;; - *) - echo "cc-wrapper: used as improper sort of dependency" >2; - return 1 - ;; -esac +# See ../setup-hooks/role.bash +getTargetRole +getTargetRoleWrapper addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 43cd87fb4597..0ea9dd0cb9f4 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -191,7 +191,12 @@ stdenv.mkDerivation { propagatedBuildInputs = [ bintools ]; depsTargetTargetPropagated = extraPackages; - setupHook = ./setup-hook.sh; + wrapperName = "CC_WRAPPER"; + + setupHooks = [ + ../setup-hooks/role.bash + ./setup-hook.sh + ]; postFixup = '' diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 29a7306b9b7e..17d34c1e1f1b 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -66,55 +66,22 @@ set -u # over no state, and there's no @-substitutions within, so any redefined # function is guaranteed to be exactly the same. ccWrapper_addCVars () { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac + # See ../setup-hooks/role.bash + local role_post role_pre + getTargetRoleEnvHook if [[ -d "$1/include" ]]; then - export NIX_${role}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" + export NIX_${role_pre}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" fi if [[ -d "$1/Library/Frameworks" ]]; then - export NIX_${role}CFLAGS_COMPILE+=" -F$1/Library/Frameworks" + export NIX_${role_pre}CFLAGS_COMPILE+=" -F$1/Library/Frameworks" fi } -# Since the same cc-wrapper derivation can be depend on in multiple ways, we -# need to accumulate *each* role (i.e. target platform relative the depending -# derivation) in which the cc-wrapper derivation is used. -# `NIX_CC_WRAPPER_@infixSalt@_TARGET_*` tracks this (needs to be an exported env -# var so can't use fancier data structures). -# -# We also need to worry about what role is being added on *this* invocation of -# setup-hook, which `role` tracks. -case $targetOffset in - -1) - export NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD=1 - role_pre='BUILD_' - role_post='_FOR_BUILD' - ;; - 0) - export NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST=1 - role_pre='' - role_post='' - ;; - 1) - export NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET=1 - role_pre='TARGET_' - role_post='_FOR_TARGET' - ;; - *) - echo "cc-wrapper: used as improper sort of dependency" >2; - return 1 - ;; -esac +# See ../setup-hooks/role.bash +getTargetRole +getTargetRoleWrapper # We use the `targetOffset` to choose the right env hook to accumulate the right # sort of deps (those with that offset). diff --git a/pkgs/build-support/setup-hooks/role.bash b/pkgs/build-support/setup-hooks/role.bash new file mode 100644 index 000000000000..6f1c36f5c050 --- /dev/null +++ b/pkgs/build-support/setup-hooks/role.bash @@ -0,0 +1,75 @@ +# Since the same derivation can be depend on in multiple ways, we need to +# accumulate *each* role (i.e. host and target platforms relative the depending +# derivation) in which the derivation is used. +# +# The role is intened to be use as part of other variables names like +# - $NIX_${role_pre}_SOMETHING +# - $NIX_SOMETHING_${role_post} + +function getRole() { + case $1 in + -1) + role_pre='BUILD_' + role_post='_FOR_BUILD' + ;; + 0) + role_pre='' + role_post='' + ;; + 1) + role_pre='TARGET_' + role_post='_FOR_TARGET' + ;; + *) + echo "@name@: used as improper sort of dependency" >2 + return 1 + ;; + esac +} + +# `hostOffset` describes how the host platform of the package is slid relative +# to the depending package. `targetOffset` likewise describes the target +# platform of the package. Both are brought into scope of the setup hook defined +# for dependency whose setup hook is being processed relative to the package +# being built. + +function getHostRole() { + getRole "$hostOffset" +} +function getTargetRole() { + getRole "$targetOffset" +} + +# `depHostOffset` describes how the host platform of the dependencies are slid +# relative to the depending package. `depTargetOffset` likewise describes the +# target platform of dependenices. Both are brought into scope of the +# environment hook defined for the dependency being applied relative to the +# package being built. + +function getHostRoleEnvHook() { + getRole "$depHostOffset" +} +function getTargetRoleEnvHook() { + getRole "$depTargetOffset" +} + +# This variant is inteneded specifically for code-prodocing tool wrapper scripts +# `NIX_@wrapperName@_@infixSalt@_TARGET_*` tracks this (needs to be an exported +# env var so can't use fancier data structures). +function getTargetRoleWrapper() { + case $targetOffset in + -1) + export NIX_@wrapperName@_@infixSalt@_TARGET_BUILD=1 + ;; + 0) + export NIX_@wrapperName@_@infixSalt@_TARGET_HOST=1 + ;; + 1) + export NIX_@wrapperName@_@infixSalt@_TARGET_TARGET=1 + ;; + *) + echo "@name@: used as improper sort of dependency" >2 + return 1 + ;; + esac +} diff --git a/pkgs/development/compilers/gcc/libstdc++-hook.sh b/pkgs/development/compilers/gcc/libstdc++-hook.sh index 2325eeb9e2cf..8b1d5d2da678 100644 --- a/pkgs/development/compilers/gcc/libstdc++-hook.sh +++ b/pkgs/development/compilers/gcc/libstdc++-hook.sh @@ -1,13 +1,5 @@ -# The `hostOffset` describes how the host platform of the dependencies are slid -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem $(echo -n @gcc@/include/c++/*) -isystem $(echo -n @gcc@/include/c++/*)/$(@gcc@/bin/gcc -dumpmachine)" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libstdc++" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem $(echo -n @gcc@/include/c++/*) -isystem $(echo -n @gcc@/include/c++/*)/$(@gcc@/bin/gcc -dumpmachine)" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libstdc++" diff --git a/pkgs/development/compilers/llvm/3.5/libc++/default.nix b/pkgs/development/compilers/llvm/3.5/libc++/default.nix index 1f1129f578f4..6edd5e9798c7 100644 --- a/pkgs/development/compilers/llvm/3.5/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.5/libc++/default.nix @@ -39,7 +39,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh index e18733b5ea3a..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.5/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies are slid -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/3.7/libc++/default.nix b/pkgs/development/compilers/llvm/3.7/libc++/default.nix index 4296c0fd192c..462e35a483f4 100644 --- a/pkgs/development/compilers/llvm/3.7/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.7/libc++/default.nix @@ -33,7 +33,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh index e18733b5ea3a..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.7/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies are slid -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/3.8/libc++/default.nix b/pkgs/development/compilers/llvm/3.8/libc++/default.nix index ea468b3772e0..cc3f5545146c 100644 --- a/pkgs/development/compilers/llvm/3.8/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.8/libc++/default.nix @@ -31,7 +31,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh index bcd93cf486ff..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.8/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/3.9/libc++/default.nix b/pkgs/development/compilers/llvm/3.9/libc++/default.nix index ad514b0daa54..7e5c30bdfd35 100644 --- a/pkgs/development/compilers/llvm/3.9/libc++/default.nix +++ b/pkgs/development/compilers/llvm/3.9/libc++/default.nix @@ -31,7 +31,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh index bcd93cf486ff..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/3.9/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/4/libc++/default.nix b/pkgs/development/compilers/llvm/4/libc++/default.nix index f28957c35185..718abc420a97 100644 --- a/pkgs/development/compilers/llvm/4/libc++/default.nix +++ b/pkgs/development/compilers/llvm/4/libc++/default.nix @@ -44,7 +44,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh index bcd93cf486ff..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/4/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/5/libc++/default.nix b/pkgs/development/compilers/llvm/5/libc++/default.nix index 9ddeea7ef79a..cb6dfe2808eb 100644 --- a/pkgs/development/compilers/llvm/5/libc++/default.nix +++ b/pkgs/development/compilers/llvm/5/libc++/default.nix @@ -40,7 +40,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh index bcd93cf486ff..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/compilers/llvm/6/libc++/default.nix b/pkgs/development/compilers/llvm/6/libc++/default.nix index 3c6c009a58fa..27d8cd18b666 100644 --- a/pkgs/development/compilers/llvm/6/libc++/default.nix +++ b/pkgs/development/compilers/llvm/6/libc++/default.nix @@ -40,7 +40,10 @@ stdenv.mkDerivation rec { linkCxxAbi = stdenv.isLinux; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; meta = { homepage = http://libcxx.llvm.org/; diff --git a/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh index bcd93cf486ff..6611259165ae 100644 --- a/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh +++ b/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh @@ -1,14 +1,6 @@ -# The `hostOffset` describes how the host platform of the dependencies -# relative to the depending package. It is brought into scope of the setup hook -# defined as the role of the dependency whose hooks is being run. -case $hostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $hostOffset-offset deps" >2; - return 1 ;; -esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole linkCxxAbi="@linkCxxAbi@" -export NIX_${role}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" -export NIX_${role}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" +export NIX_${role_pre}CXXSTDLIB_COMPILE+=" -isystem @out@/include/c++/v1" +export NIX_${role_pre}CXXSTDLIB_LINK=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}" diff --git a/pkgs/development/libraries/gettext/default.nix b/pkgs/development/libraries/gettext/default.nix index 6dec7747c7e8..a7c79ee600ec 100644 --- a/pkgs/development/libraries/gettext/default.nix +++ b/pkgs/development/libraries/gettext/default.nix @@ -48,7 +48,10 @@ stdenv.mkDerivation rec { # HACK, see #10874 (and 14664) buildInputs = stdenv.lib.optional (!stdenv.isLinux && !hostPlatform.isCygwin) libiconv; - setupHook = ./gettext-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./gettext-setup-hook.sh + ]; gettextNeedsLdflags = hostPlatform.libc != "glibc" && !hostPlatform.isMusl; enableParallelBuilding = true; diff --git a/pkgs/development/libraries/gettext/gettext-setup-hook.sh b/pkgs/development/libraries/gettext/gettext-setup-hook.sh index 074d313e48aa..0a6bc0dd253a 100644 --- a/pkgs/development/libraries/gettext/gettext-setup-hook.sh +++ b/pkgs/development/libraries/gettext/gettext-setup-hook.sh @@ -1,6 +1,8 @@ gettextDataDirsHook() { + # See pkgs/build-support/setup-hooks/role.bash + getHostRoleEnvHook if [ -d "$1/share/gettext" ]; then - addToSearchPath GETTEXTDATADIRS "$1/share/gettext" + addToSearchPath "GETTEXTDATADIRS${role_post}" "$1/share/gettext" fi } @@ -8,21 +10,8 @@ addEnvHooks "$hostOffset" gettextDataDirsHook # libintl must be listed in load flags on non-Glibc # it doesn't hurt to have it in Glibc either though -gettextLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac - - export NIX_${role}LDFLAGS+=" -lintl" -} - if [ ! -z "@gettextNeedsLdflags@" ]; then - addEnvHooks "$hostOffset" gettextLdflags + # See pkgs/build-support/setup-hooks/role.bash + getHostRole + export NIX_${role_pre}LDFLAGS+=" -lintl" fi diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index a4e6fed88e1c..169a4d38bb53 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -14,7 +14,10 @@ stdenv.mkDerivation rec { sha256 = "0y1ij745r4p48mxq84rax40p10ln7fc7m243p8k8sia519i3dxfc"; }; - setupHook = ./setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./setup-hook.sh + ]; postPatch = lib.optionalString ((hostPlatform != buildPlatform && hostPlatform.libc == "msvcrt") || stdenv.cc.nativeLibc) diff --git a/pkgs/development/libraries/libiconv/setup-hook.sh b/pkgs/development/libraries/libiconv/setup-hook.sh index 78222dddbf1d..d20e94513e26 100644 --- a/pkgs/development/libraries/libiconv/setup-hook.sh +++ b/pkgs/development/libraries/libiconv/setup-hook.sh @@ -1,18 +1,6 @@ # libiconv must be listed in load flags on non-Glibc # it doesn't hurt to have it in Glibc either though -iconvLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac - export NIX_${role}LDFLAGS+=" -liconv" -} - -addEnvHooks "$hostOffset" iconvLdflags +# See pkgs/build-support/setup-hooks/role.bash +getHostRole +export NIX_${role_pre}LDFLAGS+=" -liconv" diff --git a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh index d47d602e2edb..81df09eba176 100644 --- a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh +++ b/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh @@ -1,18 +1,6 @@ -setupCompatFlags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole - export NIX_${role}LDFLAGS+=" -lnbcompat" - export NIX_${role}CFLAGS_COMPILE+=" -DHAVE_NBTOOL_CONFIG_H" - export NIX_${role}CFLAGS_COMPILE+=" -include nbtool_config.h" -} - -addEnvHooks "$hostOffset" setupCompatFlags +export NIX_${role_pre}LDFLAGS+=" -lnbcompat" +export NIX_${role_pre}CFLAGS_COMPILE+=" -DHAVE_NBTOOL_CONFIG_H" +export NIX_${role_pre}CFLAGS_COMPILE+=" -include nbtool_config.h" diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index b4fb99504ef2..84d6926c50c7 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -167,7 +167,10 @@ let sha256 = "17phkfafybxwhzng44k5bhmag6i55br53ky1nwcmw583kg2fa86z"; version = "7.1.2"; - setupHook = ./compat-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./compat-setup-hook.sh + ]; # override defaults to prevent infinite recursion nativeBuildInputs = [ makeMinimal ]; @@ -270,7 +273,10 @@ let runHook postInstall ''; - setupHook = ./fts-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./fts-setup-hook.sh + ]; }; stat = netBSDDerivation { diff --git a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh index 6b7064174931..5cf8c753aec3 100644 --- a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh +++ b/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh @@ -1,16 +1,4 @@ -ftsLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac +# See pkgs/build-support/setup-hooks/role.bash +getHostRole - export NIX_${role}LDFLAGS+=" -lfts" -} - -addEnvHooks "$hostOffset" ftsLdflags +export NIX_${role_pre}LDFLAGS+=" -lfts" diff --git a/pkgs/os-specific/linux/musl/fts-setup-hook.sh b/pkgs/os-specific/linux/musl/fts-setup-hook.sh index 3962dcb19a20..5cf8c753aec3 100644 --- a/pkgs/os-specific/linux/musl/fts-setup-hook.sh +++ b/pkgs/os-specific/linux/musl/fts-setup-hook.sh @@ -1,17 +1,4 @@ -ftsLdflags() { - # The `depHostOffset` describes how the host platform of the dependencies - # are slid relative to the depending package. It is brought into scope of - # the environment hook defined as the role of the dependency being applied. - case $depHostOffset in - -1) local role='BUILD_' ;; - 0) local role='' ;; - 1) local role='TARGET_' ;; - *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2; - return 1 ;; - esac - - export NIX_${role}LDFLAGS+=" -lfts" -} - -addEnvHooks "$hostOffset" ftsLdflags +# See pkgs/build-support/setup-hooks/role.bash +getHostRole +export NIX_${role_pre}LDFLAGS+=" -lfts" diff --git a/pkgs/os-specific/linux/musl/fts.nix b/pkgs/os-specific/linux/musl/fts.nix index 0f16e8cc79bf..24d25de3a2d9 100644 --- a/pkgs/os-specific/linux/musl/fts.nix +++ b/pkgs/os-specific/linux/musl/fts.nix @@ -12,5 +12,8 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ autoreconfHook pkgconfig ]; - setupHook = ./fts-setup-hook.sh; + setupHooks = [ + ../../../build-support/setup-hooks/role.bash + ./fts-setup-hook.sh + ]; } -- cgit 1.4.1 From 8b0fce8cb1013837cd2108193653a1763cd68266 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 7 May 2018 13:15:34 -0400 Subject: {bintools,cc}-wrapper: Factor out role accumulation logic --- pkgs/build-support/bintools-wrapper/add-flags.sh | 11 +-- pkgs/build-support/bintools-wrapper/default.nix | 4 +- pkgs/build-support/bintools-wrapper/ld-wrapper.sh | 2 +- pkgs/build-support/cc-wrapper/add-flags.sh | 13 +--- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 2 +- pkgs/build-support/cc-wrapper/default.nix | 4 +- pkgs/build-support/cc-wrapper/utils.sh | 80 ------------------- pkgs/build-support/wrapper-common/utils.bash | 95 +++++++++++++++++++++++ 8 files changed, 103 insertions(+), 108 deletions(-) delete mode 100644 pkgs/build-support/cc-wrapper/utils.sh create mode 100644 pkgs/build-support/wrapper-common/utils.bash (limited to 'pkgs/build-support/bintools-wrapper') diff --git a/pkgs/build-support/bintools-wrapper/add-flags.sh b/pkgs/build-support/bintools-wrapper/add-flags.sh index 7d118d20fc68..d02a25fe697b 100644 --- a/pkgs/build-support/bintools-wrapper/add-flags.sh +++ b/pkgs/build-support/bintools-wrapper/add-flags.sh @@ -11,16 +11,7 @@ var_templates_bool=( NIX+DONT_SET_RPATH ) -declare -a role_infixes=() -if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then - role_infixes+=(_BUILD_) -fi -if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then - role_infixes+=(_) -fi -if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then - role_infixes+=(_TARGET_) -fi +accumulateRoles for var in "${var_templates_list[@]}"; do mangleVarList "$var" "${role_infixes[@]}" diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index c0aea2d11312..bfcd3292729b 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -294,7 +294,7 @@ stdenv.mkDerivation { set +u substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh - substituteAll ${../cc-wrapper/utils.sh} $out/nix-support/utils.sh + substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash ## ## Extra custom steps @@ -305,7 +305,7 @@ stdenv.mkDerivation { inherit dynamicLinker expand-response-params; - # for substitution in utils.sh + # for substitution in utils.bash expandResponseParams = "${expand-response-params}/bin/expand-response-params"; meta = diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index 991ed0fe263c..2ad1fdcadc27 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -14,7 +14,7 @@ if [ -n "@coreutils_bin@" ]; then PATH="@coreutils_bin@/bin" fi -source @out@/nix-support/utils.sh +source @out@/nix-support/utils.bash if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then source @out@/nix-support/add-flags.sh diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh index 604aaf6b6cf0..ee4cc1ec06d4 100644 --- a/pkgs/build-support/cc-wrapper/add-flags.sh +++ b/pkgs/build-support/cc-wrapper/add-flags.sh @@ -14,18 +14,7 @@ var_templates_bool=( NIX+ENFORCE_NO_NATIVE ) -# Accumulate infixes for taking in the right input parameters. See setup-hook -# for details. -declare -a role_infixes=() -if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then - role_infixes+=(_BUILD_) -fi -if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then - role_infixes+=(_) -fi -if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then - role_infixes+=(_TARGET_) -fi +accumulateRoles # We need to mangle names for hygiene, but also take parameters/overrides # from the environment. diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index c2e6c1406358..b2bacec5e9b5 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -15,7 +15,7 @@ if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin" fi -source @out@/nix-support/utils.sh +source @out@/nix-support/utils.bash # Flirting with a layer violation here. if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 0ea9dd0cb9f4..1b1c82b9294f 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -282,7 +282,7 @@ stdenv.mkDerivation { + '' substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh - substituteAll ${./utils.sh} $out/nix-support/utils.sh + substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash ## ## Extra custom steps @@ -293,7 +293,7 @@ stdenv.mkDerivation { inherit expand-response-params; - # for substitution in utils.sh + # for substitution in utils.bash expandResponseParams = "${expand-response-params}/bin/expand-response-params"; meta = diff --git a/pkgs/build-support/cc-wrapper/utils.sh b/pkgs/build-support/cc-wrapper/utils.sh deleted file mode 100644 index 9215fe2dc397..000000000000 --- a/pkgs/build-support/cc-wrapper/utils.sh +++ /dev/null @@ -1,80 +0,0 @@ -mangleVarList() { - local var="$1" - shift - local -a role_infixes=("$@") - - local outputVar="${var/+/_@infixSalt@_}" - declare -gx ${outputVar}+='' - # For each role we serve, we accumulate the input parameters into our own - # cc-wrapper-derivation-specific environment variables. - for infix in "${role_infixes[@]}"; do - local inputVar="${var/+/${infix}}" - if [ -v "$inputVar" ]; then - export ${outputVar}+="${!outputVar:+ }${!inputVar}" - fi - done -} - -mangleVarBool() { - local var="$1" - shift - local -a role_infixes=("$@") - - local outputVar="${var/+/_@infixSalt@_}" - declare -gxi ${outputVar}+=0 - for infix in "${role_infixes[@]}"; do - local inputVar="${var/+/${infix}}" - if [ -v "$inputVar" ]; then - # "1" in the end makes `let` return success error code when - # expression itself evaluates to zero. - # We don't use `|| true` because that would silence actual - # syntax errors from bad variable values. - let "${outputVar} |= ${!inputVar:-0}" "1" - fi - done -} - -skip () { - if (( "${NIX_DEBUG:-0}" >= 1 )); then - echo "skipping impure path $1" >&2 - fi -} - - -# Checks whether a path is impure. E.g., `/lib/foo.so' is impure, but -# `/nix/store/.../lib/foo.so' isn't. -badPath() { - local p=$1 - - # Relative paths are okay (since they're presumably relative to - # the temporary build directory). - if [ "${p:0:1}" != / ]; then return 1; fi - - # Otherwise, the path should refer to the store or some temporary - # directory (including the build directory). - test \ - "$p" != "/dev/null" -a \ - "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \ - "${p:0:4}" != "/tmp" -a \ - "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP" -} - -expandResponseParams() { - declare -ga params=("$@") - local arg - for arg in "$@"; do - if [[ "$arg" == @* ]]; then - # phase separation makes this look useless - # shellcheck disable=SC2157 - if [ -x "@expandResponseParams@" ]; then - # params is used by caller - #shellcheck disable=SC2034 - readarray -d '' params < <("@expandResponseParams@" "$@") - return 0 - else - echo "Response files aren't supported during bootstrapping" >&2 - return 1 - fi - fi - done -} diff --git a/pkgs/build-support/wrapper-common/utils.bash b/pkgs/build-support/wrapper-common/utils.bash new file mode 100644 index 000000000000..12b596a83e6f --- /dev/null +++ b/pkgs/build-support/wrapper-common/utils.bash @@ -0,0 +1,95 @@ +# Accumulate infixes for taking in the right input parameters with the `mangle*` +# functions below. See setup-hook for details. +accumulateRoles() { + declare -ga role_infixes=() + if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_BUILD:-}" ]; then + role_infixes+=(_BUILD_) + fi + if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_HOST:-}" ]; then + role_infixes+=(_) + fi + if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_TARGET:-}" ]; then + role_infixes+=(_TARGET_) + fi +} + +mangleVarList() { + local var="$1" + shift + local -a role_infixes=("$@") + + local outputVar="${var/+/_@infixSalt@_}" + declare -gx ${outputVar}+='' + # For each role we serve, we accumulate the input parameters into our own + # cc-wrapper-derivation-specific environment variables. + for infix in "${role_infixes[@]}"; do + local inputVar="${var/+/${infix}}" + if [ -v "$inputVar" ]; then + export ${outputVar}+="${!outputVar:+ }${!inputVar}" + fi + done +} + +mangleVarBool() { + local var="$1" + shift + local -a role_infixes=("$@") + + local outputVar="${var/+/_@infixSalt@_}" + declare -gxi ${outputVar}+=0 + for infix in "${role_infixes[@]}"; do + local inputVar="${var/+/${infix}}" + if [ -v "$inputVar" ]; then + # "1" in the end makes `let` return success error code when + # expression itself evaluates to zero. + # We don't use `|| true` because that would silence actual + # syntax errors from bad variable values. + let "${outputVar} |= ${!inputVar:-0}" "1" + fi + done +} + +skip () { + if (( "${NIX_DEBUG:-0}" >= 1 )); then + echo "skipping impure path $1" >&2 + fi +} + + +# Checks whether a path is impure. E.g., `/lib/foo.so' is impure, but +# `/nix/store/.../lib/foo.so' isn't. +badPath() { + local p=$1 + + # Relative paths are okay (since they're presumably relative to + # the temporary build directory). + if [ "${p:0:1}" != / ]; then return 1; fi + + # Otherwise, the path should refer to the store or some temporary + # directory (including the build directory). + test \ + "$p" != "/dev/null" -a \ + "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \ + "${p:0:4}" != "/tmp" -a \ + "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP" +} + +expandResponseParams() { + declare -ga params=("$@") + local arg + for arg in "$@"; do + if [[ "$arg" == @* ]]; then + # phase separation makes this look useless + # shellcheck disable=SC2157 + if [ -x "@expandResponseParams@" ]; then + # params is used by caller + #shellcheck disable=SC2034 + readarray -d '' params < <("@expandResponseParams@" "$@") + return 0 + else + echo "Response files aren't supported during bootstrapping" >&2 + return 1 + fi + fi + done +} -- cgit 1.4.1 From 330ca731e88ec015181c43d92ae8f7c77cf0226a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 13 May 2018 11:31:24 -0400 Subject: treewide: Get rid of all uses of crossConfig The hack of using `crossConfig` to enforce stricter handling of dependencies is replaced with a dedicated `strictDeps` for that purpose. (Experience has shown that my punning was a terrible idea that made more difficult and embarrising to teach teach.) Now that is is clear, a few packages now use `strictDeps`, to fix various bugs: - bintools-wrapper and cc-wrapper --- pkgs/build-support/bintools-wrapper/default.nix | 1 + pkgs/build-support/bintools-wrapper/setup-hook.sh | 2 +- pkgs/build-support/cc-wrapper/default.nix | 1 + pkgs/build-support/cc-wrapper/setup-hook.sh | 2 +- pkgs/development/compilers/ghc/7.10.3.nix | 6 ++--- pkgs/development/compilers/ghc/8.0.2.nix | 6 ++--- pkgs/development/compilers/ghc/8.2.2.nix | 6 ++--- pkgs/development/compilers/ghc/8.4.1.nix | 6 ++--- pkgs/development/compilers/ghc/head.nix | 6 ++--- pkgs/development/interpreters/guile/1.8.nix | 15 ++++------- pkgs/development/libraries/fontconfig/2.10.nix | 13 ++------- pkgs/development/libraries/fontconfig/default.nix | 13 ++------- pkgs/development/libraries/gettext/default.nix | 28 +++++++++---------- pkgs/development/libraries/glibc/2.27.nix | 13 ++++----- pkgs/development/libraries/glibc/default.nix | 13 ++++----- .../tools/build-managers/cmake/default.nix | 30 ++++++++++++--------- .../tools/build-managers/cmake/setup-hook.sh | 25 ++++++++--------- pkgs/misc/uboot/nanonote.nix | 21 ++++++--------- pkgs/servers/x11/xorg/overrides.nix | 31 +++++++++++++--------- pkgs/stdenv/generic/make-derivation.nix | 5 +++- pkgs/stdenv/generic/setup.sh | 4 +-- pkgs/tools/misc/bc/default.nix | 2 +- 22 files changed, 111 insertions(+), 138 deletions(-) (limited to 'pkgs/build-support/bintools-wrapper') diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index a5084808c3bc..17ec2ec7ad75 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -186,6 +186,7 @@ stdenv.mkDerivation { else throw "unknown emulation for platform: " + targetPlatform.config; in targetPlatform.platform.bfdEmulation or (fmt + sep + arch); + strictDeps = true; depsTargetTargetPropagated = extraPackages; setupHook = ./setup-hook.sh; diff --git a/pkgs/build-support/bintools-wrapper/setup-hook.sh b/pkgs/build-support/bintools-wrapper/setup-hook.sh index 48a00b0b9b07..a093ef8f3b45 100644 --- a/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -8,7 +8,7 @@ set -u # native compile. # # TODO(@Ericson2314): No native exception -[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0 +[[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0 bintoolsWrapper_addLDVars () { case $depHostOffset in diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 8de2366ff5f5..7cd02c4b24c6 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -201,6 +201,7 @@ stdenv.mkDerivation { ln -s $ccPath/${targetPrefix}ghdl $out/bin/${targetPrefix}ghdl ''; + strictDeps = true; propagatedBuildInputs = [ bintools ]; depsTargetTargetPropagated = extraPackages; diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 29a7306b9b7e..6e6354860780 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -60,7 +60,7 @@ set -u # native compile. # # TODO(@Ericson2314): No native exception -[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0 +[[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0 # It's fine that any other cc-wrapper will redefine this. Bash functions close # over no state, and there's no @-substitutions within, so any redefined diff --git a/pkgs/development/compilers/ghc/7.10.3.nix b/pkgs/development/compilers/ghc/7.10.3.nix index e4bf23c6e9e2..4c227f561155 100644 --- a/pkgs/development/compilers/ghc/7.10.3.nix +++ b/pkgs/development/compilers/ghc/7.10.3.nix @@ -129,10 +129,8 @@ stdenv.mkDerivation rec { "--disable-large-address-space" ]; - # Hack to make sure we never to the relaxation `$PATH` and hooks support for - # compatability. This will be replaced with something clearer in a future - # masss-rebuild. - crossConfig = true; + # Make sure we never relax`$PATH` and hooks support for compatability. + strictDeps = true; nativeBuildInputs = [ ghc perl libxml2 libxslt docbook_xsl docbook_xml_dtd_45 docbook_xml_dtd_42 hscolour diff --git a/pkgs/development/compilers/ghc/8.0.2.nix b/pkgs/development/compilers/ghc/8.0.2.nix index 7d11ffb66c60..ca3b128df15b 100644 --- a/pkgs/development/compilers/ghc/8.0.2.nix +++ b/pkgs/development/compilers/ghc/8.0.2.nix @@ -128,10 +128,8 @@ stdenv.mkDerivation rec { "--disable-large-address-space" ]; - # Hack to make sure we never to the relaxation `$PATH` and hooks support for - # compatability. This will be replaced with something clearer in a future - # masss-rebuild. - crossConfig = true; + # Make sure we never relax`$PATH` and hooks support for compatability. + strictDeps = true; nativeBuildInputs = [ ghc perl hscolour sphinx ]; diff --git a/pkgs/development/compilers/ghc/8.2.2.nix b/pkgs/development/compilers/ghc/8.2.2.nix index b2a1aafe6131..c8b8451ea600 100644 --- a/pkgs/development/compilers/ghc/8.2.2.nix +++ b/pkgs/development/compilers/ghc/8.2.2.nix @@ -145,10 +145,8 @@ stdenv.mkDerivation rec { "--disable-large-address-space" ]; - # Hack to make sure we never to the relaxation `$PATH` and hooks support for - # compatability. This will be replaced with something clearer in a future - # masss-rebuild. - crossConfig = true; + # Make sure we never relax`$PATH` and hooks support for compatability. + strictDeps = true; nativeBuildInputs = [ alex autoconf autoreconfHook automake ghc happy hscolour perl python3 sphinx ]; diff --git a/pkgs/development/compilers/ghc/8.4.1.nix b/pkgs/development/compilers/ghc/8.4.1.nix index f232e0b47287..14c94887d62a 100644 --- a/pkgs/development/compilers/ghc/8.4.1.nix +++ b/pkgs/development/compilers/ghc/8.4.1.nix @@ -144,10 +144,8 @@ stdenv.mkDerivation rec { "--disable-large-address-space" ]; - # Hack to make sure we never to the relaxation `$PATH` and hooks support for - # compatability. This will be replaced with something clearer in a future - # masss-rebuild. - crossConfig = true; + # Make sure we never relax`$PATH` and hooks support for compatability. + strictDeps = true; nativeBuildInputs = [ ghc perl autoconf automake happy alex python3 ]; diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 51497e0d9cee..da38230d4854 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -134,10 +134,8 @@ stdenv.mkDerivation rec { "--disable-large-address-space" ]; - # Hack to make sure we never to the relaxation `$PATH` and hooks support for - # compatability. This will be replaced with something clearer in a future - # masss-rebuild. - crossConfig = true; + # Make sure we never relax`$PATH` and hooks support for compatability. + strictDeps = true; nativeBuildInputs = [ ghc perl autoconf automake happy alex python3 ]; diff --git a/pkgs/development/interpreters/guile/1.8.nix b/pkgs/development/interpreters/guile/1.8.nix index cf42c9a7b683..658b2cce77f9 100644 --- a/pkgs/development/interpreters/guile/1.8.nix +++ b/pkgs/development/interpreters/guile/1.8.nix @@ -16,7 +16,11 @@ stdenv.mkDerivation rec { setOutputFlags = false; # $dev gets into the library otherwise # GCC 4.6 raises a number of set-but-unused warnings. - configureFlags = [ "--disable-error-on-warning" ]; + configureFlags = [ "--disable-error-on-warning" ] + # Guile needs patching to preset results for the configure tests about + # pthreads, which work only in native builds. + ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) + "--with-threads=no"; depsBuildBuild = [ buildPackages.stdenv.cc ] ++ stdenv.lib.optional (hostPlatform != buildPlatform) @@ -34,17 +38,8 @@ stdenv.mkDerivation rec { libtool ]; - patches = [ ./cpp-4.5.patch ]; - # Guile needs patching to preset results for the configure tests - # about pthreads, which work only in native builds. - preConfigure = '' - if test -n "$crossConfig"; then - configureFlags="--with-threads=no $configureFlags" - fi - ''; - preBuild = '' sed -e '/lt_dlinit/a lt_dladdsearchdir("'$out/lib'");' -i libguile/dynl.c ''; diff --git a/pkgs/development/libraries/fontconfig/2.10.nix b/pkgs/development/libraries/fontconfig/2.10.nix index 5fb0ea4429e7..b02d9ccdcef8 100644 --- a/pkgs/development/libraries/fontconfig/2.10.nix +++ b/pkgs/development/libraries/fontconfig/2.10.nix @@ -21,19 +21,10 @@ stdenv.mkDerivation rec { "--with-cache-dir=/var/cache/fontconfig" "--disable-docs" "--with-default-fonts=" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "--with-arch=${hostPlatform.parsed.cpu.name}" ]; - # We should find a better way to access the arch reliably. - crossArch = if stdenv.hostPlatform != stdenv.buildPlatform - then hostPlatform.parsed.cpu.name - else null; - - preConfigure = '' - if test -n "$crossConfig"; then - configureFlags="$configureFlags --with-arch=$crossArch"; - fi - ''; - enableParallelBuilding = true; doCheck = true; diff --git a/pkgs/development/libraries/fontconfig/default.nix b/pkgs/development/libraries/fontconfig/default.nix index ce41f1ac7ebc..dafd4834a94b 100644 --- a/pkgs/development/libraries/fontconfig/default.nix +++ b/pkgs/development/libraries/fontconfig/default.nix @@ -53,19 +53,10 @@ stdenv.mkDerivation rec { "--disable-docs" # just <1MB; this is what you get when loading config fails for some reason "--with-default-fonts=${dejavu_fonts.minimal}" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "--with-arch=${hostPlatform.parsed.cpu.name}" ]; - # We should find a better way to access the arch reliably. - crossArch = if stdenv.hostPlatform != stdenv.buildPlatform - then hostPlatform.parsed.cpu.name - else null; - - preConfigure = '' - if test -n "$crossConfig"; then - configureFlags="$configureFlags --with-arch=$crossArch"; - fi - ''; - enableParallelBuilding = true; doCheck = true; diff --git a/pkgs/development/libraries/gettext/default.nix b/pkgs/development/libraries/gettext/default.nix index 9c3024ce25fb..b6855a7e26d4 100644 --- a/pkgs/development/libraries/gettext/default.nix +++ b/pkgs/development/libraries/gettext/default.nix @@ -16,12 +16,19 @@ stdenv.mkDerivation rec { LDFLAGS = if stdenv.isSunOS then "-lm -lmd -lmp -luutil -lnvpair -lnsl -lidmap -lavl -lsec" else ""; - configureFlags = [ "--disable-csharp" "--with-xz" ] + configureFlags = [ + "--disable-csharp" "--with-xz" # avoid retaining reference to CF during stdenv bootstrap - ++ lib.optionals stdenv.isDarwin [ - "gt_cv_func_CFPreferencesCopyAppValue=no" - "gt_cv_func_CFLocaleCopyCurrent=no" - ]; + ] ++ lib.optionals stdenv.isDarwin [ + "gt_cv_func_CFPreferencesCopyAppValue=no" + "gt_cv_func_CFLocaleCopyCurrent=no" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + # On cross building, gettext supposes that the wchar.h from libc + # does not fulfill gettext needs, so it tries to work with its + # own wchar.h file, which does not cope well with the system's + # wchar.h and stddef.h (gcc-4.3 - glibc-2.9) + "gl_cv_func_wcwidth_works=yes" + ]; postPatch = '' substituteAllInPlace gettext-runtime/src/gettext.sh.in @@ -33,17 +40,6 @@ stdenv.mkDerivation rec { sed -i -e "s/\(libgettextsrc_la_LDFLAGS = \)/\\1..\/gnulib-lib\/libxml_rpl.la /" gettext-tools/src/Makefile.in ''; - # On cross building, gettext supposes that the wchar.h from libc - # does not fulfill gettext needs, so it tries to work with its - # own wchar.h file, which does not cope well with the system's - # wchar.h and stddef.h (gcc-4.3 - glibc-2.9) - preConfigure = '' - if test -n "$crossConfig"; then - echo gl_cv_func_wcwidth_works=yes > cachefile - configureFlags="$configureFlags --cache-file=`pwd`/cachefile" - fi - ''; - nativeBuildInputs = [ xz xz.bin ]; # HACK, see #10874 (and 14664) buildInputs = stdenv.lib.optional (!stdenv.isLinux && !hostPlatform.isCygwin) libiconv; diff --git a/pkgs/development/libraries/glibc/2.27.nix b/pkgs/development/libraries/glibc/2.27.nix index bb057ae899e7..bf63b97635a0 100644 --- a/pkgs/development/libraries/glibc/2.27.nix +++ b/pkgs/development/libraries/glibc/2.27.nix @@ -71,14 +71,15 @@ callPackage ./common-2.27.nix { inherit stdenv; } { # Get rid of more unnecessary stuff. rm -rf $out/var $bin/bin/sln - + '' # For some reason these aren't stripped otherwise and retain reference # to bootstrap-tools; on cross-arm this stripping would break objects. - if [ -z "$crossConfig" ]; then - for i in "$out"/lib/*.a; do - [ "$i" = "$out/lib/libm.a" ] || strip -S "$i" - done - fi + + stdenv.lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' + + for i in "$out"/lib/*.a; do + [ "$i" = "$out/lib/libm.a" ] || $STRIP -S "$i" + done + '' + '' # Put libraries for static linking in a separate output. Note # that libc_nonshared.a and libpthread_nonshared.a are required diff --git a/pkgs/development/libraries/glibc/default.nix b/pkgs/development/libraries/glibc/default.nix index 976dbcde47ff..ea443ce9a246 100644 --- a/pkgs/development/libraries/glibc/default.nix +++ b/pkgs/development/libraries/glibc/default.nix @@ -71,14 +71,15 @@ callPackage ./common.nix { inherit stdenv; } { # Get rid of more unnecessary stuff. rm -rf $out/var $bin/bin/sln - + '' # For some reason these aren't stripped otherwise and retain reference # to bootstrap-tools; on cross-arm this stripping would break objects. - if [ -z "$crossConfig" ]; then - for i in "$out"/lib/*.a; do - [ "$i" = "$out/lib/libm.a" ] || strip -S "$i" - done - fi + + stdenv.lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' + + for i in "$out"/lib/*.a; do + [ "$i" = "$out/lib/libm.a" ] || $STRIP -S "$i" + done + '' + '' # Put libraries for static linking in a separate output. Note # that libc_nonshared.a and libpthread_nonshared.a are required diff --git a/pkgs/development/tools/build-managers/cmake/default.nix b/pkgs/development/tools/build-managers/cmake/default.nix index 97c02cd9cc12..b40b284b759e 100644 --- a/pkgs/development/tools/build-managers/cmake/default.nix +++ b/pkgs/development/tools/build-managers/cmake/default.nix @@ -80,19 +80,23 @@ stdenv.mkDerivation rec { configureFlags="--parallel=''${NIX_BUILD_CORES:-1} $configureFlags" ''; - configureFlags = [ "--docdir=share/doc/${name}" ] - ++ (if useSharedLibraries then [ "--no-system-jsoncpp" "--system-libs" ] else [ "--no-system-libs" ]) # FIXME: cleanup - ++ optional (useQt4 || withQt5) "--qt-gui" - ++ ["--"] - ++ optionals (!useNcurses) [ "-DBUILD_CursesDialog=OFF" ] - ++ optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ - "-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++" - "-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc" - "-DCMAKE_AR=${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar" - "-DCMAKE_RANLIB=${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib" - "-DCMAKE_STRIP=${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip" - # TODO: Why are ar and friends not provided by the bintools wrapper? - ]; + configureFlags = [ + "--docdir=share/doc/${name}" + # We should set the proper `CMAKE_SYSTEM_NAME`. + # http://www.cmake.org/Wiki/CMake_Cross_Compiling + # + # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and + # strip. Otherwise they are taken to be relative to the source root of the + # package being built. + "-DCMAKE_CXX_COMPILER=${stdenv.cc.targetPrefix}c++" + "-DCMAKE_C_COMPILER=${stdenv.cc.targetPrefix}cc" + "-DCMAKE_AR=${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar" + "-DCMAKE_RANLIB=${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib" + "-DCMAKE_STRIP=${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip" + ] ++ (if useSharedLibraries then [ "--no-system-jsoncpp" "--system-libs" ] else [ "--no-system-libs" ]) # FIXME: cleanup + ++ optional (useQt4 || withQt5) "--qt-gui" + ++ ["--"] + ++ optionals (!useNcurses) [ "-DBUILD_CursesDialog=OFF" ]; dontUseCmakeConfigure = true; enableParallelBuilding = true; diff --git a/pkgs/development/tools/build-managers/cmake/setup-hook.sh b/pkgs/development/tools/build-managers/cmake/setup-hook.sh index c796c31cb70a..003f900c9541 100755 --- a/pkgs/development/tools/build-managers/cmake/setup-hook.sh +++ b/pkgs/development/tools/build-managers/cmake/setup-hook.sh @@ -29,20 +29,17 @@ cmakeConfigurePhase() { cmakeFlags="-DCMAKE_INSTALL_PREFIX=$prefix $cmakeFlags" fi - if [ -n "$crossConfig" ]; then - # By now it supports linux builds only. We should set the proper - # CMAKE_SYSTEM_NAME otherwise. - # http://www.cmake.org/Wiki/CMake_Cross_Compiling - # - # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and - # strip. Otherwise they are taken to be relative to the source root of - # the package being built. - cmakeFlags="-DCMAKE_CXX_COMPILER=$crossConfig-c++ $cmakeFlags" - cmakeFlags="-DCMAKE_C_COMPILER=$crossConfig-cc $cmakeFlags" - cmakeFlags="-DCMAKE_AR=$(command -v $crossConfig-ar) $cmakeFlags" - cmakeFlags="-DCMAKE_RANLIB=$(command -v $crossConfig-ranlib) $cmakeFlags" - cmakeFlags="-DCMAKE_STRIP=$(command -v $crossConfig-strip) $cmakeFlags" - fi + # We should set the proper `CMAKE_SYSTEM_NAME`. + # http://www.cmake.org/Wiki/CMake_Cross_Compiling + # + # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and + # strip. Otherwise they are taken to be relative to the source root of the + # package being built. + cmakeFlags="-DCMAKE_CXX_COMPILER=$CXX $cmakeFlags" + cmakeFlags="-DCMAKE_C_COMPILER=$CC $cmakeFlags" + cmakeFlags="-DCMAKE_AR=$(command -v $AR) $cmakeFlags" + cmakeFlags="-DCMAKE_RANLIB=$(command -v $RANLAB) $cmakeFlags" + cmakeFlags="-DCMAKE_STRIP=$(command -v $STRIP) $cmakeFlags" # This installs shared libraries with a fully-specified install # name. By default, cmake installs shared libraries with just the diff --git a/pkgs/misc/uboot/nanonote.nix b/pkgs/misc/uboot/nanonote.nix index 2783927ef57c..fb3b98f478e6 100644 --- a/pkgs/misc/uboot/nanonote.nix +++ b/pkgs/misc/uboot/nanonote.nix @@ -1,8 +1,5 @@ {stdenv, fetchurl, fetchgit}: -# We should enable this check once we have the cross target system information -# assert stdenv.system == "armv5tel-linux" || crossConfig == "armv5tel-linux"; - # All this file is made for the Marvell Sheevaplug stdenv.mkDerivation { @@ -30,21 +27,19 @@ stdenv.mkDerivation { sed -i -e 's/0x200000;bootm/0x400000;bootm/' include/configs/qi_lb60.h ''; - # Remove the cross compiler prefix, and add reiserfs support + makeFlags = [ + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" + ]; + + # Add reiserfs support configurePhase = '' make mrproper make qi_lb60_config - sed -i /CROSS_COMPILE/d include/config.mk ''; - buildPhase = '' + preBuild= '' # A variable named 'src' used to affect the build in some uboot... - unset src - if test -z "$crossConfig"; then - make clean all - else - make clean all ARCH=mips CROSS_COMPILE=$crossConfig- - fi + unset -v src ''; dontStrip = true; @@ -59,6 +54,6 @@ stdenv.mkDerivation { ''; meta = { - platforms = [ "mipsel-linux" ]; + platforms = stdenv.lib.platforms.mips; }; } diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index 18189ba2e68d..42831dc40642 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -5,11 +5,9 @@ let inherit (stdenv) lib isDarwin; inherit (lib) overrideDerivation; - setMalloc0ReturnsNullCrossCompiling = '' - if test -n "$crossConfig"; then - configureFlags="$configureFlags --enable-malloc0returnsnull"; - fi - ''; + malloc0ReturnsNullCrossFlag = stdenv.lib.optional + (stdenv.hostPlatform != stdenv.buildPlatform) + "--enable-malloc0returnsnull"; gitRelease = { libName, version, rev, sha256 } : attrs : attrs // { name = libName + "-" + version; @@ -101,7 +99,9 @@ in libX11 = attrs: attrs // { outputs = [ "out" "dev" "man" ]; - preConfigure = setMalloc0ReturnsNullCrossCompiling + '' + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; + preConfigure = '' sed 's,^as_dummy.*,as_dummy="\$PATH",' -i configure ''; postInstall = @@ -138,16 +138,19 @@ in libXxf86vm = attrs: attrs // { outputs = [ "out" "dev" ]; - preConfigure = setMalloc0ReturnsNullCrossCompiling; + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; }; # Propagate some build inputs because of header file dependencies. # Note: most of these are in Requires.private, so maybe builder.sh # should propagate them automatically. libXt = attrs: attrs // { - preConfigure = setMalloc0ReturnsNullCrossCompiling + '' + preConfigure = '' sed 's,^as_dummy.*,as_dummy="\$PATH",' -i configure ''; + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; propagatedBuildInputs = [ xorg.libSM ]; CPP = stdenv.lib.optionalString stdenv.isDarwin "clang -E -"; outputs = [ "out" "dev" "devdoc" ]; @@ -188,7 +191,8 @@ in libXft = attrs: attrs // { outputs = [ "out" "dev" ]; propagatedBuildInputs = [ xorg.libXrender args.freetype args.fontconfig ]; - preConfigure = setMalloc0ReturnsNullCrossCompiling; + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; # the include files need ft2build.h, and Requires.private isn't enough for us postInstall = '' sed "/^Requires:/s/$/, freetype2/" -i "$dev/lib/pkgconfig/xft.pc" @@ -198,7 +202,8 @@ in libXext = attrs: attrs // { outputs = [ "out" "dev" "man" "doc" ]; propagatedBuildInputs = [ xorg.xproto xorg.libXau ]; - preConfigure = setMalloc0ReturnsNullCrossCompiling; + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; }; libXfixes = attrs: attrs // { @@ -221,7 +226,8 @@ in libXrandr = attrs: attrs // { outputs = [ "out" "dev" ]; - preConfigure = setMalloc0ReturnsNullCrossCompiling; + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; propagatedBuildInputs = [xorg.libXrender]; }; @@ -232,8 +238,9 @@ in libXrender = attrs: attrs // { outputs = [ "out" "dev" "doc" ]; + configureFlags = attrs.configureFlags or [] + ++ malloc0ReturnsNullCrossFlag; propagatedBuildInputs = [ xorg.renderproto ]; - preConfigure = setMalloc0ReturnsNullCrossCompiling; }; libXres = attrs: attrs // { diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 46df958b8396..e108e3f156ac 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -52,7 +52,8 @@ rec { # InstallCheck phase , doInstallCheck ? false - , crossConfig ? null + , # TODO(@Ericson2314): Make always true and remove + strictDeps ? stdenv.hostPlatform != stdenv.buildPlatform , meta ? {} , passthru ? {} , pos ? # position used in error messages and for meta.position @@ -156,6 +157,8 @@ rec { userHook = config.stdenv.userHook or null; __ignoreNulls = true; + inherit strictDeps; + depsBuildBuild = lib.elemAt (lib.elemAt dependencies 0) 0; nativeBuildInputs = lib.elemAt (lib.elemAt dependencies 0) 1; depsBuildTarget = lib.elemAt (lib.elemAt dependencies 0) 2; diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index d7a4781448ae..bfab19dd9737 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -501,7 +501,7 @@ activatePackage() { # the transition, we do include everything in thatcase. # # TODO(@Ericson2314): Don't special-case native compilation - if [[ ( -z "${crossConfig-}" || "$hostOffset" -le -1 ) && -d "$pkg/bin" ]]; then + if [[ ( -z "${strictDeps-}" || "$hostOffset" -le -1 ) && -d "$pkg/bin" ]]; then addToSearchPath _PATH "$pkg/bin" fi @@ -551,7 +551,7 @@ _addToEnv() { for depTargetOffset in "${allPlatOffsets[@]}"; do (( "$depHostOffset" <= "$depTargetOffset" )) || continue local hookRef="${hookVar}[$depTargetOffset - $depHostOffset]" - if [[ -z "${crossConfig-}" ]]; then + if [[ -z "${strictDeps-}" ]]; then # Apply environment hooks to all packages during native # compilation to ease the transition. # diff --git a/pkgs/tools/misc/bc/default.nix b/pkgs/tools/misc/bc/default.nix index fc60a000e36e..52bd28e9748d 100644 --- a/pkgs/tools/misc/bc/default.nix +++ b/pkgs/tools/misc/bc/default.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { # Hack to make sure we never to the relaxation `$PATH` and hooks support for # compatability. This will be replaced with something clearer in a future # masss-rebuild. - crossConfig = true; + strictDeps = true; meta = { description = "GNU software calculator"; -- cgit 1.4.1