diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index 1c5b08541ac2..310cbc001c8b 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -44,9 +44,9 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}" while (( "$n" < "$nParams" )); do p=${params[n]} p2=${params[n+1]:-} # handle `p` being last one - if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then + if [ "${p:0:3}" = -L/ ] && badPathWithDarwinSdk "${p:2}"; then skip "${p:2}" - elif [ "$p" = -L ] && badPath "$p2"; then + elif [ "$p" = -L ] && badPathWithDarwinSdk "$p2"; then n+=1; skip "$p2" elif [ "$p" = -rpath ] && badPath "$p2"; then n+=1; skip "$p2" diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 5d338a0dd0dc..da1a709684da 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -103,7 +103,7 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then -[IL] | -isystem) path=$p2 skipNext=true ;; esac - if [[ -n $path ]] && badPath "$path"; then + if [[ -n $path ]] && badPathWithDarwinSdk "$path"; then skip "$path" $skipNext && n+=1 continue diff --git a/pkgs/build-support/wrapper-common/utils.bash b/pkgs/build-support/wrapper-common/utils.bash index 2faf96df15b4..c9870d1b4d41 100644 --- a/pkgs/build-support/wrapper-common/utils.bash +++ b/pkgs/build-support/wrapper-common/utils.bash @@ -118,6 +118,21 @@ badPath() { "${p#"${TEMPDIR:-/tmp}"}" = "$p" } +# Like `badPath`, but handles paths that may be interpreted relative to +# `$SDKROOT` on Darwin. For example, `-L/usr/lib/swift` is interpreted +# as `-L$SDKROOT/usr/lib/swift` when `$SDKROOT` is set and +# `$SDKROOT/usr/lib/swift` exists. +badPathWithDarwinSdk() { + path=$1 + if [[ "@darwinMinVersion@" ]]; then + sdkPath=$SDKROOT/$path + if [[ -e $sdkPath ]]; then + path=$sdkPath + fi + fi + badPath "$path" +} + expandResponseParams() { declare -ga params=("$@") local arg