From e047c69ed406c834722b6ed7bb1bdd39d3e5eef0 Mon Sep 17 00:00:00 2001 From: Emily Date: Fri, 25 Oct 2024 19:41:08 +0100 Subject: [PATCH] {bintools-wrapper,cc-wrapper}: allow paths relative to the Darwin SDK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `-L` and `-I` are interpreted relative to the `$SDKROOT` by the Darwin toolchain, so we have to avoid filtering out such paths in the purity filter hacks in order to not break e.g. the .NET Core build system. It’s also just the correct thing to do for the platform. --- pkgs/build-support/bintools-wrapper/ld-wrapper.sh | 4 ++-- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 2 +- pkgs/build-support/wrapper-common/utils.bash | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) 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