Skip to content

Commit 01cfc3b

Browse files
authored
Add support for Python 3.14 on macOS and GNU Linux (astral-sh#443)
The biggest change seems to be around blake2's implementation. I figure I'll follow-up on musl Linux separately.
1 parent 9b16897 commit 01cfc3b

12 files changed

+199
-35
lines changed

Diff for: ci-matrix.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ def should_include_entry(entry: dict[str, str], filters: dict[str, set[str]]) ->
7171
if filters.get("arch") and entry["arch"] not in filters["arch"]:
7272
return False
7373

74-
if filters.get("libc") and entry.get("libc") not in filters["libc"]:
74+
if (
75+
filters.get("libc")
76+
and entry.get("libc")
77+
and entry["libc"] not in filters["libc"]
78+
):
7579
return False
7680

7781
if filters.get("build"):

Diff for: ci-targets.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ darwin:
99
- "3.11"
1010
- "3.12"
1111
- "3.13"
12+
- "3.14"
1213
build_options:
1314
- debug
1415
- pgo+lto
@@ -26,6 +27,7 @@ darwin:
2627
- "3.11"
2728
- "3.12"
2829
- "3.13"
30+
- "3.14"
2931
build_options:
3032
- debug
3133
- pgo+lto
@@ -45,6 +47,7 @@ linux:
4547
- "3.11"
4648
- "3.12"
4749
- "3.13"
50+
- "3.14"
4851
build_options:
4952
- debug
5053
- noopt
@@ -65,6 +68,7 @@ linux:
6568
- "3.11"
6669
- "3.12"
6770
- "3.13"
71+
- "3.14"
6872
build_options:
6973
- debug
7074
- noopt
@@ -85,6 +89,7 @@ linux:
8589
- "3.11"
8690
- "3.12"
8791
- "3.13"
92+
- "3.14"
8893
build_options:
8994
- debug
9095
- noopt
@@ -105,6 +110,7 @@ linux:
105110
- "3.11"
106111
- "3.12"
107112
- "3.13"
113+
- "3.14"
108114
build_options:
109115
- debug
110116
- noopt
@@ -125,6 +131,7 @@ linux:
125131
- "3.11"
126132
- "3.12"
127133
- "3.13"
134+
- "3.14"
128135
build_options:
129136
- debug
130137
- noopt
@@ -145,6 +152,7 @@ linux:
145152
- "3.11"
146153
- "3.12"
147154
- "3.13"
155+
- "3.14"
148156
build_options:
149157
- debug
150158
- pgo+lto
@@ -165,6 +173,7 @@ linux:
165173
- "3.11"
166174
- "3.12"
167175
- "3.13"
176+
- "3.14"
168177
build_options:
169178
- debug
170179
- pgo+lto
@@ -185,6 +194,7 @@ linux:
185194
- "3.11"
186195
- "3.12"
187196
- "3.13"
197+
- "3.14"
188198
build_options:
189199
- debug
190200
- pgo+lto
@@ -205,6 +215,7 @@ linux:
205215
- "3.11"
206216
- "3.12"
207217
- "3.13"
218+
- "3.14"
208219
build_options:
209220
- debug
210221
- noopt

Diff for: cpython-unix/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BUILD := $(HERE)/build.py
66
NULL :=
77
SPACE := $(subst ,, )
88

9-
ALL_PYTHON_VERSIONS := 3.9 3.10 3.11 3.12 3.13
9+
ALL_PYTHON_VERSIONS := 3.9 3.10 3.11 3.12 3.13 3.14
1010

1111
ifndef PYBUILD_TARGET_TRIPLE
1212
$(error PYBUILD_TARGET_TRIPLE not defined)

Diff for: cpython-unix/build-cpython.sh

+23-7
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ cat Makefile.extra
7070
pushd Python-${PYTHON_VERSION}
7171

7272
# configure doesn't support cross-compiling on Apple. Teach it.
73-
if [ "${PYTHON_MAJMIN_VERSION}" = "3.13" ]; then
74-
patch -p1 -i ${ROOT}/patch-apple-cross-3.13.patch
75-
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.12" ]; then
76-
patch -p1 -i ${ROOT}/patch-apple-cross-3.12.patch
77-
else
78-
patch -p1 -i ${ROOT}/patch-apple-cross.patch
73+
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
74+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
75+
patch -p1 -i ${ROOT}/patch-apple-cross-3.13.patch
76+
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.12" ]; then
77+
patch -p1 -i ${ROOT}/patch-apple-cross-3.12.patch
78+
else
79+
patch -p1 -i ${ROOT}/patch-apple-cross.patch
80+
fi
7981
fi
8082

8183
# This patch is slightly different on Python 3.10+.
@@ -94,7 +96,9 @@ fi
9496
# Configure nerfs RUNSHARED when cross-compiling, which prevents PGO from running when
9597
# we can in fact run the target binaries (e.g. x86_64 host and i686 target). Undo that.
9698
if [ -n "${CROSS_COMPILING}" ]; then
97-
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
99+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]; then
100+
patch -p1 -i ${ROOT}/patch-dont-clear-runshared-14.patch
101+
elif [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
98102
patch -p1 -i ${ROOT}/patch-dont-clear-runshared-13.patch
99103
elif [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
100104
patch -p1 -i ${ROOT}/patch-dont-clear-runshared.patch
@@ -471,6 +475,18 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
471475
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_ptsname_r=no"
472476
fi
473477

478+
# explicit_bzero is only available in glibc 2.25+, but we target a lower version for compatibility.
479+
# it's only needed for the HACL Blake2 implementation in Python 3.14+
480+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]; then
481+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_explicit_bzero=no"
482+
fi
483+
484+
# On 3.14+ `test_strftime_y2k` fails when cross-compiling for `x86_64_v2` and `x86_64_v3` targets on
485+
# Linux, so we ignore it. See https://github.com/python/cpython/issues/128104
486+
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
487+
export PROFILE_TASK='-m test --pgo --ignore test_strftime_y2k'
488+
fi
489+
474490
# We use ndbm on macOS and BerkeleyDB elsewhere.
475491
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
476492
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=ndbm"

Diff for: cpython-unix/build-main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import sys
1313

14+
from pythonbuild.cpython import meets_python_minimum_version
1415
from pythonbuild.downloads import DOWNLOADS
1516
from pythonbuild.utils import (
1617
compress_python_archive,
@@ -68,6 +69,7 @@ def main():
6869
"cpython-3.11",
6970
"cpython-3.12",
7071
"cpython-3.13",
72+
"cpython-3.14",
7173
},
7274
default="cpython-3.11",
7375
help="Python distribution to build",
@@ -164,7 +166,9 @@ def main():
164166
release_tag = release_tag_from_git()
165167

166168
# Guard against accidental misuse of the free-threaded flag with older versions
167-
if "freethreaded" in args.options and python_majmin not in ("3.13",):
169+
if "freethreaded" in args.options and not meets_python_minimum_version(
170+
python_majmin, "3.13"
171+
):
168172
print(
169173
"Invalid build option: 'freethreaded' is only compatible with CPython 3.13+ (got %s)"
170174
% cpython_version

Diff for: cpython-unix/build.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def build_cpython_host(
465465

466466
# Set environment variables allowing convenient testing for Python
467467
# version ranges.
468-
for v in ("3.9", "3.10", "3.11", "3.12", "3.13"):
468+
for v in ("3.9", "3.10", "3.11", "3.12", "3.13", "3.14"):
469469
normal_version = v.replace(".", "_")
470470

471471
if meets_python_minimum_version(python_version, v):
@@ -801,7 +801,7 @@ def build_cpython(
801801

802802
# Set environment variables allowing convenient testing for Python
803803
# version ranges.
804-
for v in ("3.9", "3.10", "3.11", "3.12", "3.13"):
804+
for v in ("3.9", "3.10", "3.11", "3.12", "3.13", "3.14"):
805805
normal_version = v.replace(".", "_")
806806

807807
if meets_python_minimum_version(python_version, v):
@@ -1223,6 +1223,7 @@ def main():
12231223
"cpython-3.11",
12241224
"cpython-3.12",
12251225
"cpython-3.13",
1226+
"cpython-3.14",
12261227
):
12271228
build_cpython(
12281229
settings,

Diff for: cpython-unix/extension-modules.yml

+33-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,36 @@ _bisect:
1919
- _bisectmodule.c
2020

2121
_blake2:
22-
sources:
23-
- _blake2/blake2module.c
24-
- _blake2/blake2b_impl.c
25-
- _blake2/blake2s_impl.c
22+
# In 3.14+, Blake2 is provided by Hacl*
23+
sources-conditional:
24+
- sources:
25+
- _blake2/blake2module.c
26+
- _blake2/blake2b_impl.c
27+
- _blake2/blake2s_impl.c
28+
maximum-python-version: "3.13"
29+
- sources:
30+
- blake2module.c
31+
- _hacl/Hacl_Hash_Blake2s.c
32+
- _hacl/Hacl_Hash_Blake2b.c
33+
- _hacl/Lib_Memzero0.c
34+
minimum-python-version: "3.14"
35+
includes-conditional:
36+
- includes:
37+
- Modules/_hacl
38+
- Modules/_hacl/include
39+
- Modules/_hacl/internal
40+
minimum-python-version: "3.14"
41+
links-conditional:
42+
- name: :libHacl_Hash_Blake2.a
43+
minimum-python-version: "3.14"
44+
defines-conditional:
45+
- define: _BSD_SOURCE
46+
minimum-python-version: "3.14"
47+
- define: _DEFAULT_SOURCE
48+
minimum-python-version: "3.14"
49+
# Disable `explicit_bzero`, it requires glib 2.25+
50+
- define: LINUX_NO_EXPLICIT_BZERO
51+
minimum-python-version: "3.14"
2652

2753
_bz2:
2854
sources:
@@ -355,6 +381,9 @@ _multiprocessing:
355381
_opcode:
356382
sources:
357383
- _opcode.c
384+
setup-enabled-conditional:
385+
- enabled: true
386+
minimum-python-version: "3.14"
358387

359388
_operator:
360389
setup-enabled: true

Diff for: cpython-unix/patch-dont-clear-runshared-14.patch

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index bd0221481c5..f2fb52c1efc 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -1605,10 +1605,6 @@ else # shared is disabled
6+
fi
7+
AC_MSG_RESULT([$LDLIBRARY])
8+
9+
-if test "$cross_compiling" = yes; then
10+
- RUNSHARED=
11+
-fi
12+
-
13+
# HOSTRUNNER - Program to run CPython for the host platform
14+
AC_MSG_CHECKING([HOSTRUNNER])
15+
if test -z "$HOSTRUNNER"

0 commit comments

Comments
 (0)