Skip to content

Commit 148e1ac

Browse files
Add libavif support for iOS (#9117)
Co-authored-by: Andrew Murray <[email protected]>
1 parent 2ab301d commit 148e1ac

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

.github/workflows/wheels-dependencies.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,51 +186,71 @@ function build_libavif {
186186

187187
python3 -m pip install meson ninja
188188

189-
if [[ "$PLAT" == "x86_64" ]] || [ -n "$SANITIZER" ]; then
189+
if ([[ "$PLAT" == "x86_64" ]] && [[ -z "$IOS_SDK" ]]) || [ -n "$SANITIZER" ]; then
190190
build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03
191191
fi
192192

193193
local build_type=MinSizeRel
194+
local build_shared=ON
194195
local lto=ON
195196

196197
local libavif_cmake_flags
197198

198-
if [ -n "$IS_MACOS" ]; then
199+
if [[ -n "$IS_MACOS" ]]; then
199200
lto=OFF
200201
libavif_cmake_flags=(
201202
-DCMAKE_C_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
202203
-DCMAKE_CXX_FLAGS_MINSIZEREL="-Oz -DNDEBUG -flto" \
203204
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,-S,-x,-dead_strip_dylibs" \
204205
)
206+
if [[ -n "$IOS_SDK" ]]; then
207+
build_shared=OFF
208+
fi
205209
else
206210
if [[ "$MB_ML_VER" == 2014 ]] && [[ "$PLAT" == "x86_64" ]]; then
207211
build_type=Release
208212
fi
209213
libavif_cmake_flags=(-DCMAKE_SHARED_LINKER_FLAGS_INIT="-Wl,--strip-all,-z,relro,-z,now")
210214
fi
215+
if [[ -n "$IOS_SDK" ]] && [[ "$PLAT" == "x86_64" ]]; then
216+
libavif_cmake_flags+=(-DAOM_TARGET_CPU=generic)
217+
else
218+
libavif_cmake_flags+=(
219+
-DAVIF_CODEC_AOM_DECODE=OFF \
220+
-DAVIF_CODEC_DAV1D=LOCAL
221+
)
222+
fi
211223

212224
local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz)
225+
213226
# CONFIG_AV1_HIGHBITDEPTH=0 is a flag for libaom (included as a subproject
214227
# of libavif) that disables support for encoding high bit depth images.
215228
(cd $out_dir \
216229
&& cmake \
217230
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
218231
-DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \
219232
-DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib \
220-
-DBUILD_SHARED_LIBS=ON \
233+
-DBUILD_SHARED_LIBS=$build_shared \
221234
-DAVIF_LIBSHARPYUV=LOCAL \
222235
-DAVIF_LIBYUV=LOCAL \
223236
-DAVIF_CODEC_AOM=LOCAL \
224237
-DCONFIG_AV1_HIGHBITDEPTH=0 \
225-
-DAVIF_CODEC_AOM_DECODE=OFF \
226-
-DAVIF_CODEC_DAV1D=LOCAL \
227238
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=$lto \
228239
-DCMAKE_C_VISIBILITY_PRESET=hidden \
229240
-DCMAKE_CXX_VISIBILITY_PRESET=hidden \
230241
-DCMAKE_BUILD_TYPE=$build_type \
231242
"${libavif_cmake_flags[@]}" \
232-
. \
233-
&& make install)
243+
$HOST_CMAKE_FLAGS . )
244+
245+
if [[ -n "$IOS_SDK" ]]; then
246+
# libavif's CMake configuration generates a meson cross file... but it
247+
# doesn't work for iOS cross-compilation. Copy in Pillow-generated
248+
# meson-cross config to replace the cmake-generated version.
249+
cp $WORKDIR/meson-cross.txt $out_dir/crossfile-apple.meson
250+
fi
251+
252+
(cd $out_dir && make install)
253+
234254
touch libavif-stamp
235255
}
236256

@@ -268,10 +288,7 @@ function build {
268288
build_tiff
269289
fi
270290

271-
if [[ -z "$IOS_SDK" ]]; then
272-
# Short term workaround; don't build libavif on iOS
273-
build_libavif
274-
fi
291+
build_libavif
275292
build_libpng
276293
build_lcms2
277294
build_openjpeg

checks/check_wheel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def test_wheel_modules() -> None:
2525

2626
elif sys.platform == "ios":
2727
# tkinter is not available on iOS
28-
# libavif is not available on iOS (for now)
29-
expected_modules -= {"tkinter", "avif"}
28+
expected_modules.remove("tkinter")
3029

3130
assert set(features.get_supported_modules()) == expected_modules
3231

0 commit comments

Comments
 (0)