Skip to content

Commit a7338f8

Browse files
authored
Merge pull request #8500 from nulano/zlib-ng
Use zlib-ng instead of zlib
2 parents c79aab7 + 01bc487 commit a7338f8

File tree

8 files changed

+54
-22
lines changed

8 files changed

+54
-22
lines changed

.github/workflows/wheels-dependencies.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ if [[ -n "$IS_MACOS" ]]; then
5050
else
5151
GIFLIB_VERSION=5.2.1
5252
fi
53-
if [[ -n "$IS_MACOS" ]] || [[ "$MB_ML_VER" != 2014 ]]; then
54-
ZLIB_VERSION=1.3.1
55-
else
56-
ZLIB_VERSION=1.2.8
57-
fi
53+
ZLIB_NG_VERSION=2.2.2
5854
LIBWEBP_VERSION=1.4.0
5955
BZIP2_VERSION=1.0.8
6056
LIBXCB_VERSION=1.17.0
@@ -74,6 +70,16 @@ function build_pkg_config {
7470
touch pkg-config-stamp
7571
}
7672

73+
function build_zlib_ng {
74+
if [ -e zlib-stamp ]; then return; fi
75+
fetch_unpack https://github.com/zlib-ng/zlib-ng/archive/$ZLIB_NG_VERSION.tar.gz zlib-ng-$ZLIB_NG_VERSION.tar.gz
76+
(cd zlib-ng-$ZLIB_NG_VERSION \
77+
&& ./configure --prefix=$BUILD_PREFIX --zlib-compat \
78+
&& make -j4 \
79+
&& make install)
80+
touch zlib-stamp
81+
}
82+
7783
function build_brotli {
7884
if [ -e brotli-stamp ]; then return; fi
7985
local out_dir=$(fetch_unpack https://github.com/google/brotli/archive/v$BROTLI_VERSION.tar.gz brotli-$BROTLI_VERSION.tar.gz)
@@ -100,7 +106,7 @@ function build {
100106
if [ -z "$IS_ALPINE" ] && [ -z "$IS_MACOS" ]; then
101107
yum remove -y zlib-devel
102108
fi
103-
build_new_zlib
109+
build_zlib_ng
104110

105111
build_simple xcb-proto 1.17.0 https://xorg.freedesktop.org/archive/individual/proto
106112
if [ -n "$IS_MACOS" ]; then

Tests/check_wheel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_wheel_features() -> None:
3434
"fribidi",
3535
"harfbuzz",
3636
"libjpeg_turbo",
37+
"zlib_ng",
3738
"xcb",
3839
}
3940

Tests/test_features.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ def test(name: str, function: Callable[[str], str | None]) -> None:
3636
else:
3737
assert function(name) == version
3838
if name != "PIL":
39-
if name == "zlib" and version is not None:
40-
version = re.sub(".zlib-ng$", "", version)
41-
elif name == "libtiff" and version is not None:
42-
version = re.sub("t$", "", version)
39+
if version is not None:
40+
if name == "zlib" and features.check_feature("zlib_ng"):
41+
version = re.sub(".zlib-ng$", "", version)
42+
elif name == "libtiff":
43+
version = re.sub("t$", "", version)
4344
assert version is None or re.search(r"\d+(\.\d+)*$", version)
4445

4546
for module in features.modules:

docs/reference/features.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Feature version numbers are available only where stated.
5454
Support for the following features can be checked:
5555

5656
* ``libjpeg_turbo``: (compile time) Whether Pillow was compiled against the libjpeg-turbo version of libjpeg. Compile-time version number is available.
57+
* ``zlib_ng``: (compile time) Whether Pillow was compiled against the zlib-ng version of zlib. Compile-time version number is available.
5758
* ``raqm``: Raqm library, required for ``ImageFont.Layout.RAQM`` in :py:func:`PIL.ImageFont.truetype`. Run-time version number is available for Raqm 0.7.0 or newer.
5859
* ``libimagequant``: (compile time) ImageQuant quantization support in :py:func:`PIL.Image.Image.quantize`. Run-time version number is available.
5960
* ``xcb``: (compile time) Support for X11 in :py:func:`PIL.ImageGrab.grab` via the XCB library.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ test-extras = "tests"
104104

105105
[tool.cibuildwheel.macos.environment]
106106
PATH = "$(pwd)/build/deps/darwin/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
107+
DYLD_LIBRARY_PATH = "$(pwd)/build/deps/darwin/lib"
107108

108109
[tool.black]
109110
exclude = "wheels/multibuild"

src/PIL/features.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def get_supported_codecs() -> list[str]:
127127
"fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
128128
"harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
129129
"libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"),
130+
"zlib_ng": ("PIL._imaging", "HAVE_ZLIBNG", "zlib_ng_version"),
130131
"libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"),
131132
"xcb": ("PIL._imaging", "HAVE_XCB", None),
132133
}
@@ -308,7 +309,11 @@ def pilinfo(out: IO[str] | None = None, supported_formats: bool = True) -> None:
308309
# this check is also in src/_imagingcms.c:setup_module()
309310
version_static = tuple(int(x) for x in v.split(".")) < (2, 7)
310311
t = "compiled for" if version_static else "loaded"
311-
if name == "raqm":
312+
if name == "zlib":
313+
zlib_ng_version = version_feature("zlib_ng")
314+
if zlib_ng_version is not None:
315+
v += ", compiled for zlib-ng " + zlib_ng_version
316+
elif name == "raqm":
312317
for f in ("fribidi", "harfbuzz"):
313318
v2 = version_feature(f)
314319
if v2 is not None:

