Skip to content

Commit 63835f0

Browse files
committed
Add zstd support on Unix
1 parent 9bb8bcb commit 63835f0

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

cpython-unix/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ $(OUTDIR)/xz-$(XZ_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/
236236
$(OUTDIR)/zlib-$(ZLIB_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-zlib.sh
237237
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) zlib
238238

239+
$(OUTDIR)/zstd-$(ZSTD_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-zstd.sh
240+
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) zstd
241+
239242
PYTHON_HOST_DEPENDS := \
240243
$(PYTHON_DEP_DEPENDS) \
241244
$(HERE)/build-cpython-host.sh \
@@ -272,6 +275,7 @@ PYTHON_DEPENDS_$(1) := \
272275
$$(if $$(NEED_UUID),$$(OUTDIR)/uuid-$$(UUID_VERSION)-$$(PACKAGE_SUFFIX).tar) \
273276
$$(if $$(NEED_XZ),$$(OUTDIR)/xz-$$(XZ_VERSION)-$$(PACKAGE_SUFFIX).tar) \
274277
$$(if $$(NEED_ZLIB),$$(OUTDIR)/zlib-$$(ZLIB_VERSION)-$$(PACKAGE_SUFFIX).tar) \
278+
$$(if $$(NEED_ZSTD),$$(OUTDIR)/zstd-$$(ZSTD_VERSION)-$$(PACKAGE_SUFFIX).tar) \
275279
$$(NULL)
276280

277281
ALL_PYTHON_DEPENDS_$(1) = \

cpython-unix/build-cpython.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" && "${TARGET_TRIPLE}" = "ppc64le
377377
LDFLAGS="${LDFLAGS} -Wl,--no-tls-get-addr-optimize"
378378
fi
379379

380+
# On Python 3.14+, there's a zstd module
381+
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]]; then
382+
EXTRA_CONFIGURE_FLAGS="${EXTRA_CONFIGURE_FLAGS} --with-zstd=${TOOLS_PATH}/deps"
383+
fi
384+
380385
CPPFLAGS=$CFLAGS
381386

382387
CONFIGURE_FLAGS="

cpython-unix/build-zstd.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
set -ex
7+
8+
ROOT=`pwd`
9+
10+
export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH
11+
export PREFIX="/tools/deps"
12+
13+
tar -xf zstd-${ZSTD_VERSION}.tar.gz
14+
15+
pushd cpython-source-deps-zstd-${ZSTD_VERSION}/lib
16+
17+
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" make -j ${NUM_CPUS} lib-release
18+
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out

cpython-unix/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ def main():
11631163
"xtrans",
11641164
"xz",
11651165
"zlib",
1166+
"zstd",
11661167
):
11671168
tools_path = "host" if action in ("m4", "patchelf") else "deps"
11681169

cpython-unix/extension-modules.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,14 @@ _xxtestfuzz:
772772
- _xxtestfuzz/fuzzer.c
773773

774774
_zstd:
775-
# Disable on all targets until we add a zstd library
776-
disabled-targets:
777-
- .*
778775
minimum-python-version: '3.14'
779776
sources:
780777
- _zstd/_zstdmodule.c
781-
- _zstd/zdict.c
778+
- _zstd/zstddict.c
782779
- _zstd/compressor.c
783780
- _zstd/decompressor.c
781+
links:
782+
- zstd
784783

785784
_zoneinfo:
786785
minimum-python-version: "3.9"

cpython-unix/targets.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ aarch64-apple-darwin:
108108
- tk
109109
- uuid
110110
- xz
111+
- zstd
111112
openssl_target: darwin64-arm64-cc
112113

113114
aarch64-apple-ios:

0 commit comments

Comments
 (0)