Skip to content

Commit 8995523

Browse files
committed
Add support for building with libmpdec
We don't need-need this until 3.16 now, but earlier versions threatened we would need it as of 3.15 so I thought it more urgent. We don't force it on, so only use if already available.
1 parent c1d592c commit 8995523

3 files changed

Lines changed: 53 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, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd, Mpdec
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,41 @@ 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+
class Mpdec(ModuleBuilder):
470+
"""
471+
Prevent falling back to bundled libmpdec (deprecated and scheduled for removal in Python 3.16)
472+
"""
473+
474+
m_debian = "!libmpdec-dev"
475+
m_telltale = "{include}/mpdecimal.h"
476+
477+
xenv_CFLAGS = "-fPIC"
478+
479+
def auto_select_reason(self):
480+
if self.setup.python_spec.version >= "3.16":
481+
if PPG.target.is_macos:
482+
return "Required for 3.16 and up"
483+
if not self.resolved_telltale:
484+
return "Required for 3.16 and up"
485+
486+
@property
487+
def url(self):
488+
return self.cfg_url(self.version) or f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{self.version}.tar.gz"
489+
490+
@property
491+
def version(self):
492+
return self.cfg_version("4.0.1")
493+
494+
def c_configure_args(self):
495+
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
496+
yield config_args
497+
498+
else:
499+
pass # yield "--static"
500+
yield "--disable-cxx"
501+
502+
def _do_linux_compile(self):
503+
self.run_configure("./configure", self.c_configure_args())
504+
self.run_make()
505+
self.run_make("install")

0 commit comments

Comments
 (0)