diff --git a/archivers/py-zstandard/Makefile b/archivers/py-zstandard/Makefile index 9c30f2f9a584..bbc0e13f15ad 100644 --- a/archivers/py-zstandard/Makefile +++ b/archivers/py-zstandard/Makefile @@ -2,6 +2,7 @@ DISTNAME= zstandard-0.25.0 PKGNAME= ${PYPKGPREFIX}-${DISTNAME} +PKGREVISION= 1 CATEGORIES= archivers python MASTER_SITES= ${MASTER_SITE_PYPI:=z/zstandard/} @@ -13,19 +14,22 @@ LICENSE= modified-bsd TOOL_DEPENDS+= ${PYPKGPREFIX}-setuptools>=78:../../devel/py-setuptools DEPENDS+= ${PYPKGPREFIX}-cffi>=1.11:../../devel/py-cffi TEST_DEPENDS+= ${PYPKGPREFIX}-hypothesis-[0-9]*:../../devel/py-hypothesis +TEST_DEPENDS+= ${PYPKGPREFIX}-test-[0-9]*:../../devel/py-test -.include "../../mk/bsd.prefs.mk" -# qsort_r(3) was added in NetBSD 11.0 -.if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} < 110000 -CPPFLAGS+= -DZDICT_QSORT=ZDICT_QSORT_C90 -.endif +.include "options.mk" -# as of 0.25.0 -# 28 errors +# Run the tests against the built module, once per backend. Use a copy +# of the tests outside WRKSRC so that the unbuilt zstandard directory +# there is not picked up. +do-test: + ${RUN} ${MKDIR} ${WRKDIR}/t && \ + ${CP} -R ${WRKSRC}/tests ${WRKDIR}/t/ +.for policy in cext cffi + ${RUN} cd ${WRKDIR}/t && ${SETENV} ${TEST_ENV} \ + PYTHONPATH=$$(echo ${WRKSRC}/build/lib.*) \ + PYTHON_ZSTANDARD_IMPORT_POLICY=${policy} \ + pytest-${PYVERSSUFFIX} ${PYTEST_ARGS_ZSTD} +.endfor -# upstream prefers to use its bundled version of zstd -# https://github.com/indygreg/python-zstandard/blob/0063333790a853360c816101511635865405834f/c-ext/backend_c.c#L137-L151 -#BUILDLINK_API_DEPENDS.zstd+= zstd>=1.5.7 -#.include "../../archivers/zstd/buildlink3.mk" .include "../../lang/python/wheel.mk" .include "../../mk/bsd.pkg.mk" diff --git a/archivers/py-zstandard/distinfo b/archivers/py-zstandard/distinfo index e162fcaac5d3..63f03ff9ab6f 100644 --- a/archivers/py-zstandard/distinfo +++ b/archivers/py-zstandard/distinfo @@ -3,3 +3,5 @@ $NetBSD: distinfo,v 1.30 2025/09/21 16:31:15 wiz Exp $ BLAKE2s (zstandard-0.25.0.tar.gz) = d00ec4dc262fea466fc89b02ed392a49c1efac45e56973074fd65cc526c24927 SHA512 (zstandard-0.25.0.tar.gz) = 7e7f73328ec242fbcf3e17de15f8833cb1933139bc6243751d3e23e1d6d95fd5d5e17c9b1af64d59821847d24135a55118f59a8a807d7c319612246653f4b192 Size (zstandard-0.25.0.tar.gz) = 711513 bytes +SHA1 (patch-make__cffi.py) = ad7df7dade4ed09daf84659bde6471a5905d455b +SHA1 (patch-setup.py) = b1bfdc87ef6b95665d1e84700b7a948575ee0793 diff --git a/archivers/py-zstandard/options.mk b/archivers/py-zstandard/options.mk new file mode 100644 index 000000000000..1b906c3a00cb --- /dev/null +++ b/archivers/py-zstandard/options.mk @@ -0,0 +1,23 @@ +# $NetBSD$ + +PKG_OPTIONS_VAR= PKG_OPTIONS.py-zstandard +PKG_SUPPORTED_OPTIONS= zstandard-bundled-zstd + +.include "../../mk/bsd.options.mk" + +.if !empty(PKG_OPTIONS:Mzstandard-bundled-zstd) +# The bundled zstd keeps multi_compress_to_buffer() and +# multi_decompress_to_buffer(), which need zstd's private thread pool. +# qsort_r(3) was added in NetBSD 11.0 +. if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} < 110000 +CPPFLAGS+= -DZDICT_QSORT=ZDICT_QSORT_C90 +. endif +.else +WHEEL_ARGS+= -C--global-option=--system-zstd +WHEEL_ARGS+= -C--global-option=--system-zstd-cffi +# These tests assume the bundled zstd. +PYTEST_ARGS_ZSTD= -k 'not test_features' +PYTEST_ARGS_ZSTD+= --deselect tests/test_module_attributes.py::TestModuleAttributes::test_version +BUILDLINK_API_DEPENDS.zstd+= zstd>=1.5.7 +.include "../../archivers/zstd/buildlink3.mk" +.endif diff --git a/archivers/py-zstandard/patches/patch-make__cffi.py b/archivers/py-zstandard/patches/patch-make__cffi.py new file mode 100644 index 000000000000..1b4f32fb7ef0 --- /dev/null +++ b/archivers/py-zstandard/patches/patch-make__cffi.py @@ -0,0 +1,206 @@ +$NetBSD$ + +Support building the CFFI backend against the system zstd library, +enabled with a separate --system-zstd-cffi switch. + +From Michal Gorny (Gentoo) and Boyuan Yang (Debian), as carried in +Debian's python-zstandard 0.25.0-2 (patches 0002 to 0005). +https://github.com/indygreg/python-zstandard/pull/249 + +--- make_cffi.py.orig 2025-09-14 20:35:55.000000000 +0000 ++++ make_cffi.py +@@ -16,22 +16,6 @@ + import cffi + import packaging.tags + +-HERE = os.path.abspath(os.path.dirname(__file__)) +- +-SOURCES = [ +- "zstd/zstd.c", +-] +- +-# Headers whose preprocessed output will be fed into cdef(). +-HEADERS = [ +- os.path.join(HERE, "zstd", p) +- for p in ("zstd_errors.h", "zstd.h", "zdict.h") +-] +- +-INCLUDE_DIRS = [ +- os.path.join(HERE, "zstd"), +-] +- + # cffi can't parse some of the primitives in zstd.h. So we invoke the + # preprocessor and feed its output into cffi. + compiler = distutils.ccompiler.new_compiler() +@@ -168,21 +152,67 @@ + return b"\n".join(lines) + + +-# musl 1.1 doesn't define qsort_r. We need to force using the C90 +-# variant. +-define_macros = [] +-for tag in packaging.tags.platform_tags(): +- if tag.startswith("musllinux_1_1_"): +- define_macros.append(("ZDICT_QSORT", "ZDICT_QSORT_C90")) ++def get_ffi(system_zstd = False): ++ zstd_sources = [] ++ include_dirs = [] ++ libraries = [] ++ ++ if not system_zstd: ++ here = os.path.abspath(os.path.dirname(__file__)) ++ ++ zstd_sources += [ ++ "zstd/zstd.c", ++ ] ++ ++ # Headers whose preprocessed output will be fed into cdef(). ++ headers = [ ++ os.path.join(here, "zstd", p) ++ for p in ("zstd_errors.h", "zstd.h", "zdict.h") ++ ] + ++ include_dirs += [ ++ os.path.join(here, "zstd"), ++ ] ++ else: ++ libraries += ["zstd"] + +-ffi = cffi.FFI() +-# *_DISABLE_DEPRECATE_WARNINGS prevents the compiler from emitting a warning +-# when cffi uses the function. Since we statically link against zstd, even +-# if we use the deprecated functions it shouldn't be a huge problem. +-ffi.set_source( +- "zstandard._cffi", +- """ ++ # Locate headers using the preprocessor. ++ include_re = re.compile(r'^# \d+ "([^"]+/(?:zstd_errors|zstd|zdict)\.h)"') ++ with tempfile.TemporaryDirectory() as temp_dir: ++ with open(os.path.join(temp_dir, "input.h"), "w") as f: ++ f.write(""" ++#include ++#include ++#include ++""") ++ compiler.preprocess(os.path.join(temp_dir, "input.h"), ++ os.path.join(temp_dir, "output.h")) ++ with open(os.path.join(temp_dir, "output.h"), "r") as f: ++ discovered_headers = { ++ os.path.basename(m.group(1)): m.group(1) ++ for m in map(include_re.match, f) ++ if m is not None ++ } ++ headers = [ ++ discovered_headers[name] ++ for name in ("zstd_errors.h", "zstd.h", "zdict.h") ++ ] ++ ++ # musl 1.1 doesn't define qsort_r. We need to force using the C90 ++ # variant. ++ define_macros = [] ++ for tag in packaging.tags.platform_tags(): ++ if tag.startswith("musllinux_1_1_"): ++ define_macros.append(("ZDICT_QSORT", "ZDICT_QSORT_C90")) ++ ++ ++ ffi = cffi.FFI() ++ # *_DISABLE_DEPRECATE_WARNINGS prevents the compiler from emitting a warning ++ # when cffi uses the function. Since we statically link against zstd, even ++ # if we use the deprecated functions it shouldn't be a huge problem. ++ ffi.set_source( ++ "zstandard._cffi", ++ """ + #define ZSTD_STATIC_LINKING_ONLY + #define ZSTD_DISABLE_DEPRECATE_WARNINGS + #include +@@ -191,48 +221,51 @@ + #define ZDICT_DISABLE_DEPRECATE_WARNINGS + #include + """, +- sources=SOURCES, +- include_dirs=INCLUDE_DIRS, +- define_macros=define_macros, +-) +- +-DEFINE = re.compile(rb"^#define\s+([a-zA-Z0-9_]+)\s+(\S+)") +- +-sources = [] +- +-# Feed normalized preprocessor output for headers into the cdef parser. +-for header in HEADERS: +- preprocessed = preprocess(header) +- sources.append(normalize_output(preprocessed)) +- +- # #define's are effectively erased as part of going through preprocessor. +- # So perform a manual pass to re-add those to the cdef source. +- with open(header, "rb") as fh: +- for line in fh: +- line = line.strip() +- m = DEFINE.match(line) +- if not m: +- continue ++ sources=zstd_sources, ++ include_dirs=include_dirs, ++ define_macros=define_macros, ++ libraries=libraries, ++ ) + +- if m.group(1) == b"ZSTD_STATIC_LINKING_ONLY": +- continue ++ define = re.compile(rb"^#define\s+([a-zA-Z0-9_]+)\s+(\S+)") + +- # The parser doesn't like some constants with complex values. +- if m.group(1) in (b"ZSTD_LIB_VERSION", b"ZSTD_VERSION_STRING"): +- continue ++ sources = [] + +- # These defines create aliases from old (camelCase) type names +- # to the new PascalCase names, which breaks CFFI. +- if m.group(1).lower() == m.group(2).lower(): +- continue ++ # Feed normalized preprocessor output for headers into the cdef parser. ++ for header in headers: ++ preprocessed = preprocess(header) ++ sources.append(normalize_output(preprocessed)) ++ ++ # #define's are effectively erased as part of going through preprocessor. ++ # So perform a manual pass to re-add those to the cdef source. ++ with open(header, "rb") as fh: ++ for line in fh: ++ line = line.strip() ++ m = define.match(line) ++ if not m: ++ continue ++ ++ if m.group(1) == b"ZSTD_STATIC_LINKING_ONLY": ++ continue ++ ++ # The parser doesn't like some constants with complex values. ++ if m.group(1) in (b"ZSTD_LIB_VERSION", b"ZSTD_VERSION_STRING"): ++ continue ++ ++ # These defines create aliases from old (camelCase) type names ++ # to the new PascalCase names, which breaks CFFI. ++ if m.group(1).lower() == m.group(2).lower(): ++ continue ++ ++ # The ... is magic syntax by the cdef parser to resolve the ++ # value at compile time. ++ sources.append(b"#define " + m.group(1) + b" ...") ++ ++ cdeflines = b"\n".join(sources).splitlines() ++ cdeflines = [line for line in cdeflines if line.strip()] ++ ffi.cdef(b"\n".join(cdeflines).decode("latin1")) ++ return ffi + +- # The ... is magic syntax by the cdef parser to resolve the +- # value at compile time. +- sources.append(b"#define " + m.group(1) + b" ...") +- +-cdeflines = b"\n".join(sources).splitlines() +-cdeflines = [line for line in cdeflines if line.strip()] +-ffi.cdef(b"\n".join(cdeflines).decode("latin1")) + + if __name__ == "__main__": +- ffi.compile() ++ get_ffi().compile() diff --git a/archivers/py-zstandard/patches/patch-setup.py b/archivers/py-zstandard/patches/patch-setup.py new file mode 100644 index 000000000000..cef5bff6d290 --- /dev/null +++ b/archivers/py-zstandard/patches/patch-setup.py @@ -0,0 +1,39 @@ +$NetBSD$ + +Support building the CFFI backend against the system zstd library, +enabled with a separate --system-zstd-cffi switch. + +From Michal Gorny (Gentoo) and Boyuan Yang (Debian), as carried in +Debian's python-zstandard 0.25.0-2 (patches 0002 to 0005). +https://github.com/indygreg/python-zstandard/pull/249 + +--- setup.py.orig 2025-09-14 20:35:55.000000000 +0000 ++++ setup.py +@@ -73,6 +73,7 @@ + + SUPPORT_LEGACY = False + SYSTEM_ZSTD = False ++SYSTEM_ZSTD_CFFI = False + WARNINGS_AS_ERRORS = False + C_BACKEND = True + CFFI_BACKEND = True +@@ -103,6 +104,10 @@ + SYSTEM_ZSTD = True + sys.argv.remove("--system-zstd") + ++if "--system-zstd-cffi" in sys.argv: ++ SYSTEM_ZSTD_CFFI = True ++ sys.argv.remove("--system-zstd-cffi") ++ + if "--warnings-as-errors" in sys.argv: + WARNINGS_AS_ERRORS = True + sys.argv.remove("--warning-as-errors") +@@ -138,7 +143,7 @@ + if CFFI_BACKEND and cffi: + import make_cffi + +- extensions.append(make_cffi.ffi.distutils_extension()) ++ extensions.append(make_cffi.get_ffi(system_zstd=SYSTEM_ZSTD_CFFI).distutils_extension()) + + version = None + diff --git a/mk/defaults/options.description b/mk/defaults/options.description index 5d38361df45e..9d6e0bc7552b 100644 --- a/mk/defaults/options.description +++ b/mk/defaults/options.description @@ -1131,6 +1131,7 @@ zlib-ng Enable support for zlib-ng compression with SIMD optimizations. zoom Plays Infocom-compatible games, with graphics support. zrtp Enable ZRTP support. zsh-multibyte Enable multibyte support in Zsh. +zstandard-bundled-zstd Use zstd bundled with py-zstandard instead of pkgsrc zstd. zstd Enable Zstandard (de)compression support. zts Enable the Zend Thread Safety option for PHP. zziplib Enable zip support using zziplib.