Skip to content

Commit 2110d43

Browse files
authored
Build mpdecimal on Windows and fix Python 3.13 validation (#7)
* Attempt to download and build `mpdecimal` on Windows * Patch `mpdecimal` in `python.props` * Remove `_msi` from expected global extensions * Allow `_msi` to be missing during `collect_python_build_artifacts` * Add `_testclinic_limited` and `_testlimitedcapi` to ignored extensions * Add `python313.dll` to allowed libraries * Fix expected global extensions for 3.13 * Allow `_PyWarnings_Init` to be missing on 3.13 * Include 3.8 in `_PyWarnings_Init` case * Include `_xxsubinterpreters` in 3.8 extensions
1 parent 4a78a31 commit 2110d43

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

cpython-windows/build.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
"_lzma": {
6666
"ignore_additional_depends": {"$(OutDir)liblzma$(PyDebugExt).lib"},
6767
},
68-
"_msi": {},
68+
"_msi": {
69+
# Removed in 3.13.
70+
"ignore_missing": True,
71+
},
6972
"_overlapped": {},
7073
"_multiprocessing": {},
7174
"_socket": {},
@@ -352,13 +355,15 @@ def hack_props(
352355
xz_version = DOWNLOADS["xz"]["version"]
353356
zlib_version = DOWNLOADS["zlib"]["version"]
354357
tcltk_commit = DOWNLOADS["tk-windows-bin"]["git_commit"]
358+
mpdecimal_version = DOWNLOADS["mpdecimal"]["version"]
355359

356360
sqlite_path = td / ("sqlite-autoconf-%s" % sqlite_version)
357361
bzip2_path = td / ("bzip2-%s" % bzip2_version)
358362
libffi_path = td / "libffi"
359363
tcltk_path = td / ("cpython-bin-deps-%s" % tcltk_commit)
360364
xz_path = td / ("xz-%s" % xz_version)
361365
zlib_path = td / ("zlib-%s" % zlib_version)
366+
mpdecimal_path = td / ("mpdecimal-%s" % mpdecimal_version)
362367

363368
openssl_root = td / "openssl" / arch
364369
openssl_libs_path = openssl_root / "lib"
@@ -398,6 +403,9 @@ def hack_props(
398403
elif b"<zlibDir" in line:
399404
line = b"<zlibDir>%s\\</zlibDir>" % zlib_path
400405

406+
elif b"<mpdecimalDir" in line:
407+
line = b"<mpdecimalDir>%s\\</mpdecimalDir>" % mpdecimal_path
408+
401409
lines.append(line)
402410

403411
with python_props_path.open("wb") as fh:
@@ -1155,15 +1163,17 @@ def collect_python_build_artifacts(
11551163
"_ctypes_test",
11561164
"_testbuffer",
11571165
"_testcapi",
1166+
"_testclinic_limited",
11581167
"_testclinic",
11591168
"_testconsole",
11601169
"_testembed",
11611170
"_testimportmultiple",
11621171
"_testinternalcapi",
1163-
"_testsinglephase",
1172+
"_testlimitedcapi",
11641173
"_testmultiphase",
1165-
"xxlimited",
1174+
"_testsinglephase",
11661175
"xxlimited_35",
1176+
"xxlimited",
11671177
}
11681178

11691179
other_projects = {"pythoncore"}
@@ -1409,6 +1419,12 @@ def build_cpython(
14091419
setuptools_wheel = download_entry("setuptools", BUILD)
14101420
pip_wheel = download_entry("pip", BUILD)
14111421

1422+
# CPython 3.13+ no longer uses a bundled version by default
1423+
if meets_python_minimum_version(python_version, "3.13"):
1424+
mpdecimal_archive = download_entry("mpdecimal", BUILD)
1425+
else:
1426+
mpdecimal_archive = None
1427+
14121428
if arch == "amd64":
14131429
build_platform = "x64"
14141430
build_directory = "amd64"
@@ -1426,12 +1442,16 @@ def build_cpython(
14261442
for a in (
14271443
python_archive,
14281444
bzip2_archive,
1445+
mpdecimal_archive,
14291446
openssl_archive,
14301447
sqlite_archive,
14311448
tk_bin_archive,
14321449
xz_archive,
14331450
zlib_archive,
14341451
):
1452+
if a is None:
1453+
continue
1454+
14351455
log("extracting %s to %s" % (a, td))
14361456
fs.append(e.submit(extract_tar_to_directory, a, td))
14371457

@@ -1599,11 +1619,6 @@ def build_cpython(
15991619
if not meets_python_minimum_version(python_version, "3.12"):
16001620
args.append("--include-distutils")
16011621

1602-
# CPython 3.13+ no longer uses a bundled libmpdec by default
1603-
# TODO(zanieb): We should use the system libmpdec as we do for Unix builds
1604-
if meets_python_minimum_version(python_version, "3.13"):
1605-
args.append("--with-system-libmpdec=no")
1606-
16071622
args.extend(["--include-idle", "--include-stable", "--include-tcltk"])
16081623

16091624
exec_and_log(

src/validation.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const PE_ALLOWED_LIBRARIES: &[&str] = &[
125125
"python310.dll",
126126
"python311.dll",
127127
"python312.dll",
128+
"python313.dll",
128129
"sqlite3.dll",
129130
"tcl86t.dll",
130131
"tk86t.dll",
@@ -679,7 +680,13 @@ const GLOBAL_EXTENSIONS: &[&str] = &[
679680
// We didn't build ctypes_test until 3.9.
680681
// We didn't build some test extensions until 3.9.
681682

682-
const GLOBAL_EXTENSIONS_PYTHON_3_8: &[&str] = &["audioop", "_sha256", "_sha512", "parser"];
683+
const GLOBAL_EXTENSIONS_PYTHON_3_8: &[&str] = &[
684+
"audioop",
685+
"_sha256",
686+
"_sha512",
687+
"parser",
688+
"_xxsubinterpreters",
689+
];
683690

684691
const GLOBAL_EXTENSIONS_PYTHON_3_9: &[&str] = &[
685692
"audioop",
@@ -727,9 +734,7 @@ const GLOBAL_EXTENSIONS_PYTHON_3_13: &[&str] = &[
727734
"_interpqueues",
728735
"_interpreters",
729736
"_sha2",
730-
"_suggestions",
731737
"_sysconfig",
732-
"_testexternalinspection",
733738
"_tokenize",
734739
"_typing",
735740
"_zoneinfo",
@@ -759,16 +764,16 @@ const GLOBAL_EXTENSIONS_POSIX: &[&str] = &[
759764
const GLOBAL_EXTENSIONS_LINUX_PRE_3_13: &[&str] = &["spwd"];
760765

761766
const GLOBAL_EXTENSIONS_WINDOWS: &[&str] = &[
762-
"_msi",
763767
"_overlapped",
764768
"_winapi",
765-
"_xxsubinterpreters",
766769
"msvcrt",
767770
"nt",
768771
"winreg",
769772
"winsound",
770773
];
771774

775+
const GLOBAL_EXTENSIONS_WINDOWS_PRE_3_13: &[&str] = &["_msi"];
776+
772777
/// Extension modules not present in Windows static builds.
773778
const GLOBAL_EXTENSIONS_WINDOWS_NO_STATIC: &[&str] = &["_testinternalcapi", "_tkinter"];
774779

@@ -1494,6 +1499,10 @@ fn validate_extension_modules(
14941499
if is_windows {
14951500
wanted.extend(GLOBAL_EXTENSIONS_WINDOWS);
14961501

1502+
if matches!(python_major_minor, "3.8" | "3.9" | "3.10" | "3.11" | "3.12") {
1503+
wanted.extend(GLOBAL_EXTENSIONS_WINDOWS_PRE_3_13);
1504+
}
1505+
14971506
if static_crt {
14981507
for x in GLOBAL_EXTENSIONS_WINDOWS_NO_STATIC {
14991508
wanted.remove(*x);
@@ -1949,9 +1958,10 @@ fn validate_distribution(
19491958
// Static distributions never export symbols.
19501959
let wanted = if is_static {
19511960
false
1952-
// For some strange reason _PyWarnings_Init is exported as part of the ABI.
1961+
// For some strange reason _PyWarnings_Init is exported as part of the ABI before
1962+
// Python 3.13.
19531963
} else if name == "_warnings" {
1954-
true
1964+
matches!(python_major_minor, "3.8" | "3.9" | "3.10" | "3.11" | "3.12")
19551965
// Windows dynamic doesn't export extension module init functions.
19561966
} else if triple.contains("-windows-") {
19571967
false

0 commit comments

Comments
 (0)