summary refs log tree commit diff
path: root/pkgs/build-support/cc-wrapper/setup-hook.sh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2018-05-14 23:33:03 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2018-05-14 23:33:03 -0400
commit5e17335bd7ff853379122e08dadfaa2fc1c020b7 (patch)
tree911e75d700bebef1aa60fedcaa6a29b5032d6428 /pkgs/build-support/cc-wrapper/setup-hook.sh
parent330ca731e88ec015181c43d92ae8f7c77cf0226a (diff)
parent0fc21a364bfd6b2dea9010fdf21415ff3de1805a (diff)
downloadnixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.tar
nixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.tar.gz
nixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.tar.bz2
nixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.tar.lz
nixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.tar.xz
nixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.tar.zst
nixpkgs-5e17335bd7ff853379122e08dadfaa2fc1c020b7.zip
Merge remote-tracking branch 'upstream/staging' into strictDeps
Diffstat (limited to 'pkgs/build-support/cc-wrapper/setup-hook.sh')
-rw-r--r--pkgs/build-support/cc-wrapper/setup-hook.sh53
1 files changed, 12 insertions, 41 deletions
diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh
index 6e635486078..9dacacc1f36 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).
@@ -147,6 +114,10 @@ export ${role_pre}CXX=@named_cxx@
 export CC${role_post}=@named_cc@
 export CXX${role_post}=@named_cxx@
 
+# 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
 set +u