From 4c8af04c6a94d4ce537ca1eeb9a840a89920700b Mon Sep 17 00:00:00 2001
From: Andrew Murray <radarhere@users.noreply.github.com>
Date: Wed, 20 Nov 2024 19:35:32 +1100
Subject: [PATCH] Use zlib-ng on Linux

---
 .github/workflows/wheels-dependencies.sh | 20 +++++++++++++++++---
 Tests/check_wheel.py                     |  2 +-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh
index f86099af16e..76256373f08 100755
--- a/.github/workflows/wheels-dependencies.sh
+++ b/.github/workflows/wheels-dependencies.sh
@@ -50,10 +50,10 @@ if [[ -n "$IS_MACOS" ]]; then
 else
     GIFLIB_VERSION=5.2.1
 fi
-if [[ -n "$IS_MACOS" ]] || [[ "$MB_ML_VER" != 2014 ]]; then
+if [[ -n "$IS_MACOS" ]]; then
     ZLIB_VERSION=1.3.1
 else
-    ZLIB_VERSION=1.2.8
+    ZLIB_NG_VERSION=2.2.2
 fi
 LIBWEBP_VERSION=1.4.0
 BZIP2_VERSION=1.0.8
@@ -74,6 +74,16 @@ function build_pkg_config {
     touch pkg-config-stamp
 }
 
+function build_zlib_ng {
+    if [ -e zlib-stamp ]; then return; fi
+    fetch_unpack https://github.com/zlib-ng/zlib-ng/archive/$ZLIB_NG_VERSION.tar.gz zlib-ng-$ZLIB_NG_VERSION.tar.gz
+    (cd zlib-ng-$ZLIB_NG_VERSION \
+        && ./configure --prefix=$BUILD_PREFIX \
+        && make -j4 \
+        && make install)
+    touch zlib-stamp
+}
+
 function build_brotli {
     if [ -e brotli-stamp ]; then return; fi
     local cmake=$(get_modern_cmake)
@@ -101,7 +111,11 @@ function build {
     if [ -z "$IS_ALPINE" ] && [ -z "$IS_MACOS" ]; then
         yum remove -y zlib-devel
     fi
-    build_new_zlib
+    if [ -n "$IS_MACOS" ]; then
+        build_new_zlib
+    else
+        build_zlib_ng
+    fi
 
     build_simple xcb-proto 1.17.0 https://xorg.freedesktop.org/archive/individual/proto
     if [ -n "$IS_MACOS" ]; then
diff --git a/Tests/check_wheel.py b/Tests/check_wheel.py
index 374e48e8ad3..b5409286251 100644
--- a/Tests/check_wheel.py
+++ b/Tests/check_wheel.py
@@ -40,7 +40,7 @@ def test_wheel_features() -> None:
 
     if sys.platform == "win32":
         expected_features.remove("xcb")
-    else:
+    elif sys.paltform != "darwin":
         expected_features.remove("zlib_ng")
 
     assert set(features.get_supported_features()) == expected_features