1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-10 12:33:48 -05:00

Use Zlib from XCode SDK in a way compatible with XCode 16 and CLT (#3301)

* use `xcrun` instead of `xcodebuild` which is absent in CLT
* use an alternative way that's compatible with CPython's setup.py since 3.5.2

---------

Co-authored-by: Ivan Pozdeev <vano@mail.mipt.ru>
This commit is contained in:
Jared Stever
2025-08-16 10:17:53 -07:00
committed by GitHub
parent bc44cb8fc0
commit 71a8d47b81

View File

@@ -1826,24 +1826,24 @@ use_homebrew_zlib() {
} }
use_xcode_sdk_zlib() { use_xcode_sdk_zlib() {
local xcode_major;
# If a custom compiler is used, including XCode SDK will likely break it # If a custom compiler is used, including XCode SDK will likely break it
[[ "${CC:-clang}" != "clang" || "$(command -v clang 2>/dev/null || true)" != "/usr/bin/clang" ]] && return 1 [[ "${CC:-clang}" != "clang" || "$(command -v clang 2>/dev/null || true)" != "/usr/bin/clang" ]] && return 1
# The flags set by this function break the build in XCode 16 due to unknown changes from XCode 15
# For future-proofing, also disable it if we cannot determine the version local sdkroot="$(xcrun --sdk macosx --show-sdk-path 2>/dev/null || true)"
[[ $(xcodebuild -version 2>/dev/null || true) =~ ^Xcode\ ([[:digit:]]+) ]] && xcode_major="${BASH_REMATCH[1]}" [[ -z ${sdkroot} || ! -d ${sdkroot} ]] && return 1
[[ -z $xcode_major || $xcode_major -ge 16 ]] && return 1
local xc_sdk_path="$(xcrun --show-sdk-path 2>/dev/null || true)" # Since Xcode 16 / macOS SDK 15, Apple tightened how the linker uses SDK content:
if [ -d "$xc_sdk_path" ]; then # forcing -L "$SDK/usr/lib" now leads to odd link failures.
echo "python-build: use zlib from xcode sdk" echo "python-build: use zlib from xcode sdk"
# Even though SDK's compiler uses the SDK dirs implicitly, # Since 3.9.1 (bpo-41116), CPython's setup.py logic can search default SDK's sysroot itself
# CPython's setup.py has to have nonstandard paths specified explicitly # so we don't need to do anything
# to search for zlib.h in them # Since 3.5.2 (Issue #25136), distutils knows to look for Apple XCode 7+ stub libraries (.tbd)
export CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-I${xc_sdk_path}/usr/include" # when searching in the SDK
if is_mac -ge 1100; then # Since 2.7.4 and 3.2.1 (issue #7724), setup.py and distutils can search in the MacOS SDK when
export LDFLAGS="${LDFLAGS:+$LDFLAGS }-L${xc_sdk_path}/usr/lib" # it's explicitly specified with -isysroot
fi
fi export CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }-isysroot ${sdkroot}"
return 0
} }
use_macports_zlib() { use_macports_zlib() {