1 # Accumulate suffixes for taking in the right input parameters with the `mangle*`
2 # functions below. See setup-hook for details.
4 declare -ga role_suffixes
=()
5 if [ "${NIX_@wrapperName@_TARGET_BUILD_@suffixSalt@:-}" ]; then
6 role_suffixes
+=('_FOR_BUILD')
8 if [ "${NIX_@wrapperName@_TARGET_HOST_@suffixSalt@:-}" ]; then
11 if [ "${NIX_@wrapperName@_TARGET_TARGET_@suffixSalt@:-}" ]; then
12 role_suffixes
+=('_FOR_TARGET')
16 mangleVarListGeneric
() {
21 local -a role_suffixes
=("$@")
23 local outputVar
="${var}_@suffixSalt@"
24 declare -gx "$outputVar"+=''
25 # For each role we serve, we accumulate the input parameters into our own
26 # cc-wrapper-derivation-specific environment variables.
27 for suffix
in "${role_suffixes[@]}"; do
28 local inputVar
="${var}${suffix}"
29 if [ -v "$inputVar" ]; then
30 export "${outputVar}+=${!outputVar:+$sep}${!inputVar}"
36 mangleVarListGeneric
" " "$@"
42 local -a role_suffixes
=("$@")
44 local outputVar
="${var}_@suffixSalt@"
45 declare -gxi "${outputVar}+=0"
46 for suffix
in "${role_suffixes[@]}"; do
47 local inputVar
="${var}${suffix}"
48 if [ -v "$inputVar" ]; then
49 # "1" in the end makes `let` return success error code when
50 # expression itself evaluates to zero.
51 # We don't use `|| true` because that would silence actual
52 # syntax errors from bad variable values.
53 let "${outputVar} |= ${!inputVar:-0}" "1"
58 # Combine a singular value from all roles. If multiple roles are being served,
59 # and the value differs in these roles then the request is impossible to
60 # satisfy and we abort immediately.
64 local -a role_suffixes
=("$@")
66 local outputVar
="${var}_@suffixSalt@"
67 for suffix
in "${role_suffixes[@]}"; do
68 local inputVar
="${var}${suffix}"
69 if [ -v "$inputVar" ]; then
70 if [ -v "$outputVar" ]; then
71 if [ "${!outputVar}" != "${!inputVar}" ]; then
73 echo "Multiple conflicting values defined for $outputVar"
74 echo "Existing value is ${!outputVar}"
75 echo "Attempting to set to ${!inputVar} via $inputVar"
81 declare -gx ${outputVar}="${!inputVar}"
88 if (( "${NIX_DEBUG:-0}" >= 1 )); then
89 echo "skipping impure path $1" >&2
94 echo "impure path \`$1' used in link" >&2
99 # Checks whether a path is impure. E.g., `/lib/foo.so' is impure, but
100 # `/nix/store/.../lib/foo.so' isn't.
104 # Relative paths are okay (since they're presumably relative to
105 # the temporary build directory).
106 if [ "${p:0:1}" != / ]; then return 1; fi
108 # Otherwise, the path should refer to the store or some temporary
109 # directory (including the build directory).
111 "$p" != "/dev/null" -a \
112 "${p#"${NIX_STORE}"}" = "$p" -a \
113 "${p#"${NIX_BUILD_TOP}"}" = "$p" -a \
114 "${p#/tmp}" = "$p" -a \
115 "${p#"${TMP:-/tmp}"}" = "$p" -a \
116 "${p#"${TMPDIR:-/tmp}"}" = "$p" -a \
117 "${p#"${TEMP:-/tmp}"}" = "$p" -a \
118 "${p#"${TEMPDIR:-/tmp}"}" = "$p"
121 # Like `badPath`, but handles paths that may be interpreted relative to
122 # `$SDKROOT` on Darwin. For example, `-L/usr/lib/swift` is interpreted
123 # as `-L$SDKROOT/usr/lib/swift` when `$SDKROOT` is set and
124 # `$SDKROOT/usr/lib/swift` exists.
125 badPathWithDarwinSdk
() {
127 if [[ "@darwinMinVersion@" ]]; then
128 sdkPath
=$SDKROOT/$path
129 if [[ -e $sdkPath ]]; then
136 expandResponseParams
() {
137 declare -ga params
=("$@")
140 if [[ "$arg" == @
* ]]; then
141 # phase separation makes this look useless
142 # shellcheck disable=SC2157
143 if [ -x "@expandResponseParams@" ]; then
144 # params is used by caller
145 #shellcheck disable=SC2034
146 readarray
-d '' params
< <("@expandResponseParams@" "$@")
157 if [[ "$arg" = -static ]]; then
159 elif [[ "$arg" = -static-pie ]]; then
166 # When building static-pie executables we cannot have rpath
167 # set. At least glibc requires rpath to be empty
169 local linkType
=$1 ret i
172 if [[ "$linkType" == "static-pie" ]]; then
173 while [[ "$#" -gt 0 ]]; do
175 if [[ "$i" == -rpath ]]; then
176 # also skip its argument