diff --git a/Dockerfile b/Dockerfile index 4adc57c..155e000 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y git htop build-essential \ gdb lcov patchelf python3-pip python3-venv tcl \ libexpat1-dev libffi-dev zlib1g-dev libgdbm-dev libgdbm-compat-dev \ libssl-dev libsqlite3-dev uuid-dev \ - liblzma-dev libbz2-dev libzstd-dev + liblzma-dev libbz2-dev libzstd-dev libmpdec-dev RUN /usr/bin/python3 -mpip install -U pip setuptools diff --git a/src/portable_python/cpython.py b/src/portable_python/cpython.py index d712c3f..118e427 100644 --- a/src/portable_python/cpython.py +++ b/src/portable_python/cpython.py @@ -8,7 +8,7 @@ from runez.pyenv import Version from portable_python import LOG, patch_file, patch_folder, PPG, PythonBuilder -from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd +from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Mpdec, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd from portable_python.external.xtkinter import TkInter from portable_python.inspector import LibAutoCorrect, PythonInspector @@ -96,7 +96,7 @@ def build_information(self): @classmethod def candidate_modules(cls): - return [LibFFI, Zlib, Zstd, Xz, Bzip2, Readline, Openssl, Sqlite, Bdb, Gdbm, Uuid, TkInter] + return [LibFFI, Zlib, Zstd, Xz, Bzip2, Readline, Openssl, Sqlite, Bdb, Gdbm, Uuid, TkInter, Mpdec] @property def url(self): @@ -184,6 +184,18 @@ def xenv_LIBZSTD_LIBS(self): if self.version >= "3.14" and PPG.target.is_macos: yield f"{self.deps_lib_dir}/libzstd.a" + def xenv_LIBMPDEC_CFLAGS(self): + if self.version >= "3.14" and PPG.target.is_macos: + # Normally ./configure will autodetect using pkg-config, but + # this doesn't typically work on Mac (the pkg-config binary is + # in homebrew, which we omit from path) so we have to provide + # some hints about how to staticly include it. + yield f"-I{self.deps}/include" + + def xenv_LIBMPDEC_LIBS(self): + if self.version >= "3.14" and PPG.target.is_macos: + yield f"{self.deps_lib_dir}/libmpdec.a" + @runez.cached_property def prefix_lib_folder(self): """Path to /lib/pythonM.m folder""" diff --git a/src/portable_python/external/xcpython.py b/src/portable_python/external/xcpython.py index dd11828..2059722 100644 --- a/src/portable_python/external/xcpython.py +++ b/src/portable_python/external/xcpython.py @@ -465,3 +465,42 @@ def _do_linux_compile(self): # staticly compile this doesn't need a fixup. I got as far as: # "libdir=\\$(executable_path)/../lib") self.run_make("install", f"prefix={os.path.abspath(self.deps)}") + + +class Mpdec(ModuleBuilder): + """ + Prevent falling back to bundled libmpdec (deprecated and scheduled for removal in Python 3.16) + """ + + m_debian = "!libmpdec-dev" + m_telltale = "{include}/mpdecimal.h" + + xenv_CFLAGS = "-fPIC" + + def auto_select_reason(self): + if self.setup.python_spec.version >= "3.16": + if PPG.target.is_macos: + return "Required for 3.16 and up" + if not self.resolved_telltale: + return "Required for 3.16 and up" + + @property + def url(self): + return self.cfg_url(self.version) or f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{self.version}.tar.gz" + + @property + def version(self): + return self.cfg_version("4.0.1") + + def c_configure_args(self): + if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir): + yield config_args + + else: + pass # yield "--static" + yield "--disable-cxx" + + def _do_linux_compile(self): + self.run_configure("./configure", self.c_configure_args()) + self.run_make() + self.run_make("install")