Skip to content

Commit 2db5c1d

Browse files
committed
Fix musl detection in Python 3.12 and below
CPython 3.10 and below don't even attempt to fix the target triple for musl. CPython 3.11 and 3.12 do, but in our setup it doens't work right because of an autoconf bug. CPython 3.13 rewrites the target triple detection logic and works fine. Meanwhile, the previous patch to this part of configure.ac is no longer relevant because clang stopped implementing --print-multiarch in LLVM 16 (llvm/llvm-project@e05edb19), so we can drop those patches. Fixes #724.
1 parent 5dcb8cc commit 2db5c1d

6 files changed

+87
-43
lines changed

cpython-unix/build-cpython.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,14 @@ if [ -n "${CROSS_COMPILING}" ]; then
115115
fi
116116
fi
117117

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

129128
# Python 3.11 supports using a provided Python to use during bootstrapping
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From d7a70fe9ffa0e4e173bae545cdcba62dc7a2a1f1 Mon Sep 17 00:00:00 2001
2+
From: Geoffrey Thomas <[email protected]>
3+
Date: Sat, 25 Oct 2025 18:49:45 -0400
4+
Subject: [PATCH 1/1] LOCAL: configure.ac: Fix musl detection
5+
Forwarded: not-needed
6+
7+
Newer versions of Python rework this code significantly, so this does
8+
not need to be upstreamed.
9+
---
10+
configure.ac | 5 +++++
11+
1 file changed, 5 insertions(+)
12+
13+
diff --git a/configure.ac b/configure.ac
14+
index ac3be3850a9..9c7c02ea6de 100644
15+
--- a/configure.ac
16+
+++ b/configure.ac
17+
@@ -866,6 +866,11 @@ EOF
18+
19+
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
20+
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
21+
+ case "$CC" in
22+
+ musl-*)
23+
+ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
24+
+ ;;
25+
+ esac
26+
AC_MSG_RESULT([$PLATFORM_TRIPLET])
27+
else
28+
AC_MSG_RESULT([none])
29+
--
30+
2.39.5 (Apple Git-154)
31+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From 851c49bafb1fe11c02eafe4850e952cafec548b7 Mon Sep 17 00:00:00 2001
2+
From: Geoffrey Thomas <[email protected]>
3+
Date: Sat, 25 Oct 2025 18:49:45 -0400
4+
Subject: [PATCH 1/1] LOCAL: configure.ac: Fix musl detection
5+
Forwarded: not-needed
6+
7+
We set HOST_CC to regular (glibc) clang and CC to musl-clang.
8+
AC_CANONICAL_HOST sets build_os based on the output of config.guess,
9+
which looks at HOST_CC in preference to CC, and therefore misreports the
10+
target triple as gnu. Directly checking CC works for us.
11+
12+
Newer versions of Python rework this code significantly to not rely on
13+
build_os and do musl detection internally, so this does not need to be
14+
upstreamed.
15+
---
16+
configure.ac | 4 ++--
17+
1 file changed, 2 insertions(+), 2 deletions(-)
18+
19+
diff --git a/configure.ac b/configure.ac
20+
index 1a02d19f1b2..ee743c11aa5 100644
21+
--- a/configure.ac
22+
+++ b/configure.ac
23+
@@ -1108,8 +1108,8 @@ EOF
24+
25+
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
26+
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
27+
- case "$build_os" in
28+
- linux-musl*)
29+
+ case "$CC" in
30+
+ musl-*)
31+
PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
32+
;;
33+
esac
34+
--
35+
2.39.5 (Apple Git-154)
36+

cpython-unix/patch-disable-multiarch-13.patch

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpython-unix/patch-disable-multiarch.patch

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/verify_distribution.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
import importlib.machinery
56
import os
67
import struct
78
import sys
@@ -255,6 +256,17 @@ def test_hash_algorithm(self):
255256
msg=f"{sys.hash_info.algorithm=!r} is not siphash",
256257
)
257258

259+
def test_libc_identity(self):
260+
def assertLibc(value):
261+
for libc in ("-gnu", "-musl"):
262+
if os.environ["TARGET_TRIPLE"].endswith(libc):
263+
self.assertIn(libc, value)
264+
else:
265+
self.assertNotIn(libc, value)
266+
267+
assertLibc(sys.implementation._multiarch)
268+
assertLibc(importlib.machinery.EXTENSION_SUFFIXES[0])
269+
258270

259271
if __name__ == "__main__":
260272
unittest.main()

0 commit comments

Comments
 (0)