From 40c4afa2ba938cb458ff6f2320a8a2f3d4d47fb8 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Mar 2025 16:27:18 -0500 Subject: [PATCH 1/7] Add support for Python 3.14 on musl --- ci-targets.yaml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ci-targets.yaml b/ci-targets.yaml index cd892ac9..70078e87 100644 --- a/ci-targets.yaml +++ b/ci-targets.yaml @@ -256,6 +256,7 @@ linux: - "3.11" - "3.12" - "3.13" + - "3.14" build_options: - debug+static - noopt+static @@ -263,6 +264,12 @@ linux: - debug - noopt - lto + build_options_conditional: + - options: + - freethreaded+debug + - freethreaded+noopt + - freethreaded+lto + minimum-python-version: "3.13" run: true x86_64_v2-unknown-linux-musl: @@ -275,6 +282,7 @@ linux: - "3.11" - "3.12" - "3.13" + - "3.14" build_options: - debug+static - noopt+static @@ -282,6 +290,12 @@ linux: - debug - noopt - lto + build_options_conditional: + - options: + - freethreaded+debug + - freethreaded+noopt + - freethreaded+lto + minimum-python-version: "3.13" run: true x86_64_v3-unknown-linux-musl: @@ -294,6 +308,7 @@ linux: - "3.11" - "3.12" - "3.13" + - "3.14" build_options: - debug+static - noopt+static @@ -301,6 +316,12 @@ linux: - debug - noopt - lto + build_options_conditional: + - options: + - freethreaded+debug + - freethreaded+noopt + - freethreaded+lto + minimum-python-version: "3.13" run: true x86_64_v4-unknown-linux-musl: @@ -313,6 +334,7 @@ linux: - "3.11" - "3.12" - "3.13" + - "3.14" build_options: - debug+static - noopt+static @@ -320,6 +342,12 @@ linux: - debug - noopt - lto + build_options_conditional: + - options: + - freethreaded+debug + - freethreaded+noopt + - freethreaded+lto + minimum-python-version: "3.13" run: true windows: From e13624fcc2b121a1f47ed791725dd01da0180cfe Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Mar 2025 16:55:14 -0500 Subject: [PATCH 2/7] Allow missing `cpuid.h` --- cpython-unix/extension-modules.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpython-unix/extension-modules.yml b/cpython-unix/extension-modules.yml index a8ff460f..90139ef6 100644 --- a/cpython-unix/extension-modules.yml +++ b/cpython-unix/extension-modules.yml @@ -49,6 +49,11 @@ _blake2: # Disable `explicit_bzero`, it requires glib 2.25+ - define: LINUX_NO_EXPLICIT_BZERO minimum-python-version: "3.14" + # Disable cpuid.h requirement for musl builds + - define: NO_CPUID + targets: + - .*-unknown-linux-musl + minimum-python-version: "3.14" _bz2: sources: From 6c2a3b2190bc79ecdf00a246f6092265cdf607bf Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Mar 2025 17:57:42 -0500 Subject: [PATCH 3/7] Patch `cpuid.h` guard --- cpython-unix/build-cpython.sh | 6 ++++++ cpython-unix/extension-modules.yml | 5 ----- cpython-unix/patch-blake-musl-314.patch | 12 ++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 cpython-unix/patch-blake-musl-314.patch diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 5e66f053..1cbcee3f 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -317,6 +317,12 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then patch -p1 -i ${ROOT}/patch-test-embed-prevent-segfault.patch fi + +# For Python 3.14+, the include for `cpuid.h` is improperly guarded +if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && "${CC}" = "musl-clang" ]]; then + patch -p1 -i ${ROOT}/patch-blake-musl-314.patch +fi + # Most bits look at CFLAGS. But setup.py only looks at CPPFLAGS. # So we need to set both. CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC -I${TOOLS_PATH}/deps/include -I${TOOLS_PATH}/deps/include/ncursesw" diff --git a/cpython-unix/extension-modules.yml b/cpython-unix/extension-modules.yml index 90139ef6..a8ff460f 100644 --- a/cpython-unix/extension-modules.yml +++ b/cpython-unix/extension-modules.yml @@ -49,11 +49,6 @@ _blake2: # Disable `explicit_bzero`, it requires glib 2.25+ - define: LINUX_NO_EXPLICIT_BZERO minimum-python-version: "3.14" - # Disable cpuid.h requirement for musl builds - - define: NO_CPUID - targets: - - .*-unknown-linux-musl - minimum-python-version: "3.14" _bz2: sources: diff --git a/cpython-unix/patch-blake-musl-314.patch b/cpython-unix/patch-blake-musl-314.patch new file mode 100644 index 00000000..0c3010ba --- /dev/null +++ b/cpython-unix/patch-blake-musl-314.patch @@ -0,0 +1,12 @@ +diff --git a/Modules/blake2module.c b/Modules/blake2module.c +--- a/Modules/blake2module.c ++++ b/Modules/blake2module.c +@@ -33,7 +33,7 @@ + // pulled into the build automatically, and then only the CPU autodetection will + // need to be updated here. + +-#if defined(__x86_64__) && defined(__GNUC__) ++#if defined(__x86_64__) && defined(__GLIBC__) + #include + #elif defined(_M_X64) + #include From 5ba95acdf6fb1c35c14a54819c52e8a0d598de16 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Mar 2025 18:25:21 -0500 Subject: [PATCH 4/7] Patch `__cpuid_count` too --- cpython-unix/build-cpython.sh | 2 +- cpython-unix/patch-blake-musl-314.patch | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 1cbcee3f..dcabfe0a 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -318,7 +318,7 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then fi -# For Python 3.14+, the include for `cpuid.h` is improperly guarded +# For Python 3.14+, use of `cpuid` is improperly guarded if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && "${CC}" = "musl-clang" ]]; then patch -p1 -i ${ROOT}/patch-blake-musl-314.patch fi diff --git a/cpython-unix/patch-blake-musl-314.patch b/cpython-unix/patch-blake-musl-314.patch index 0c3010ba..a5955973 100644 --- a/cpython-unix/patch-blake-musl-314.patch +++ b/cpython-unix/patch-blake-musl-314.patch @@ -10,3 +10,12 @@ diff --git a/Modules/blake2module.c b/Modules/blake2module.c #include #elif defined(_M_X64) #include +@@ -76,7 +76,7 @@ void detect_cpu_features(cpu_flags *flags) { + if (!flags->done) { + int eax1 = 0, ebx1 = 0, ecx1 = 0, edx1 = 0; + int eax7 = 0, ebx7 = 0, ecx7 = 0, edx7 = 0; +-#if defined(__x86_64__) && defined(__GNUC__) ++#if defined(__x86_64__) && defined(__GNULIBC__) + __cpuid_count(1, 0, eax1, ebx1, ecx1, edx1); + __cpuid_count(7, 0, eax7, ebx7, ecx7, edx7); + #elif defined(_M_X64) From 445dc69193963b34f9680c357964f0dc8e733c63 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Mar 2025 18:50:01 -0500 Subject: [PATCH 5/7] Update match for 3.13+ --- cpython-unix/build-cpython.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index dcabfe0a..c96b63f4 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -980,7 +980,7 @@ s390x-unknown-linux-gnu) x86_64-unknown-linux-*) # In Python 3.13+, the musl target is identified in cross compiles and the output directory # is named accordingly. - if [ "${CC}" = "musl-clang" ] && [ "${PYTHON_MAJMIN_VERSION}" = "3.13" ]; then + if [[ "${CC}" = "musl-clang" && -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]]; then PYTHON_ARCH="x86_64-linux-musl" else PYTHON_ARCH="x86_64-linux-gnu" From 70de8d8c944c9752900533a0967188418e2521b5 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 19 Mar 2025 20:32:59 -0500 Subject: [PATCH 6/7] Disable free-threaded builds --- ci-targets.yaml | 52 +++++++++++++++++++---------------- cpython-unix/build-cpython.sh | 2 +- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/ci-targets.yaml b/ci-targets.yaml index 70078e87..b1f53aa8 100644 --- a/ci-targets.yaml +++ b/ci-targets.yaml @@ -264,12 +264,13 @@ linux: - debug - noopt - lto - build_options_conditional: - - options: - - freethreaded+debug - - freethreaded+noopt - - freethreaded+lto - minimum-python-version: "3.13" + # freethreaded builds require mimalloc which is not available on musl yet + # build_options_conditional: + # - options: + # - freethreaded+debug + # - freethreaded+noopt + # - freethreaded+lto + # minimum-python-version: "3.13" run: true x86_64_v2-unknown-linux-musl: @@ -290,12 +291,13 @@ linux: - debug - noopt - lto - build_options_conditional: - - options: - - freethreaded+debug - - freethreaded+noopt - - freethreaded+lto - minimum-python-version: "3.13" + # freethreaded builds require mimalloc which is not available on musl yet + # build_options_conditional: + # - options: + # - freethreaded+debug + # - freethreaded+noopt + # - freethreaded+lto + # minimum-python-version: "3.13" run: true x86_64_v3-unknown-linux-musl: @@ -316,12 +318,13 @@ linux: - debug - noopt - lto - build_options_conditional: - - options: - - freethreaded+debug - - freethreaded+noopt - - freethreaded+lto - minimum-python-version: "3.13" + # freethreaded builds require mimalloc which is not available on musl yet + # build_options_conditional: + # - options: + # - freethreaded+debug + # - freethreaded+noopt + # - freethreaded+lto + # minimum-python-version: "3.13" run: true x86_64_v4-unknown-linux-musl: @@ -342,12 +345,13 @@ linux: - debug - noopt - lto - build_options_conditional: - - options: - - freethreaded+debug - - freethreaded+noopt - - freethreaded+lto - minimum-python-version: "3.13" + # freethreaded builds require mimalloc which is not available on musl yet + # build_options_conditional: + # - options: + # - freethreaded+debug + # - freethreaded+noopt + # - freethreaded+lto + # minimum-python-version: "3.13" run: true windows: diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index c96b63f4..bfce75d8 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -422,7 +422,7 @@ if [ -n "${CPYTHON_DEBUG}" ]; then fi # Explicitly enable mimalloc on 3.13+, it's already included by default but with this it'll fail -# if it's missing from the system. The MUSL builds do not supprt mimalloc yet. +# if it's missing from the system. The musl builds do not supprt mimalloc yet. if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" && "${CC}" != "musl-clang" ]]; then CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-mimalloc" fi From cd1c6dd42995526811b7d6d16cadad0798d2eb83 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 20 Mar 2025 15:57:40 -0500 Subject: [PATCH 7/7] Include `cpuid.h` from clang --- cpython-unix/build-cpython.sh | 8 +------- cpython-unix/patch-blake-musl-314.patch | 21 --------------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 cpython-unix/patch-blake-musl-314.patch diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index bfce75d8..bd045e91 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -317,12 +317,6 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then patch -p1 -i ${ROOT}/patch-test-embed-prevent-segfault.patch fi - -# For Python 3.14+, use of `cpuid` is improperly guarded -if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && "${CC}" = "musl-clang" ]]; then - patch -p1 -i ${ROOT}/patch-blake-musl-314.patch -fi - # Most bits look at CFLAGS. But setup.py only looks at CPPFLAGS. # So we need to set both. CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC -I${TOOLS_PATH}/deps/include -I${TOOLS_PATH}/deps/include/ncursesw" @@ -397,7 +391,7 @@ if [ "${CC}" = "musl-clang" ]; then # provided by musl. These are part of the include files that are part of clang. # But musl-clang eliminates them from the default include path. So copy them into # place. - for h in /tools/${TOOLCHAIN}/lib/clang/*/include/*intrin.h /tools/${TOOLCHAIN}/lib/clang/*/include/{__wmmintrin_aes.h,__wmmintrin_pclmul.h,mm_malloc.h}; do + for h in /tools/${TOOLCHAIN}/lib/clang/*/include/*intrin.h /tools/${TOOLCHAIN}/lib/clang/*/include/{__wmmintrin_aes.h,__wmmintrin_pclmul.h,mm_malloc.h,cpuid.h}; do filename=$(basename "$h") if [ -e "/tools/host/include/${filename}" ]; then echo "${filename} already exists; don't need to copy!" diff --git a/cpython-unix/patch-blake-musl-314.patch b/cpython-unix/patch-blake-musl-314.patch deleted file mode 100644 index a5955973..00000000 --- a/cpython-unix/patch-blake-musl-314.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/Modules/blake2module.c b/Modules/blake2module.c ---- a/Modules/blake2module.c -+++ b/Modules/blake2module.c -@@ -33,7 +33,7 @@ - // pulled into the build automatically, and then only the CPU autodetection will - // need to be updated here. - --#if defined(__x86_64__) && defined(__GNUC__) -+#if defined(__x86_64__) && defined(__GLIBC__) - #include - #elif defined(_M_X64) - #include -@@ -76,7 +76,7 @@ void detect_cpu_features(cpu_flags *flags) { - if (!flags->done) { - int eax1 = 0, ebx1 = 0, ecx1 = 0, edx1 = 0; - int eax7 = 0, ebx7 = 0, ecx7 = 0, edx7 = 0; --#if defined(__x86_64__) && defined(__GNUC__) -+#if defined(__x86_64__) && defined(__GNULIBC__) - __cpuid_count(1, 0, eax1, ebx1, ecx1, edx1); - __cpuid_count(7, 0, eax7, ebx7, ecx7, edx7); - #elif defined(_M_X64)