Skip to content

Commit 3236d6e

Browse files
authored
Merge pull request #72 from thatch/thatch/mpdec
Add support for building with libmpdec
2 parents c1d592c + 52ce29d commit 3236d6e

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y git htop build-essential \
77
gdb lcov patchelf python3-pip python3-venv tcl \
88
libexpat1-dev libffi-dev zlib1g-dev libgdbm-dev libgdbm-compat-dev \
99
libssl-dev libsqlite3-dev uuid-dev \
10-
liblzma-dev libbz2-dev libzstd-dev
10+
liblzma-dev libbz2-dev libzstd-dev libmpdec-dev
1111

1212
RUN /usr/bin/python3 -mpip install -U pip setuptools
1313

src/portable_python/cpython.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from runez.pyenv import Version
99

1010
from portable_python import LOG, patch_file, patch_folder, PPG, PythonBuilder
11-
from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd
11+
from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Mpdec, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd
1212
from portable_python.external.xtkinter import TkInter
1313
from portable_python.inspector import LibAutoCorrect, PythonInspector
1414

@@ -96,7 +96,7 @@ def build_information(self):
9696

9797
@classmethod
9898
def candidate_modules(cls):
99-
return [LibFFI, Zlib, Zstd, Xz, Bzip2, Readline, Openssl, Sqlite, Bdb, Gdbm, Uuid, TkInter]
99+
return [LibFFI, Zlib, Zstd, Xz, Bzip2, Readline, Openssl, Sqlite, Bdb, Gdbm, Uuid, TkInter, Mpdec]
100100

101101
@property
102102
def url(self):
@@ -184,6 +184,18 @@ def xenv_LIBZSTD_LIBS(self):
184184
if self.version >= "3.14" and PPG.target.is_macos:
185185
yield f"{self.deps_lib_dir}/libzstd.a"
186186

187+
def xenv_LIBMPDEC_CFLAGS(self):
188+
if self.version >= "3.14" and PPG.target.is_macos:
189+
# Normally ./configure will autodetect using pkg-config, but
190+
# this doesn't typically work on Mac (the pkg-config binary is
191+
# in homebrew, which we omit from path) so we have to provide
192+
# some hints about how to staticly include it.
193+
yield f"-I{self.deps}/include"
194+
195+
def xenv_LIBMPDEC_LIBS(self):
196+
if self.version >= "3.14" and PPG.target.is_macos:
197+
yield f"{self.deps_lib_dir}/libmpdec.a"
198+
187199
@runez.cached_property
188200
def prefix_lib_folder(self):
189201
"""Path to <prefix>/lib/pythonM.m folder"""

src/portable_python/external/xcpython.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,42 @@ def _do_linux_compile(self):
465465
# staticly compile this doesn't need a fixup. I got as far as:
466466
# "libdir=\\$(executable_path)/../lib")
467467
self.run_make("install", f"prefix={os.path.abspath(self.deps)}")
468+
469+
470+
class Mpdec(ModuleBuilder):
471+
"""
472+
Prevent falling back to bundled libmpdec (deprecated and scheduled for removal in Python 3.16)
473+
"""
474+
475+
m_debian = "!libmpdec-dev"
476+
m_telltale = "{include}/mpdecimal.h"
477+
478+
xenv_CFLAGS = "-fPIC"
479+
480+
def auto_select_reason(self):
481+
if self.setup.python_spec.version >= "3.16":
482+
if PPG.target.is_macos:
483+
return "Required for 3.16 and up"
484+
if not self.resolved_telltale:
485+
return "Required for 3.16 and up"
486+
487+
@property
488+
def url(self):
489+
return self.cfg_url(self.version) or f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{self.version}.tar.gz"
490+
491+
@property
492+
def version(self):
493+
return self.cfg_version("4.0.1")
494+
495+
def c_configure_args(self):
496+
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
497+
yield config_args
498+
499+
else:
500+
pass # yield "--static"
501+
yield "--disable-cxx"
502+
503+
def _do_linux_compile(self):
504+
self.run_configure("./configure", self.c_configure_args())
505+
self.run_make()
506+
self.run_make("install")

0 commit comments

Comments
 (0)