Skip to content

Commit afc3b40

Browse files
committed
Starting with 3.14, zstd is expected
1 parent 030e0b0 commit afc3b40

3 files changed

Lines changed: 43 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
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: 12 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,16 @@ def c_configure_args(self):
172172
yield f"-ltcl{version.mm}"
173173
yield f"-ltk{version.mm}"
174174

175+
if self.active_module(Zstd):
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"LIBZSTD_CFLAGS=-I{self.deps}/include"
182+
yield f"LIBZSTD_LIBS={self.deps_lib_dir}/libzstd.a"
183+
184+
175185
@runez.cached_property
176186
def prefix_lib_folder(self):
177187
"""Path to <prefix>/lib/pythonM.m folder"""

src/portable_python/external/xcpython.py

Lines changed: 30 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,32 @@ 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+
class Zstd(ModuleBuilder):
434+
"""
435+
"""
436+
437+
m_debian = "!libzstd-dev"
438+
m_telltale = "{include}/zstd.h"
439+
440+
xenv_CFLAGS = "-fPIC"
441+
442+
def auto_select_reason(self):
443+
if self.setup.python_spec.version >= "3.14":
444+
return "Required for 3.14 and up" # Well, "expected" anyway
445+
446+
@property
447+
def url(self):
448+
return self.cfg_url(self.version) or f"https://github.com/facebook/zstd/releases/download/v{self.version}/zstd-{self.version}.tar.gz"
449+
450+
@property
451+
def version(self):
452+
return self.cfg_version("1.5.7")
453+
454+
def _do_linux_compile(self):
455+
# Notably, this does not build when given a relative path.
456+
self.run_make(f"prefix={os.path.abspath(self.deps)}")
457+
# the libdir on the resulting .dylib on Mac is wrong, but as long as we
458+
# staticly compile this doesn't need a fixup. I got as far as:
459+
# "libdir=\\$(executable_path)/../lib")
460+
self.run_make("install", f"prefix={os.path.abspath(self.deps)}")

0 commit comments

Comments
 (0)