|
| 1 | +#!/bin/bash |
| 2 | +# Define custom utilities |
| 3 | +# Test for macOS with [ -n "$IS_MACOS" ] |
| 4 | +if [ -z "$IS_MACOS" ]; then |
| 5 | + export MB_ML_LIBC=${AUDITWHEEL_POLICY::9} |
| 6 | + export MB_ML_VER=${AUDITWHEEL_POLICY:9} |
| 7 | +fi |
| 8 | +export PLAT=$CIBW_ARCHS |
| 9 | +source wheels/multibuild/common_utils.sh |
| 10 | +source wheels/multibuild/library_builders.sh |
| 11 | +if [ -z "$IS_MACOS" ]; then |
| 12 | + source wheels/multibuild/manylinux_utils.sh |
| 13 | +fi |
| 14 | + |
| 15 | +ARCHIVE_SDIR=pillow-depends-main |
| 16 | + |
| 17 | +# Package versions for fresh source builds |
| 18 | +FREETYPE_VERSION=2.13.2 |
| 19 | +HARFBUZZ_VERSION=8.2.1 |
| 20 | +LIBPNG_VERSION=1.6.40 |
| 21 | +JPEGTURBO_VERSION=3.0.1 |
| 22 | +OPENJPEG_VERSION=2.5.0 |
| 23 | +XZ_VERSION=5.4.5 |
| 24 | +TIFF_VERSION=4.6.0 |
| 25 | +LCMS2_VERSION=2.15 |
| 26 | +if [[ -n "$IS_MACOS" ]]; then |
| 27 | + GIFLIB_VERSION=5.1.4 |
| 28 | +else |
| 29 | + GIFLIB_VERSION=5.2.1 |
| 30 | +fi |
| 31 | +if [[ -n "$IS_MACOS" ]] || [[ "$MB_ML_VER" != 2014 ]]; then |
| 32 | + ZLIB_VERSION=1.3 |
| 33 | +else |
| 34 | + ZLIB_VERSION=1.2.8 |
| 35 | +fi |
| 36 | +LIBWEBP_VERSION=1.3.2 |
| 37 | +BZIP2_VERSION=1.0.8 |
| 38 | +LIBXCB_VERSION=1.16 |
| 39 | +BROTLI_VERSION=1.1.0 |
| 40 | + |
| 41 | +if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "x86_64" ]]; then |
| 42 | + function build_openjpeg { |
| 43 | + local out_dir=$(fetch_unpack https://github.com/uclouvain/openjpeg/archive/v${OPENJPEG_VERSION}.tar.gz openjpeg-2.5.0.tar.gz) |
| 44 | + (cd $out_dir \ |
| 45 | + && cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \ |
| 46 | + && make install) |
| 47 | + touch openjpeg-stamp |
| 48 | + } |
| 49 | +fi |
| 50 | + |
| 51 | +function build_brotli { |
| 52 | + local cmake=$(get_modern_cmake) |
| 53 | + local out_dir=$(fetch_unpack https://github.com/google/brotli/archive/v$BROTLI_VERSION.tar.gz brotli-1.1.0.tar.gz) |
| 54 | + (cd $out_dir \ |
| 55 | + && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib . \ |
| 56 | + && make install) |
| 57 | + if [[ "$MB_ML_LIBC" == "manylinux" ]]; then |
| 58 | + cp /usr/local/lib64/libbrotli* /usr/local/lib |
| 59 | + cp /usr/local/lib64/pkgconfig/libbrotli* /usr/local/lib/pkgconfig |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +function build { |
| 64 | + if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "arm64" ]]; then |
| 65 | + export BUILD_PREFIX="/usr/local" |
| 66 | + fi |
| 67 | + build_xz |
| 68 | + if [ -z "$IS_ALPINE" ] && [ -z "$IS_MACOS" ]; then |
| 69 | + yum remove -y zlib-devel |
| 70 | + fi |
| 71 | + build_new_zlib |
| 72 | + |
| 73 | + build_simple xcb-proto 1.16.0 https://xorg.freedesktop.org/archive/individual/proto |
| 74 | + if [ -n "$IS_MACOS" ]; then |
| 75 | + if [[ "$CIBW_ARCHS" == "arm64" ]]; then |
| 76 | + build_simple xorgproto 2023.2 https://www.x.org/pub/individual/proto |
| 77 | + build_simple libXau 1.0.11 https://www.x.org/pub/individual/lib |
| 78 | + build_simple libpthread-stubs 0.5 https://xcb.freedesktop.org/dist |
| 79 | + if [ -f /Library/Frameworks/Python.framework/Versions/Current/share/pkgconfig/xcb-proto.pc ]; then |
| 80 | + cp /Library/Frameworks/Python.framework/Versions/Current/share/pkgconfig/xcb-proto.pc /Library/Frameworks/Python.framework/Versions/Current/lib/pkgconfig/xcb-proto.pc |
| 81 | + fi |
| 82 | + fi |
| 83 | + else |
| 84 | + sed s/\${pc_sysrootdir\}// /usr/local/share/pkgconfig/xcb-proto.pc > /usr/local/lib/pkgconfig/xcb-proto.pc |
| 85 | + fi |
| 86 | + build_simple libxcb $LIBXCB_VERSION https://www.x.org/releases/individual/lib |
| 87 | + |
| 88 | + build_libjpeg_turbo |
| 89 | + build_tiff |
| 90 | + build_libpng |
| 91 | + build_lcms2 |
| 92 | + if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "arm64" ]]; then |
| 93 | + for dylib in libjpeg.dylib libtiff.dylib liblcms2.dylib; do |
| 94 | + cp $BUILD_PREFIX/lib/$dylib /opt/arm64-builds/lib |
| 95 | + done |
| 96 | + fi |
| 97 | + build_openjpeg |
| 98 | + |
| 99 | + ORIGINAL_CFLAGS=$CFLAGS |
| 100 | + CFLAGS="$CFLAGS -O3 -DNDEBUG" |
| 101 | + if [[ -n "$IS_MACOS" ]]; then |
| 102 | + CFLAGS="$CFLAGS -Wl,-headerpad_max_install_names" |
| 103 | + fi |
| 104 | + build_libwebp |
| 105 | + CFLAGS=$ORIGINAL_CFLAGS |
| 106 | + |
| 107 | + build_brotli |
| 108 | + |
| 109 | + if [ -n "$IS_MACOS" ]; then |
| 110 | + # Custom freetype build |
| 111 | + build_simple freetype $FREETYPE_VERSION https://download.savannah.gnu.org/releases/freetype tar.gz --with-harfbuzz=no |
| 112 | + else |
| 113 | + build_freetype |
| 114 | + fi |
| 115 | + |
| 116 | + if [ -z "$IS_MACOS" ]; then |
| 117 | + export FREETYPE_LIBS=-lfreetype |
| 118 | + export FREETYPE_CFLAGS=-I/usr/local/include/freetype2/ |
| 119 | + fi |
| 120 | + build_simple harfbuzz $HARFBUZZ_VERSION https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION tar.xz --with-freetype=yes --with-glib=no |
| 121 | + if [ -z "$IS_MACOS" ]; then |
| 122 | + export FREETYPE_LIBS="" |
| 123 | + export FREETYPE_CFLAGS="" |
| 124 | + fi |
| 125 | +} |
| 126 | + |
| 127 | +# Any stuff that you need to do before you start building the wheels |
| 128 | +# Runs in the root directory of this repository. |
| 129 | +curl -fsSL -o pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip |
| 130 | +untar pillow-depends-main.zip |
| 131 | + |
| 132 | +if [[ -n "$IS_MACOS" ]]; then |
| 133 | + # webp, libtiff, libxcb cause a conflict with building webp, libtiff, libxcb |
| 134 | + # libxdmcp causes an issue on macOS < 11 |
| 135 | + # if php is installed, brew tries to reinstall these after installing openblas |
| 136 | + # remove cairo to fix building harfbuzz on arm64 |
| 137 | + # remove lcms2 and libpng to fix building openjpeg on arm64 |
| 138 | + # remove zstd to avoid inclusion on x86_64 |
| 139 | + # curl from brew requires zstd, use system curl |
| 140 | + brew remove --ignore-dependencies webp libpng libtiff libxcb libxdmcp curl php cairo lcms2 ghostscript zstd |
| 141 | + |
| 142 | + brew install pkg-config |
| 143 | +fi |
| 144 | + |
| 145 | +wrap_wheel_builder build |
| 146 | + |
| 147 | +# Append licenses |
| 148 | +for filename in wheels/dependency_licenses/*; do |
| 149 | + echo -e "\n\n----\n\n$(basename $filename | cut -f 1 -d '.')\n" | cat >> LICENSE |
| 150 | + cat $filename >> LICENSE |
| 151 | +done |
0 commit comments