1
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}
2
+
3
+ # Setup that needs to be done before multibuild utils are invoked
4
+ PROJECTDIR=$( pwd)
5
+ if [[ " $( uname -s) " == " Darwin" ]]; then
6
+ # Safety check - macOS builds require that CIBW_ARCHS is set, and that it
7
+ # only contains a single value (even though cibuildwheel allows multiple
8
+ # values in CIBW_ARCHS).
9
+ if [[ -z " $CIBW_ARCHS " ]]; then
10
+ echo " ERROR: Pillow macOS builds require CIBW_ARCHS be defined."
11
+ exit 1
12
+ fi
13
+ if [[ " $CIBW_ARCHS " == * " " * ]]; then
14
+ echo " ERROR: Pillow macOS builds only support a single architecture in CIBW_ARCHS."
15
+ exit 1
16
+ fi
17
+
18
+ # Build macOS dependencies in `build/darwin`
19
+ # Install them into `build/deps/darwin`
20
+ WORKDIR=$( pwd) /build/darwin
21
+ BUILD_PREFIX=$( pwd) /build/deps/darwin
22
+ else
23
+ # Build prefix will default to /usr/local
24
+ WORKDIR=$( pwd) /build
25
+ MB_ML_LIBC=${AUDITWHEEL_POLICY:: 9}
26
+ MB_ML_VER=${AUDITWHEEL_POLICY: 9}
7
27
fi
8
- export PLAT=$CIBW_ARCHS
28
+ PLAT=$CIBW_ARCHS
29
+
30
+ # Define custom utilities
9
31
source wheels/multibuild/common_utils.sh
10
32
source wheels/multibuild/library_builders.sh
11
33
if [ -z " $IS_MACOS " ]; then
@@ -38,35 +60,43 @@ BZIP2_VERSION=1.0.8
38
60
LIBXCB_VERSION=1.17.0
39
61
BROTLI_VERSION=1.1.0
40
62
63
+ function build_pkg_config {
64
+ if [ -e pkg-config-stamp ]; then return ; fi
65
+ # This essentially duplicates the Homebrew recipe
66
+ ORIGINAL_CFLAGS=$CFLAGS
67
+ CFLAGS=" $CFLAGS -Wno-int-conversion"
68
+ build_simple pkg-config 0.29.2 https://pkg-config.freedesktop.org/releases tar.gz \
69
+ --disable-debug --disable-host-tool --with-internal-glib \
70
+ --with-pc-path=$BUILD_PREFIX /share/pkgconfig:$BUILD_PREFIX /lib/pkgconfig \
71
+ --with-system-include-path=$( xcrun --show-sdk-path --sdk macosx) /usr/include
72
+ CFLAGS=$ORIGINAL_CFLAGS
73
+ export PKG_CONFIG=$BUILD_PREFIX /bin/pkg-config
74
+ touch pkg-config-stamp
75
+ }
76
+
41
77
function build_brotli {
78
+ if [ -e brotli-stamp ]; then return ; fi
42
79
local cmake=$( get_modern_cmake)
43
80
local out_dir=$( fetch_unpack https://github.com/google/brotli/archive/v$BROTLI_VERSION .tar.gz brotli-$BROTLI_VERSION .tar.gz)
44
81
(cd $out_dir \
45
- && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX /lib . \
82
+ && $cmake -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_INSTALL_LIBDIR= $BUILD_PREFIX /lib - DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX /lib . \
46
83
&& make install)
47
- if [[ " $MB_ML_LIBC " == " manylinux" ]]; then
48
- cp /usr/local/lib64/libbrotli* /usr/local/lib
49
- cp /usr/local/lib64/pkgconfig/libbrotli* /usr/local/lib/pkgconfig
50
- fi
84
+ touch brotli-stamp
51
85
}
52
86
53
87
function build_harfbuzz {
88
+ if [ -e harfbuzz-stamp ]; then return ; fi
54
89
python3 -m pip install meson ninja
55
90
56
91
local out_dir=$( fetch_unpack https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION /$HARFBUZZ_VERSION .tar.xz harfbuzz-$HARFBUZZ_VERSION .tar.xz)
57
92
(cd $out_dir \
58
- && meson setup build --buildtype=release -Dfreetype=enabled -Dglib=disabled)
93
+ && meson setup build --prefix= $BUILD_PREFIX --libdir= $BUILD_PREFIX /lib -- buildtype=release -Dfreetype=enabled -Dglib=disabled)
59
94
(cd $out_dir /build \
60
95
&& meson install)
61
- if [[ " $MB_ML_LIBC " == " manylinux" ]]; then
62
- cp /usr/local/lib64/libharfbuzz* /usr/local/lib
63
- fi
96
+ touch harfbuzz-stamp
64
97
}
65
98
66
99
function build {
67
- if [[ -n " $IS_MACOS " ]] && [[ " $CIBW_ARCHS " == " arm64" ]]; then
68
- sudo chown -R runner /usr/local
69
- fi
70
100
build_xz
71
101
if [ -z " $IS_ALPINE " ] && [ -z " $IS_MACOS " ]; then
72
102
yum remove -y zlib-devel
@@ -78,16 +108,24 @@ function build {
78
108
build_simple xorgproto 2024.1 https://www.x.org/pub/individual/proto
79
109
build_simple libXau 1.0.11 https://www.x.org/pub/individual/lib
80
110
build_simple libpthread-stubs 0.5 https://xcb.freedesktop.org/dist
81
- if [[ " $CIBW_ARCHS " == " arm64" ]]; then
82
- cp /usr/local/share/pkgconfig/xcb-proto.pc /usr/local/lib/pkgconfig
83
- fi
84
111
else
85
- sed s/\$ {pc_sysrootdir\} // /usr/local/ share/pkgconfig/xcb-proto.pc > /usr/local /lib/pkgconfig/xcb-proto.pc
112
+ sed s/\$ {pc_sysrootdir\} // $BUILD_PREFIX / share/pkgconfig/xcb-proto.pc > $BUILD_PREFIX /lib/pkgconfig/xcb-proto.pc
86
113
fi
87
114
build_simple libxcb $LIBXCB_VERSION https://www.x.org/releases/individual/lib
88
115
89
116
build_libjpeg_turbo
90
- build_tiff
117
+ if [ -n " $IS_MACOS " ]; then
118
+ # Custom tiff build to include jpeg; by default, configure won't include
119
+ # headers/libs in the custom macOS prefix. Explicitly disable webp,
120
+ # libdeflate and zstd, because on x86_64 macs, it will pick up the
121
+ # Homebrew versions of those libraries from /usr/local.
122
+ build_simple tiff $TIFF_VERSION https://download.osgeo.org/libtiff tar.gz \
123
+ --with-jpeg-include-dir=$BUILD_PREFIX /include --with-jpeg-lib-dir=$BUILD_PREFIX /lib \
124
+ --disable-webp --disable-libdeflate --disable-zstd
125
+ else
126
+ build_tiff
127
+ fi
128
+
91
129
build_libpng
92
130
build_lcms2
93
131
build_openjpeg
@@ -112,32 +150,47 @@ function build {
112
150
build_harfbuzz
113
151
}
114
152
153
+ # Perform all dependency builds in the build subfolder.
154
+ mkdir -p $WORKDIR
155
+ pushd $WORKDIR > /dev/null
156
+
115
157
# Any stuff that you need to do before you start building the wheels
116
158
# Runs in the root directory of this repository.
117
- curl -fsSL -o pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
118
- untar pillow-depends-main.zip
119
-
120
- if [[ -n " $IS_MACOS " ]]; then
121
- # libdeflate may cause a minimum target error when repairing the wheel
122
- # libtiff and libxcb cause a conflict with building libtiff and libxcb
123
- # libxau and libxdmcp cause an issue on macOS < 11
124
- # remove cairo to fix building harfbuzz on arm64
125
- # remove lcms2 and libpng to fix building openjpeg on arm64
126
- # remove jpeg-turbo to avoid inclusion on arm64
127
- # remove webp and zstd to avoid inclusion on x86_64
128
- # curl from brew requires zstd, use system curl
129
- brew remove --ignore-dependencies libpng libtiff libxcb libxau libxdmcp curl cairo lcms2 zstd
130
- if [[ " $CIBW_ARCHS " == " arm64" ]]; then
131
- brew remove --ignore-dependencies jpeg-turbo
132
- else
133
- brew remove --ignore-dependencies libdeflate webp
159
+ if [[ ! -d $WORKDIR /pillow-depends-main ]]; then
160
+ if [[ ! -f $PROJECTDIR /pillow-depends-main.zip ]]; then
161
+ echo " Download pillow dependency sources..."
162
+ curl -fSL -o $PROJECTDIR /pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
134
163
fi
164
+ echo " Unpacking pillow dependency sources..."
165
+ untar $PROJECTDIR /pillow-depends-main.zip
166
+ fi
135
167
136
- brew install pkg-config
168
+ if [[ -n " $IS_MACOS " ]]; then
169
+ # Homebrew (or similar packaging environments) install can contain some of
170
+ # the libraries that we're going to build. However, they may be compiled
171
+ # with a MACOSX_DEPLOYMENT_TARGET that doesn't match what we want to use,
172
+ # and they may bring in other dependencies that we don't want. The same will
173
+ # be true of any other locations on the path. To avoid conflicts, strip the
174
+ # path down to the bare minimum (which, on macOS, won't include any
175
+ # development dependencies).
176
+ export PATH=" $BUILD_PREFIX /bin:$( dirname $( which python3) ) :/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
177
+ export CMAKE_PREFIX_PATH=$BUILD_PREFIX
178
+
179
+ # Ensure the basic structure of the build prefix directory exists.
180
+ mkdir -p " $BUILD_PREFIX /bin"
181
+ mkdir -p " $BUILD_PREFIX /lib"
182
+
183
+ # Ensure pkg-config is available
184
+ build_pkg_config
185
+ # Ensure cmake is available
186
+ python3 -m pip install cmake
137
187
fi
138
188
139
189
wrap_wheel_builder build
140
190
191
+ # Return to the project root to finish the build
192
+ popd > /dev/null
193
+
141
194
# Append licenses
142
195
for filename in wheels/dependency_licenses/* ; do
143
196
echo -e " \n\n----\n\n$( basename $filename | cut -f 1 -d ' .' ) \n" | cat >> LICENSE
0 commit comments