Pages

Friday, June 26, 2020

Build latest libvips

As mentioned in the libvips README, you can easily compile libvips if you need a newer version than is provided by your distribution. For example,
FROM ubuntu:18.04

ENV VIPS_VERSION=8.9.2
RUN set -o errexit -o nounset && \
    wget --no-verbose https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz && \
    tar -xf /vips-${VIPS_VERSION}.tar.gz && \
    rm vips-${VIPS_VERSION}.tar.gz && \
    cd vips-${VIPS_VERSION} && \
    ./configure && \
    make && \
    make install && \
    ldconfig && \
    cd .. && \
    rm --recursive vips-${VIPS_VERSION}

But if you want to save some time recompiling (or want a deb for any other reason), you can modify the packaging to use the version you compiled instead. Here's an example with Ubuntu.
# docker build -t vips-deb .
# docker run --rm -v $PWD/debs:/debs vips-deb

FROM ubuntu:18.04

RUN mkdir /debs

WORKDIR /build

RUN set -o errexit -o nounset \
    && apt-get update --yes \
    && apt-get install --no-install-recommends --no-install-suggests --yes \
        build-essential \
        ca-certificates \
        devscripts \
        equivs \
        wget \
    && rm --recursive --force /var/lib/apt/lists/*

# use the Debian version that matches the base image from https://launchpad.net/ubuntu/+source/vips
ENV DEBIAN_VIPS_VERSION=8.4.5-1build1
ENV VIPS_VERSION=8.9.2
RUN set -o errexit -o nounset \
    && wget --no-verbose https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz \
    && tar -xf vips-${VIPS_VERSION}.tar.gz \
    && rm vips-${VIPS_VERSION}.tar.gz \
    && cd vips-${VIPS_VERSION} \
    && wget --no-verbose https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/vips/${DEBIAN_VIPS_VERSION}/vips_${DEBIAN_VIPS_VERSION}.debian.tar.xz \
    && tar -xf vips_${DEBIAN_VIPS_VERSION}.debian.tar.xz \
    && rm vips_${DEBIAN_VIPS_VERSION}.debian.tar.xz \
    && cd debian \
    && EMAIL=john@example.com NAME="John Doe" dch -v ${VIPS_VERSION}-1 "Update to version ${VIPS_VERSION}" \
    && sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list \
    && apt-get update --yes \
    # don't install Python bindings (this will be supplied by pyvips)
    && sed -Ei '/Package: python-vipscc/,/^$/d' control \
    && mk-build-deps -t 'apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends' -i control \
    && debuild -i -us -uc -bCMD cp /build/*.deb /debs \
    && rm --recursive --force /var/lib/apt/lists/*

CMD cp --force /build/*.deb /debs
One thing to note, as the Pyvips README says
If you have the development headers for libvips installed and have a working C compiler, this module will use cffi API mode to try to build a libvips binary extension for your Python. If it is unable to build a binary extension, it will use cffi ABI mode instead and only needs the libvips shared library. This takes longer to start up and is typically ~20% slower in execution.
You can confirm whether it is running in ABI mode after installing libvips by running this command
echo -e 'import logging\nlogging.basicConfig(level=logging.DEBUG)\nimport pyvips' | python3
Example ABI Mode Output
DEBUG:pyvips:Binary module load failed: No module named '_libvips'
DEBUG:pyvips:Falling back to ABI mode
DEBUG:pyvips:Loaded lib <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7f6c56754978>
DEBUG:pyvips:Loaded lib <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7f6c56754860>
DEBUG:pyvips:Inited libvips
Example Non-ABI Mode Output
DEBUG:pyvips:Loaded binary module _libvips
DEBUG:pyvips:Module generated for libvips 8.9
DEBUG:pyvips:Linked to libvips 8.9
DEBUG:pyvips:Inited libvips

No comments:

Post a Comment