Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Add libavif build #193

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
if: "!startsWith(github.ref, 'refs/tags/')"
uses: ./.github/workflows/wheels-macos.yml
with:
build-commit: "main"
build-commit: "master"
artifacts-name: "wheels-latest"

linux-latest:
if: "!startsWith(github.ref, 'refs/tags/')"
uses: ./.github/workflows/wheels-linux.yml
with:
build-commit: "main"
build-commit: "master"
artifacts-name: "wheels-latest"

release:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "Pillow"]
path = Pillow
url = https://github.com/python-Pillow/Pillow.git
url = https://github.com/fdintino/Pillow.git
[submodule "multibuild"]
path = multibuild
url = https://github.com/multi-build/multibuild.git
2 changes: 1 addition & 1 deletion Pillow
Submodule Pillow updated 512 files
16 changes: 11 additions & 5 deletions config.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Define custom utilities
# Test for macOS with [ -n "$IS_MACOS" ]

ARCHIVE_SDIR=pillow-depends-main
ARCHIVE_SDIR=pillow-depends-master
PILLOW_WHEELS_DIR=$(abspath $(dirname "$CONFIG_PATH"))

source $PILLOW_WHEELS_DIR/config_libavif.sh

# Package versions for fresh source builds
FREETYPE_VERSION=2.12.1
Expand Down Expand Up @@ -52,8 +55,8 @@ function build_brotli {
function pre_build {
# Any stuff that you need to do before you start building the wheels
# Runs in the root directory of this repository.
curl -fsSL -o pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
untar pillow-depends-main.zip
curl -fsSL -o pillow-depends-master.zip https://github.com/fdintino/pillow-depends/archive/master.zip
untar pillow-depends-master.zip

build_xz
if [ -z "$IS_ALPINE" ] && [ -z "$IS_MACOS" ]; then
Expand Down Expand Up @@ -119,6 +122,9 @@ function pre_build {
export FREETYPE_CFLAGS=''
fi

# defined in config_libavif.sh
build_libavif

# Append licenses
for filename in dependency_licenses/*; do
echo -e "\n\n----\n\n$(basename $filename | cut -f 1 -d '.')\n" | cat >> Pillow/LICENSE
Expand All @@ -145,7 +151,7 @@ function run_tests_in_repo {

EXP_CODECS="jpg jpg_2000 libtiff zlib"
EXP_MODULES="freetype2 littlecms2 pil tkinter webp"
EXP_FEATURES="fribidi harfbuzz libjpeg_turbo raqm transp_webp webp_anim webp_mux xcb"
EXP_FEATURES="avif fribidi harfbuzz libjpeg_turbo raqm transp_webp webp_anim webp_mux xcb"

function run_tests {
if [ -n "$IS_MACOS" ]; then
Expand All @@ -163,7 +169,7 @@ function run_tests {
python3 -m pip install numpy
fi

mv ../pillow-depends-main/test_images/* ../Pillow/Tests/images
mv ../pillow-depends-master/test_images/* ../Pillow/Tests/images

# Runs tests on installed distribution from an empty directory
(cd ../Pillow && run_tests_in_repo)
Expand Down
293 changes: 293 additions & 0 deletions config_libavif.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
set -e

PILLOW_WHEELS_DIR=$(abspath $(dirname "$CONFIG_PATH"))

LIBAVIF_VERSION=0.9.0
CARGO_C_VERSION=0.8.0
AOM_VERSION=2.0.2
DAV1D_VERSION=0.8.2
SVT_AV1_VERSION=0.8.6
RAV1E_VERSION=0.4.0

function install_nasm {
if [ -e nasm-stamp ]; then return; fi

echo "::group::Build nasm"
if [ -n "$IS_MACOS" ]; then
brew install nasm
else
build_simple nasm 2.15.05 https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/
fi
echo "::endgroup::"

touch nasm-stamp
}

function install_meson {
if [ -e meson-stamp ]; then return; fi

echo "::group::Install meson"
$PYTHON_EXE -m pip install meson
echo "::endgroup::"

touch meson-stamp
}

function install_ninja {
if [ -e ninja-stamp ]; then return; fi

echo "::group::Install ninja"
$PYTHON_EXE -m pip install ninja
local ninja_exe=$(dirname $PYTHON_EXE)/ninja
ln -s $ninja_exe /usr/local/bin/ninja-build
echo "::endgroup::"

touch ninja-stamp
}

function install_rust {
if [ -e rust-stamp ]; then return; fi

echo "::group::Install rust"
if [ -n "$IS_MACOS" ]; then
brew install rust
else
if [[ "$MB_ML_VER" == "1" ]]; then
# Download and use old rustup-init that's compatible with glibc on el5
curl -sLO https://static.rust-lang.org/rustup/archive/1.22.1/$PLAT-unknown-linux-gnu/rustup-init
chmod u+x rustup-init
./rustup-init --default-toolchain nightly-2020-07-18 -y
else
curl https://sh.rustup.rs -sSf | /bin/sh -s -- -y
fi
fi
if [ -e $HOME/.cargo/env ]; then
source $HOME/.cargo/env
fi
echo "::endgroup::"

touch rust-stamp
}

function install_more_modern_cmake {
# install_modern_cmake installs cmake 2.8, but some libavif dependencies
# require a higher version
if [ -e cmake-more-modern ]; then return; fi

echo "::group::Install cmake"
if [ -n "$IS_MACOS" ]; then
brew install cmake
else
$PYTHON_EXE -m pip install cmake
fi
echo "::endgroup::"

touch cmake-more-modern
}

function install_cargo_c {
install_rust

if which cargo-cbuild 1>/dev/null 2>/dev/null; then return; fi

echo "::group::Install cargo-c"
if [ -n "$IS_MACOS" ]; then
brew install cargo-c
else
mkdir -p $HOME/.cargo/bin
(cd $HOME/.cargo/bin \
&& fetch_unpack \
https://github.com/lu-zero/cargo-c/releases/download/v$CARGO_C_VERSION/cargo-c-linux.tar.gz \
cargo-c-$CARGO_C_VERSION-linux.tar.gz)
fi
echo "::endgroup::"
}

function build_aom {
if [ -e aom-stamp ]; then return; fi

if [ ! -n "$IS_MACOS" ]; then
install_more_modern_cmake
install_nasm
fi

echo "::group::Build aom"

if [ -n "$IS_MACOS" ]; then
brew install aom
else
(rm_mkdir aom-$AOM_VERSION \
&& cd aom-$AOM_VERSION \
&& fetch_unpack \
https://storage.googleapis.com/aom-releases/libaom-$AOM_VERSION.tar.gz)

if [[ "$MB_ML_VER" == "1" ]]; then
(cd aom-$AOM_VERSION \
&& patch -p1 < $PILLOW_WHEELS_DIR/patches/aom-2.0.2-manylinux1.patch)
fi
mkdir aom-$AOM_VERSION/build/linux
(cd aom-$AOM_VERSION/build/linux \
&& cmake \
-DCMAKE_C_FLAGS=-fPIC \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${BUILD_PREFIX}" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DBUILD_SHARED_LIBS=0 \
-DENABLE_DOCS=0 \
-DENABLE_EXAMPLES=0 \
-DENABLE_TESTDATA=0 \
-DENABLE_TESTS=0 \
-DENABLE_TOOLS=0 \
../.. \
&& make install)
fi
echo "::endgroup::"

touch aom-stamp
}

function build_dav1d {
if [ -e dav1d-stamp ]; then return; fi

install_meson
install_ninja
install_nasm

echo "::group::Build dav1d"
fetch_unpack "https://code.videolan.org/videolan/dav1d/-/archive/$DAV1D_VERSION/dav1d-$DAV1D_VERSION.tar.gz"
(cd dav1d-$DAV1D_VERSION \
&& meson . build \
"--prefix=${BUILD_PREFIX}" \
--default-library=static \
--buildtype=release \
&& ninja -vC build install)
echo "::endgroup::"

touch dav1d-stamp
}

function build_svt_av1 {
if [ -e svt-av1-stamp ]; then return; fi

echo "::group::Build SVT-AV1"

install_nasm
install_more_modern_cmake

fetch_unpack \
"https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v$SVT_AV1_VERSION/SVT-AV1-v$SVT_AV1_VERSION.tar.gz"

(cd SVT-AV1-v$SVT_AV1_VERSION/Build/linux \
&& cmake \
../.. \
-DCMAKE_INSTALL_PREFIX="${BUILD_PREFIX}" \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
&& make install \
&& cp SvtAv1Enc.pc $BUILD_PREFIX/lib/pkgconfig)

echo "::endgroup::"

touch svt-av1-stamp
}

function build_rav1e {
if [ -e rav1e-stamp ]; then return; fi

install_cargo_c
install_nasm

echo "::group::Build rav1e"

CARGO_VENDOR_TGZ=$ARCHIVE_SDIR/rav1e-vendor-$RAV1E_VERSION.tar.gz
if [ -e $CARGO_VENDOR_TGZ ]; then
mkdir -p "$HOME/.cargo"
tar -C $ARCHIVE_SDIR -zxf $CARGO_VENDOR_TGZ
VENDOR_DIR=$(pwd -P)/$ARCHIVE_SDIR/vendor
cat > ~/.cargo/config <<EOF
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "$VENDOR_DIR"
EOF
fi

fetch_unpack \
"https://github.com/xiph/rav1e/archive/v$RAV1E_VERSION.tar.gz" \
"rav1e-$RAV1E_VERSION.tar.gz"

# Strip rust version check
perl -p0i -e 's/(?<=fn rustc_version_check\(\) {).*?(?=\n}\n)//ms' \
rav1e-$RAV1E_VERSION/build.rs

(cd rav1e-$RAV1E_VERSION \
&& cargo cinstall --release --library-type=staticlib "--prefix=$BUILD_PREFIX")

if [ ! -n "$IS_MACOS" ]; then
sed -i 's/-lgcc_s/-lgcc_eh/g' "${BUILD_PREFIX}/lib/pkgconfig/rav1e.pc"
fi

echo "::endgroup::"

touch rav1e-stamp
}

function build_libavif {
if [ -e libavif-stamp ]; then return; fi

echo "::endgroup::"

LIBAVIF_CMAKE_FLAGS=()

build_aom
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_AOM=ON)

build_dav1d
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_DAV1D=ON)

if [ "$PLAT" != "i686" ]; then
if [ -n "$IS_MACOS" ]; then
build_svt_av1
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_SVT=ON)
elif [[ "$MB_ML_VER" != "1" ]]; then
LDFLAGS=-lrt build_svt_av1
LIBAVIF_CMAKE_FLAGS+=(-DCMAKE_EXE_LINKER_FLAGS=-lrt)
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_SVT=ON)
fi
fi

if [[ "$PLAT" != "i686" ]]; then
build_rav1e
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_CODEC_RAV1E=ON)
fi

if [ -n "$IS_MACOS" ]; then
# Prevent cmake from using @rpath in install id, so that delocate can
# find and bundle the libavif dylib
LIBAVIF_CMAKE_FLAGS+=(\
"-DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib" \
-DCMAKE_MACOSX_RPATH=OFF)
fi

echo "::group::Build libavif"

fetch_unpack \
"https://github.com/AOMediaCodec/libavif/archive/v$LIBAVIF_VERSION.tar.gz" \
"libavif-$LIBAVIF_VERSION.tar.gz"

mkdir -p libavif-$LIBAVIF_VERSION/build

(cd libavif-$LIBAVIF_VERSION/build \
&& cmake .. \
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_LIBDIR=lib \
"${LIBAVIF_CMAKE_FLAGS[@]}" \
&& make install)

echo "::endgroup::"

touch libavif-stamp
}
26 changes: 26 additions & 0 deletions dependency_licenses/AOM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2016, Alliance for Open Media. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Loading