Skip to content

Commit c1d592c

Browse files
authored
Merge pull request #71 from thatch/thatch/zstd-prereq
Build with zstd support
2 parents 69e3a93 + 0379153 commit c1d592c

5 files changed

Lines changed: 54 additions & 4 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
10+
liblzma-dev libbz2-dev libzstd-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
11+
from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, 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, Xz, Bzip2, Readline, Openssl, Sqlite, Bdb, Gdbm, Uuid, TkInter]
99+
return [LibFFI, Zlib, Zstd, Xz, Bzip2, Readline, Openssl, Sqlite, Bdb, Gdbm, Uuid, TkInter]
100100

101101
@property
102102
def url(self):
@@ -172,6 +172,18 @@ def c_configure_args(self):
172172
yield f"-ltcl{version.mm}"
173173
yield f"-ltk{version.mm}"
174174

175+
def xenv_LIBZSTD_CFLAGS(self):
176+
if self.version >= "3.14" and PPG.target.is_macos:
177+
# Normally ./configure will autodetect using pkg-config, but
178+
# this doesn't typically work on Mac (the pkg-config binary is
179+
# in homebrew, which we omit from path) so we have to provide
180+
# some hints about how to staticly include it.
181+
yield f"-I{self.deps}/include"
182+
183+
def xenv_LIBZSTD_LIBS(self):
184+
if self.version >= "3.14" and PPG.target.is_macos:
185+
yield f"{self.deps_lib_dir}/libzstd.a"
186+
175187
@runez.cached_property
176188
def prefix_lib_folder(self):
177189
"""Path to <prefix>/lib/pythonM.m folder"""

src/portable_python/external/_inspect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"_tkinter": "TCL_VERSION TK_VERSION",
1111
"_sqlite3": "sqlite_version version",
1212
"_ssl": "OPENSSL_VERSION",
13+
"_zstd": "zstd_version",
1314
"dbm.gnu": "_GDBM_VERSION",
1415
"ensurepip": "_PIP_VERSION",
1516
"pyexpat": "version_info",

src/portable_python/external/xcpython.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os.path
12
from typing import ClassVar
23

34
import runez
@@ -428,3 +429,39 @@ def _do_linux_compile(self):
428429
self.run_configure("./configure", self.c_configure_args())
429430
self.run_make()
430431
self.run_make("install")
432+
433+
434+
class Zstd(ModuleBuilder):
435+
"""
436+
Newer compression format present in most 3.14+ builds
437+
"""
438+
439+
m_debian = "!libzstd-dev"
440+
m_telltale = "{include}/zstd.h"
441+
442+
xenv_CFLAGS = "-fPIC"
443+
444+
def auto_select_reason(self):
445+
if self.setup.python_spec.version >= "3.14":
446+
if PPG.target.is_macos:
447+
return "Required for 3.14 and up" # Well, "expected" anyway
448+
if not self.resolved_telltale:
449+
return "Required for 3.14 and up"
450+
451+
@property
452+
def url(self):
453+
return (
454+
self.cfg_url(self.version) or f"https://github.com/facebook/zstd/releases/download/v{self.version}/zstd-{self.version}.tar.gz"
455+
)
456+
457+
@property
458+
def version(self):
459+
return self.cfg_version("1.5.7")
460+
461+
def _do_linux_compile(self):
462+
# Notably, this does not build when given a relative path.
463+
self.run_make(f"prefix={os.path.abspath(self.deps)}")
464+
# the libdir on the resulting .dylib on Mac is wrong, but as long as we
465+
# staticly compile this doesn't need a fixup. I got as far as:
466+
# "libdir=\\$(executable_path)/../lib")
467+
self.run_make("install", f"prefix={os.path.abspath(self.deps)}")

src/portable_python/inspector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def get_lib_type(install_folder, path, basename):
397397

398398

399399
class PythonInspector:
400-
default = "_bz2,_ctypes,_curses,_decimal,_dbm,_gdbm,_lzma,_tkinter,_sqlite3,_ssl,_uuid,pip,readline,pyexpat,setuptools,zlib"
400+
default = "_bz2,_ctypes,_curses,_decimal,_dbm,_gdbm,_lzma,_tkinter,_sqlite3,_ssl,_uuid,_zstd,pip,readline,pyexpat,setuptools,zlib"
401401
additional = "_asyncio,_functools,_tracemalloc,dbm.gnu,ensurepip,ossaudiodev,spwd,sys,tkinter,venv,wheel"
402402

403403
def __init__(self, spec, modules=None):

0 commit comments

Comments
 (0)