Link static libtiff dependencies - #9635
Open
hholst80 wants to merge 9 commits into
Open
Conversation
Author
|
Validated that it does not mess up a so Ubuntu 24.04 normy build: docker run --rm -v /tmp/repro:/src -w /src ubuntu:24.04 bash -lc '
set -eux
rm -rf build src/pillow.egg-info
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential python3-dev python3-venv python3-pip pkg-config libtiff-dev libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev libopenjp2-7-dev libimagequant-dev libraqm-dev libxcb1-dev binutils file ca-certificates
python3 -m venv /tmp/pillow-pr9635-venv
/tmp/pillow-pr9635-venv/bin/python -m pip install -U pip setuptools wheel pybind11
MAX_CONCURRENCY=2 /tmp/pillow-pr9635-venv/bin/python -m pip install -v --no-build-isolation --no-cache-dir .
so=$(/tmp/pillow-pr9635-venv/bin/python -c "import PIL._imaging, pathlib; print(pathlib.Path(PIL._imaging.__file__))")
printf "SO=%s\n" "$so"
/tmp/pillow-pr9635-venv/bin/python -c "from PIL import features; import PIL, pathlib; print(\"Pillow\", PIL.__version__); print(\"libtiff feature\", features.check(\"libtiff\")); print(\"libtiff version\", features.version(\"libtiff\")); print(\"PIL package\", pathlib.Path(PIL.__file__).parent)"
file "$so"
readelf -d "$so" | egrep "NEEDED|RPATH|RUNPATH" || true
ldd "$so" | egrep "tiff|jpeg|z|lzma|zstd|webp|jbig|deflate|not found" || true
' |
hholst80
marked this pull request as ready for review
May 21, 2026 15:46
radarhere
reviewed
May 25, 2026
Author
|
@radarhere who can help pull this over the finish line? are you able to merge it with main/master? |
Member
|
Did you have any thoughts on our conversation in #9615? |
Author
|
I've fixed the test image below so it reproduces my original failure exactly. The changes versus the version I posted in #9615:
FROM alpine:latest AS builder
RUN apk add --no-cache \
build-base pkgconf zlib-dev zstd-dev xz-dev curl
ENV TIFF_VERSION=4.7.1
RUN curl -fsSL "https://download.osgeo.org/libtiff/tiff-${TIFF_VERSION}.tar.gz" \
| tar xz -C /tmp && mv /tmp/tiff-* /tmp/libtiff
WORKDIR /tmp/libtiff
RUN mkdir -p _build && cd _build \
&& ../configure \
--prefix=/usr/local \
--disable-shared --enable-static --with-pic \
--disable-docs --disable-tools --disable-tests \
--disable-contrib --disable-libdeflate \
--disable-lerc --disable-jbig --disable-cxx \
--disable-webp --disable-lzma \
&& make -j"$(nproc)" && make install
FROM alpine:latest
RUN apk add --no-cache \
pkgconf build-base python3-dev py3-pip linux-headers binutils \
zlib-dev zstd-dev xz-dev libjpeg-turbo-dev
COPY --from=builder /usr/local/lib/libtiff.a /usr/local/lib/
COPY --from=builder /usr/local/include/ /usr/local/include/
COPY --from=builder /usr/local/lib/pkgconfig/ /usr/local/lib/pkgconfig/
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
WORKDIR /src
COPY . /src
RUN python3 -m venv /venv \
&& /venv/bin/pip install --no-cache-dir pybind11 setuptools wheel \
&& (/venv/bin/pip install --no-build-isolation . > /build.log 2>&1 || true)
CMD ["/venv/bin/python", "-c", "import PIL._imaging; print('IMPORT_OK')"]On this PR this works. Build and import should print |
Member
Bear with me if this is a silly question, but is this necessary? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This updates the Pillow source build to include libtiff's pkg-config static link dependencies when the detected TIFF library is an archive.
For dynamic libtiff builds, behavior is unchanged. For static-only libtiff builds, Pillow now reads
pkg-config --libs --staticfor the libtiff module that resolvedTIFF_ROOT, adds its-Ldirectories, appends private-ldependencies after-ltiff, and passes through other linker flags such as-pthread.Why
On systems with
/usr/lib/libtiff.abut nolibtiff.so, Pillow previously linkedPIL._imagingwith-ltiff -ljpeg -lzonly. The build succeeded, but importingPIL._imagingfailed with unresolved libtiff private dependency symbols such asZSTD_compressStream.Addresses #9615.
Validation
Reproduced before the fix on a host with:
/usr/lib/libtiff.alibtiff.so*pkg-config --libs libtiff-4->-ltiffpkg-config --libs --static libtiff-4->-ltiff -lzstd -lm -lzstd -llzma -pthread -lpthread -ljpeg -lzAfter the fix:
MAX_CONCURRENCY=1 python -m pip install -v --no-build-isolation -C tiff=enable .python -c "import PIL._imaging"python selftest.py-> 59 tests passed