Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 0 additions & 16 deletions cpython-unix/build-cpython-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ tar -xf Python-${PYTHON_VERSION}.tar.xz

pushd "Python-${PYTHON_VERSION}"

# Clang 13 actually prints something with --print-multiarch, confusing CPython's
# configure. This is reported as https://bugs.python.org/issue45405. We nerf the
# check since we know what we're doing.
if [ "${CC}" = "clang" ]; then
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
patch -p1 -i ${ROOT}/patch-disable-multiarch-13.patch
else
patch -p1 -i ${ROOT}/patch-disable-multiarch.patch
fi
elif [ "${CC}" = "musl-clang" ]; then
# Similarly, this is a problem for musl Clang on Python 3.13+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
patch -p1 -i ${ROOT}/patch-disable-multiarch-13.patch
fi
fi

autoconf

# When cross-compiling, we need to build a host Python that has working zlib
Expand Down
17 changes: 8 additions & 9 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ if [ -n "${CROSS_COMPILING}" ]; then
fi
fi

# Clang 13 actually prints something with --print-multiarch, confusing CPython's
# configure. This is reported as https://bugs.python.org/issue45405. We nerf the
# check since we know what we're doing.
if [[ "${CC}" = "clang" || "${CC}" = "musl-clang" ]]; then
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
patch -p1 -i ${ROOT}/patch-disable-multiarch-13.patch
else
patch -p1 -i ${ROOT}/patch-disable-multiarch.patch
fi
# CPython <=3.10 doesn't properly detect musl. CPython <=3.12 tries, but fails in our environment
# because of an autoconf bug. CPython >=3.13 is fine.
# Backport the musl detection code from CPython 3.13 so it loads
# extension modules with the right suffix.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This mixed line length wrapping is perturbing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to remove those last two lines because we're not backporting the code, not sure how I left them in.... will fix when I figure out the build failure

if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then
patch -p1 -i ${ROOT}/patch-cpython-configure-target-triple-musl-3.10.patch
elif [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_12}" ]; then
patch -p1 -i ${ROOT}/patch-cpython-configure-target-triple-musl-3.12.patch
fi

# Python 3.11 supports using a provided Python to use during bootstrapping
Expand Down
2 changes: 0 additions & 2 deletions cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ def build_cpython_host(

support = {
"build-cpython-host.sh",
"patch-disable-multiarch.patch",
"patch-disable-multiarch-13.patch",
}
for s in sorted(support):
build_env.copy_file(SUPPORT / s)
Expand Down
31 changes: 31 additions & 0 deletions cpython-unix/patch-cpython-configure-target-triple-musl-3.10.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From d7a70fe9ffa0e4e173bae545cdcba62dc7a2a1f1 Mon Sep 17 00:00:00 2001
From: Geoffrey Thomas <[email protected]>
Date: Sat, 25 Oct 2025 18:49:45 -0400
Subject: [PATCH 1/1] LOCAL: configure.ac: Fix musl detection
Forwarded: not-needed

Newer versions of Python rework this code significantly, so this does
not need to be upstreamed.
---
configure.ac | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/configure.ac b/configure.ac
index ac3be3850a9..9c7c02ea6de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -866,6 +866,11 @@ EOF

if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
+ case "$CC" in
+ musl-*)
+ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
+ ;;
+ esac
AC_MSG_RESULT([$PLATFORM_TRIPLET])
else
AC_MSG_RESULT([none])
--
2.39.5 (Apple Git-154)

36 changes: 36 additions & 0 deletions cpython-unix/patch-cpython-configure-target-triple-musl-3.12.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From 851c49bafb1fe11c02eafe4850e952cafec548b7 Mon Sep 17 00:00:00 2001
From: Geoffrey Thomas <[email protected]>
Date: Sat, 25 Oct 2025 18:49:45 -0400
Subject: [PATCH 1/1] LOCAL: configure.ac: Fix musl detection
Forwarded: not-needed

We set HOST_CC to regular (glibc) clang and CC to musl-clang.
AC_CANONICAL_HOST sets build_os based on the output of config.guess,
which looks at HOST_CC in preference to CC, and therefore misreports the
target triple as gnu. Directly checking CC works for us.

Newer versions of Python rework this code significantly to not rely on
build_os and do musl detection internally, so this does not need to be
upstreamed.
---
configure.ac | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1a02d19f1b2..ee743c11aa5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1108,8 +1108,8 @@ EOF

if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
- case "$build_os" in
- linux-musl*)
+ case "$CC" in
+ musl-*)
PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
;;
esac
--
2.39.5 (Apple Git-154)

17 changes: 0 additions & 17 deletions cpython-unix/patch-disable-multiarch-13.patch

This file was deleted.

17 changes: 0 additions & 17 deletions cpython-unix/patch-disable-multiarch.patch

This file was deleted.

12 changes: 12 additions & 0 deletions src/verify_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import importlib.machinery
import os
import struct
import sys
Expand Down Expand Up @@ -255,6 +256,17 @@ def test_hash_algorithm(self):
msg=f"{sys.hash_info.algorithm=!r} is not siphash",
)

def test_libc_identity(self):
def assertLibc(value):
for libc in ("-gnu", "-musl"):
if os.environ["TARGET_TRIPLE"].endswith(libc):
self.assertIn(libc, value)
else:
self.assertNotIn(libc, value)

assertLibc(sys.implementation._multiarch)
assertLibc(importlib.machinery.EXTENSION_SUFFIXES[0])


if __name__ == "__main__":
unittest.main()
Loading