Skip to content

Fix Python 3.13 builds on macOS #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then
patch -p1 -i ${ROOT}/patch-makesetup-deduplicate-objs.patch
fi

# testembed links against Tcl/Tk and libpython which already has Tcl/Tk leading
# duplicate symbols and warnings from objc (which causes test failures).
if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_13}" ]; then
patch -p1 -i ${ROOT}/patch-make-testembed-nolink-tcltk.patch
fi

# The default build rule for the macOS dylib doesn't pick up libraries
# from modules / makesetup. So patch it accordingly.
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
Expand Down Expand Up @@ -444,6 +450,12 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
export MACOSX_DEPLOYMENT_TARGET="${APPLE_MIN_DEPLOYMENT_TARGET}"
fi

# ptsrname_r is only available in SDK 13.4+
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
echo "Disabling ptsname_r due to macOS SDK 13.4+ requirement."
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_ptsname_r=no"
fi

# We use ndbm on macOS and BerkeleyDB elsewhere.
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=ndbm"
Expand Down
10 changes: 10 additions & 0 deletions cpython-unix/patch-make-testembed-nolink-tcltk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/Makefile.pre.in b/Makefile.pre.in
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1432,6 +1432,8 @@
$(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/build/generate_re_casefix.py $(srcdir)/Lib/re/_casefix.py

Programs/_testembed: Programs/_testembed.o $(LINK_PYTHON_DEPS)
+ $(eval MODLIBS := $(subst -Xlinker -hidden-ltcl8.6, , $(MODLIBS)))
+ $(eval MODLIBS := $(subst -Xlinker -hidden-ltk8.6, , $(MODLIBS)))
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
6 changes: 3 additions & 3 deletions cpython-unix/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ thumb7k-apple-watchos:

# Intel macOS.
#
# We target compatibility with macOS 10.13+ for compatibility with older Apple
# We target compatibility with macOS 10.9+ for compatibility with older Apple
# machines.
x86_64-apple-darwin:
host_platforms:
Expand All @@ -566,7 +566,7 @@ x86_64-apple-darwin:
target_cflags:
- '-arch'
- 'x86_64'
- '-mmacosx-version-min=10.13.4'
- '-mmacosx-version-min=10.9'
# Suppress extremely verbose warnings we see with LLVM 10.
- '-Wno-nullability-completeness'
- '-Wno-expansion-to-defined'
Expand All @@ -581,7 +581,7 @@ x86_64-apple-darwin:
target_ldflags:
- '-arch'
- 'x86_64'
- '-mmacosx-version-min=10.13.4'
- '-mmacosx-version-min=10.9'
needs:
- autoconf
- bzip2
Expand Down
4 changes: 2 additions & 2 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static PLATFORM_TAG_BY_TRIPLE: Lazy<HashMap<&'static str, &'static str>> = Lazy:
("mips64el-unknown-linux-gnuabi64", "todo"),
("ppc64le-unknown-linux-gnu", "linux-powerpc64le"),
("s390x-unknown-linux-gnu", "linux-s390x"),
("x86_64-apple-darwin", "macosx-10.13-x86_64"),
("x86_64-apple-darwin", "macosx-10.9-x86_64"),
("x86_64-apple-ios", "iOS-x86_64"),
("x86_64-pc-windows-msvc", "win-amd64"),
("x86_64-unknown-linux-gnu", "linux-x86_64"),
Expand Down Expand Up @@ -1100,7 +1100,7 @@ fn validate_macho<Mach: MachHeader<Endian = Endianness>>(
bytes: &[u8],
) -> Result<()> {
let advertised_target_version =
semver::Version::parse(&format!("{}", advertised_target_version))?;
semver::Version::parse(&format!("{}.0", advertised_target_version))?;
let advertised_sdk_version = semver::Version::parse(&format!("{}.0", advertised_sdk_version))?;

let endian = header.endian()?;
Expand Down