src/_imaging.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,6 +4397,20 @@ setup_module(PyObject *m) {
43974397
}
43984398
#endif
43994399

4400+
PyObject *have_zlibng;
4401+
#ifdef ZLIBNG_VERSION
4402+
have_zlibng = Py_True;
4403+
{
4404+
PyObject *v = PyUnicode_FromString(ZLIBNG_VERSION);
4405+
PyDict_SetItemString(d, "zlib_ng_version", v ? v : Py_None);
4406+
Py_XDECREF(v);
4407+
}
4408+
#else
4409+
have_zlibng = Py_False;
4410+
#endif
4411+
Py_INCREF(have_zlibng);
4412+
PyModule_AddObject(m, "HAVE_ZLIBNG", have_zlibng);
4413+
44004414
#ifdef HAVE_LIBTIFF
44014415
{
44024416
extern const char *ImagingTiffVersion(void);

winbuild/build_prepare.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ def cmd_msbuild(
120120
"OPENJPEG": "2.5.3",
121121
"TIFF": "4.6.0",
122122
"XZ": "5.6.3",
123-
"ZLIB": "1.3.1",
123+
"ZLIBNG": "2.2.2",
124124
}
125125
V["LIBPNG_DOTLESS"] = V["LIBPNG"].replace(".", "")
126126
V["LIBPNG_XY"] = "".join(V["LIBPNG"].split(".")[:2])
127-
V["ZLIB_DOTLESS"] = V["ZLIB"].replace(".", "")
128127

129128

130129
# dependencies, listed in order of compilation
@@ -160,18 +159,22 @@ def cmd_msbuild(
160159
"bins": ["cjpeg.exe", "djpeg.exe"],
161160
},
162161
"zlib": {
163-
"url": "https://zlib.net/FILENAME",
164-
"filename": f"zlib{V['ZLIB_DOTLESS']}.zip",
165-
"dir": f"zlib-{V['ZLIB']}",
166-
"license": "README",
167-
"license_pattern": "Copyright notice:\n\n(.+)$",
162+
"url": f"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/{V['ZLIBNG']}.zip",
163+
"filename": f"zlib-ng-{V['ZLIBNG']}.zip",
164+
"dir": f"zlib-ng-{V['ZLIBNG']}",
165+
"license": "LICENSE.md",
166+
"patch": {
167+
r"CMakeLists.txt": {
168+
"set_target_properties(zlib PROPERTIES OUTPUT_NAME zlibstatic${{SUFFIX}})": "set_target_properties(zlib PROPERTIES OUTPUT_NAME zlib)", # noqa: E501
169+
},
170+
},
168171
"build": [
169-
cmd_nmake(r"win32\Makefile.msc", "clean"),
170-
cmd_nmake(r"win32\Makefile.msc", "zlib.lib"),
171-
cmd_copy("zlib.lib", "z.lib"),
172+
*cmds_cmake(
173+
"zlib", "-DBUILD_SHARED_LIBS:BOOL=OFF", "-DZLIB_COMPAT:BOOL=ON"
174+
),
172175
],
173176
"headers": [r"z*.h"],
174-
"libs": [r"*.lib"],
177+
"libs": [r"zlib.lib"],
175178
},
176179
"xz": {
177180
"url": f"https://github.com/tukaani-project/xz/releases/download/v{V['XZ']}/FILENAME",

0 commit comments

Comments
 (0)