From d708b9ce81e74f647f71686be2f1e7cc9dfadef1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:51:09 +0200 Subject: [PATCH] Statically link zlib-ng in Linux wheels --- .github/workflows/wheels-dependencies.sh | 13 ++++++++++++- checks/check_wheel.py | 11 +++++++++++ docs/releasenotes/13.1.0.rst | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index c18eefa9af5..ac12ee04205 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -144,7 +144,18 @@ function build_zlib_ng { ORIGINAL_HOST_CONFIGURE_FLAGS=$HOST_CONFIGURE_FLAGS unset HOST_CONFIGURE_FLAGS - build_github zlib-ng/zlib-ng $ZLIB_NG_VERSION --installnamedir=$BUILD_PREFIX/lib --zlib-compat + if [[ -n "$IS_MACOS" ]]; then + build_github zlib-ng/zlib-ng $ZLIB_NG_VERSION --installnamedir=$BUILD_PREFIX/lib --zlib-compat + else + # auditwheel does not bundle libz.so.1, so link zlib-ng statically, + # with hidden symbols so a system zlib cannot take its place. + CFLAGS="$CFLAGS -fPIC -fvisibility=hidden" build_github zlib-ng/zlib-ng $ZLIB_NG_VERSION --static --zlib-compat + # The shared install used to run ldconfig, which later steps rely on + # to find libraries in /usr/local/lib. musl has no cache. + if [[ -z "$IS_ALPINE" ]]; then + ldconfig + fi + fi HOST_CONFIGURE_FLAGS=$ORIGINAL_HOST_CONFIGURE_FLAGS touch zlib-stamp diff --git a/checks/check_wheel.py b/checks/check_wheel.py index f716c8498bb..d54cd0a7dfd 100644 --- a/checks/check_wheel.py +++ b/checks/check_wheel.py @@ -3,6 +3,8 @@ import platform import sys +import pytest + from PIL import features @@ -35,6 +37,15 @@ def test_wheel_codecs() -> None: assert set(features.get_supported_codecs()) == expected_codecs +@pytest.mark.skipif(sys.platform != "linux", reason="Linux-only check") +def test_wheel_zlib_ng_linked_statically() -> None: + # The Linux wheels link zlib-ng statically, so the version at runtime + # should be from zlib-ng, whichever zlib the system has + version = features.version_codec("zlib") + assert version is not None + assert version.endswith(".zlib-ng") + + def test_wheel_features() -> None: expected_features = { "raqm", diff --git a/docs/releasenotes/13.1.0.rst b/docs/releasenotes/13.1.0.rst index ac205efb91b..02412d8d333 100644 --- a/docs/releasenotes/13.1.0.rst +++ b/docs/releasenotes/13.1.0.rst @@ -121,3 +121,13 @@ WebP encoding errors now include a description When libwebp fails to encode an image, the raised :py:exc:`ValueError` now consistently describes the error rather than only reporting a numeric code. + +zlib-ng in Linux wheels +^^^^^^^^^^^^^^^^^^^^^^^ + +The Linux wheels now link zlib-ng statically. Previously, zlib-ng was built but +not bundled into the wheels, so the system zlib was used at runtime instead, and +``PIL.features.version_feature("zlib_ng")`` reported a version that was not in use. +Pillow 13.0.0 also failed to import on systems where ``libz.so.1`` was not on the +default library search path, such as NixOS. Linux wheels no longer require a +system zlib, and gain the speed of zlib-ng as macOS and Windows wheels already did.