From 8b4e66e10af3f97596caadf430c923d82ad5d36f Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Tue, 1 Apr 2025 15:31:35 -0400 Subject: [PATCH 1/6] fix(avif): use only aomenc and dav1d to reduce wheel size Also build libavif as a shared library. When it is built as a static library, the dependency library files are combined into a single archive. But when they are linked as a shared library, the linker is able to remove unused objects. This yields a modest but not insignificant file size reduction. --- .github/workflows/wheels-dependencies.sh | 8 +++++--- wheels/dependency_licenses/RAV1E.txt | 25 ----------------------- wheels/dependency_licenses/SVT-AV1.txt | 26 ------------------------ winbuild/build_prepare.py | 4 ++-- 4 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 wheels/dependency_licenses/RAV1E.txt delete mode 100644 wheels/dependency_licenses/SVT-AV1.txt diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index accd99901..d841e389d 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -137,14 +137,16 @@ function build_libavif { && CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake \ -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \ -DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \ + -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib \ + -DCMAKE_MACOSX_RPATH=OFF \ -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_SHARED_LIBS=ON \ -DAVIF_LIBSHARPYUV=LOCAL \ -DAVIF_LIBYUV=LOCAL \ -DAVIF_CODEC_AOM=LOCAL \ + -DCONFIG_AV1_DECODER=0 \ + -DAVIF_CODEC_AOM_DECODE=OFF \ -DAVIF_CODEC_DAV1D=LOCAL \ - -DAVIF_CODEC_RAV1E=LOCAL \ - -DAVIF_CODEC_SVT=LOCAL \ -DENABLE_NASM=ON \ -DCMAKE_MODULE_PATH=/tmp/cmake/Modules \ . \ diff --git a/wheels/dependency_licenses/RAV1E.txt b/wheels/dependency_licenses/RAV1E.txt deleted file mode 100644 index 3d6c825c4..000000000 --- a/wheels/dependency_licenses/RAV1E.txt +++ /dev/null @@ -1,25 +0,0 @@ -BSD 2-Clause License - -Copyright (c) 2017-2023, the rav1e contributors -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* 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. diff --git a/wheels/dependency_licenses/SVT-AV1.txt b/wheels/dependency_licenses/SVT-AV1.txt deleted file mode 100644 index 532a982b3..000000000 --- a/wheels/dependency_licenses/SVT-AV1.txt +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2019, 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. diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index e118cd994..c487d4dd3 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -392,9 +392,9 @@ DEPS: dict[str, dict[str, Any]] = { "-DAVIF_LIBSHARPYUV=LOCAL", "-DAVIF_LIBYUV=LOCAL", "-DAVIF_CODEC_AOM=LOCAL", + "-DCONFIG_AV1_DECODER=0", + "-DAVIF_CODEC_AOM_DECODE=OFF", "-DAVIF_CODEC_DAV1D=LOCAL", - "-DAVIF_CODEC_RAV1E=LOCAL", - "-DAVIF_CODEC_SVT=LOCAL", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5", ), cmd_xcopy("include", "{inc_dir}"), From a2cbce795d0d99276f00b10a3f714afcfd2ce93f Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Wed, 2 Apr 2025 13:54:48 -0400 Subject: [PATCH 2/6] Include comment about CONFIG_AV1_DECODER=0 --- .github/workflows/wheels-dependencies.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index d841e389d..6099e503b 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -133,6 +133,8 @@ function build_libavif { fi local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz) + # CONFIG_AV1_DECODER=0 is a flag for libaom (included as a subproject of + # libavif) to disable the compilation and inclusion of aom's AVIF decoder. (cd $out_dir \ && CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake \ -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \ From 84485e1718869fecf1e6156e84f0e1e89a73ee96 Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Wed, 2 Apr 2025 15:12:44 -0400 Subject: [PATCH 3/6] s/AVIF/AV1/ --- .github/workflows/wheels-dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 6099e503b..03c3a23df 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -134,7 +134,7 @@ function build_libavif { local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz) # CONFIG_AV1_DECODER=0 is a flag for libaom (included as a subproject of - # libavif) to disable the compilation and inclusion of aom's AVIF decoder. + # libavif) to disable the compilation and inclusion of aom's AV1 decoder. (cd $out_dir \ && CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake \ -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \ From ab55e543c8ea8bdbd3621f542da761610b38e403 Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Wed, 2 Apr 2025 15:55:08 -0400 Subject: [PATCH 4/6] remove ENABLE_NASM and CMAKE_MODULE_PATH libavif cmake args ENABLE_NASM=ON is unnecessary...it forces the use of nasm over yasm if both are available, but only nasm is installed in the wheel build environments. And CMAKE_MODULE_PATH was only necessary when we used pre-built rav1e binaries. --- .github/workflows/wheels-dependencies.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 03c3a23df..a2ba89e86 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -149,8 +149,6 @@ function build_libavif { -DCONFIG_AV1_DECODER=0 \ -DAVIF_CODEC_AOM_DECODE=OFF \ -DAVIF_CODEC_DAV1D=LOCAL \ - -DENABLE_NASM=ON \ - -DCMAKE_MODULE_PATH=/tmp/cmake/Modules \ . \ && make install) touch libavif-stamp From 8a6e5affa10f7552a476581cc7c737d50f9b2594 Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Wed, 2 Apr 2025 21:43:21 -0400 Subject: [PATCH 5/6] Remove rust installation via rustup, which is no longer needed --- .github/workflows/wheels-dependencies.sh | 3 --- .github/workflows/wheels.yml | 5 ----- 2 files changed, 8 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index a2ba89e86..eec338ad4 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -122,9 +122,6 @@ function build_libavif { build_simple nasm 2.16.03 https://www.nasm.us/pub/nasm/releasebuilds/2.16.03 fi - # For rav1e - curl https://sh.rustup.rs -sSf | sh -s -- -y - . "$HOME/.cargo/env" if [ -z "$IS_ALPINE" ] && [ -z "$SANITIZER" ] && [ -z "$IS_MACOS" ]; then yum install -y perl if [[ "$MB_ML_VER" == 2014 ]]; then diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 2a8594f49..1fe6badae 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -160,11 +160,6 @@ jobs: & python.exe winbuild\build_prepare.py -v --no-imagequant --architecture=${{ matrix.cibw_arch }} shell: pwsh - - name: Update rust - if: matrix.cibw_arch == 'AMD64' - run: | - rustup update - - name: Build wheels run: | setlocal EnableDelayedExpansion From deb1c9dd4a9984e19d18159fdba69c04944b09bc Mon Sep 17 00:00:00 2001 From: Frankie Dintino Date: Fri, 4 Apr 2025 17:21:13 -0400 Subject: [PATCH 6/6] Build libavif with -Os and with LTO enabled --- .github/workflows/wheels-dependencies.sh | 9 ++++++++- winbuild/build_prepare.py | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index eec338ad4..83ece95f6 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -129,6 +129,12 @@ function build_libavif { fi fi + local build_type=MinSizeRel + + if [[ -z "$IS_ALPINE" ]] && [[ "$MB_ML_VER" == 2014 ]]; then + build_type=Release + fi + local out_dir=$(fetch_unpack https://github.com/AOMediaCodec/libavif/archive/refs/tags/v$LIBAVIF_VERSION.tar.gz libavif-$LIBAVIF_VERSION.tar.gz) # CONFIG_AV1_DECODER=0 is a flag for libaom (included as a subproject of # libavif) to disable the compilation and inclusion of aom's AV1 decoder. @@ -138,7 +144,6 @@ function build_libavif { -DCMAKE_INSTALL_LIBDIR=$BUILD_PREFIX/lib \ -DCMAKE_INSTALL_NAME_DIR=$BUILD_PREFIX/lib \ -DCMAKE_MACOSX_RPATH=OFF \ - -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=ON \ -DAVIF_LIBSHARPYUV=LOCAL \ -DAVIF_LIBYUV=LOCAL \ @@ -146,6 +151,8 @@ function build_libavif { -DCONFIG_AV1_DECODER=0 \ -DAVIF_CODEC_AOM_DECODE=OFF \ -DAVIF_CODEC_DAV1D=LOCAL \ + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ + -DCMAKE_BUILD_TYPE=$build_type \ . \ && make install) touch libavif-stamp diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index c487d4dd3..1d50aee1d 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -57,7 +57,10 @@ def cmd_nmake( def cmds_cmake( - target: str | tuple[str, ...] | list[str], *params: str, build_dir: str = "." + target: str | tuple[str, ...] | list[str], + *params: str, + build_dir: str = ".", + build_type: str = "Release", ) -> list[str]: if not isinstance(target, str): target = " ".join(target) @@ -66,7 +69,7 @@ def cmds_cmake( " ".join( [ "{cmake}", - "-DCMAKE_BUILD_TYPE=Release", + f"-DCMAKE_BUILD_TYPE={build_type}", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DCMAKE_RULE_MESSAGES:BOOL=OFF", # for NMake "-DCMAKE_C_COMPILER=cl.exe", # for Ninja @@ -396,6 +399,8 @@ DEPS: dict[str, dict[str, Any]] = { "-DAVIF_CODEC_AOM_DECODE=OFF", "-DAVIF_CODEC_DAV1D=LOCAL", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5", + "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON", + build_type="MinSizeRel", ), cmd_xcopy("include", "{inc_dir}"), ],