https://github.com/python/cpython/commit/ecb3f23b9494c30cdd7c68eb20d7ba01e1a334f4
commit: ecb3f23b9494c30cdd7c68eb20d7ba01e1a334f4
branch: main
author: Hood Chatham <roberthoodchat...@gmail.com>
committer: freakboy3742 <russ...@keith-magee.com>
date: 2025-07-24T06:31:30Z
summary:

gh-136976: Emscripten: Add _decimal and libmpdec (#136997)

Adds tooling to build mpdec (and thus _decimal) as part of an Emscripten build.

files:
M Tools/wasm/emscripten/__main__.py

diff --git a/Tools/wasm/emscripten/__main__.py 
b/Tools/wasm/emscripten/__main__.py
index b25cbb01dedd31..202dd298199b56 100644
--- a/Tools/wasm/emscripten/__main__.py
+++ b/Tools/wasm/emscripten/__main__.py
@@ -8,6 +8,7 @@
 import subprocess
 import sys
 import sysconfig
+import hashlib
 import tempfile
 from urllib.request import urlopen
 from pathlib import Path
@@ -164,20 +165,60 @@ def make_build_python(context, working_dir):
     print(f"🎉 {binary} {version}")
 
 
-@subdir(HOST_BUILD_DIR, clean_ok=True)
-def make_emscripten_libffi(context, working_dir):
-    shutil.rmtree(working_dir / "libffi-3.4.6", ignore_errors=True)
+def check_shasum(file: str, expected_shasum: str):
+    with open(file, "rb") as f:
+        digest = hashlib.file_digest(f, "sha256")
+    if digest.hexdigest() != expected_shasum:
+        raise RuntimeError(f"Unexpected shasum for {file}")
+
+
+def download_and_unpack(working_dir: Path, url: str, expected_shasum: str):
     with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete_on_close=False) 
as tmp_file:
-        with urlopen(
-            
"https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz";
-        ) as response:
+        with urlopen(url) as response:
             shutil.copyfileobj(response, tmp_file)
         tmp_file.close()
+        check_shasum(tmp_file.name, expected_shasum)
         shutil.unpack_archive(tmp_file.name, working_dir)
+
+
+@subdir(HOST_BUILD_DIR, clean_ok=True)
+def make_emscripten_libffi(context, working_dir):
+    ver = "3.4.6"
+    libffi_dir = working_dir / f"libffi-{ver}"
+    shutil.rmtree(libffi_dir, ignore_errors=True)
+    download_and_unpack(working_dir, 
f"https://github.com/libffi/libffi/releases/download/v{ver}/libffi-{ver}.tar.gz";,
 "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e")
     call(
         [EMSCRIPTEN_DIR / "make_libffi.sh"],
         env=updated_env({"PREFIX": PREFIX_DIR}),
-        cwd=working_dir / "libffi-3.4.6",
+        cwd=libffi_dir,
+        quiet=context.quiet,
+    )
+
+
+@subdir(HOST_BUILD_DIR, clean_ok=True)
+def make_mpdec(context, working_dir):
+    ver = "4.0.1"
+    mpdec_dir = working_dir / f"mpdecimal-{ver}"
+    shutil.rmtree(mpdec_dir, ignore_errors=True)
+    download_and_unpack(working_dir, 
f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{ver}.tar.gz";, 
"96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8")
+    call(
+        [
+            "emconfigure",
+            mpdec_dir / "configure",
+            "CFLAGS=-fPIC",
+            "--prefix",
+            PREFIX_DIR,
+            "--disable-shared",
+        ],
+        cwd=mpdec_dir,
+        quiet=context.quiet,
+    )
+    call(
+        [
+            "make",
+            "install"
+        ],
+        cwd=mpdec_dir,
         quiet=context.quiet,
     )
 
@@ -315,6 +356,7 @@ def build_all(context):
         configure_build_python,
         make_build_python,
         make_emscripten_libffi,
+        make_mpdec,
         configure_emscripten_python,
         make_emscripten_python,
     ]
@@ -343,6 +385,9 @@ def main():
     configure_build = subcommands.add_parser(
         "configure-build-python", help="Run `configure` for the " "build 
Python"
     )
+    make_mpdec_cmd = subcommands.add_parser(
+        "make-mpdec", help="Clone mpdec repo, configure and build it for 
emscripten"
+    )
     make_libffi_cmd = subcommands.add_parser(
         "make-libffi", help="Clone libffi repo, configure and build it for 
emscripten"
     )
@@ -363,6 +408,7 @@ def main():
         build,
         configure_build,
         make_libffi_cmd,
+        make_mpdec_cmd,
         make_build,
         configure_host,
         make_host,
@@ -400,6 +446,7 @@ def main():
 
     dispatch = {
         "make-libffi": make_emscripten_libffi,
+        "make-mpdec": make_mpdec,
         "configure-build-python": configure_build_python,
         "make-build-python": make_build_python,
         "configure-host": configure_emscripten_python,

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to