Skip to content

Commit

Permalink
feat: add native code dependencies for AVIF. (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
skidder authored Dec 13, 2024
1 parent 1d0cb7e commit 7d42794
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 0 deletions.
48 changes: 48 additions & 0 deletions deps/build-deps-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rm -rf giflib
rm -rf opencv
rm -rf bzip2
rm -rf ffmpeg
rm -rf libyuv
rm -rf aom
rm -rf libavif

if [ ! -d "$SRCDIR" ]; then
git clone https://github.com/discord/lilliput-dep-source "$SRCDIR"
Expand Down Expand Up @@ -117,6 +120,51 @@ $BASEDIR/ffmpeg/configure --prefix=$PREFIX --disable-doc --disable-programs --di
make
make install

echo '\n--------------------'
echo 'Building libyuv'
echo '--------------------\n'
mkdir -p $BASEDIR/libyuv
tar -xzf $SRCDIR/libyuv-eb6e7bb63738e29efd82ea3cf2a115238a89fa51-2024-12-12.tar.gz -C $BASEDIR/libyuv
cd $BASEDIR/libyuv
make V=1 -f linux.mk
cp libyuv.a "$PREFIX/lib"
cp -r include/* "$PREFIX/include/"

echo '\n--------------------'
echo 'Building libaom'
echo '--------------------\n'
mkdir -p $BASEDIR/aom
tar -xzf $SRCDIR/libaom-3.11.0.tar.gz -C $BASEDIR/aom
mkdir -p $BUILDDIR/aom
cd $BUILDDIR/aom
cmake $BASEDIR/aom -DENABLE_SHARED=0 -DENABLE_STATIC=1 -DENABLE_TESTS=0 -DENABLE_TOOLS=0 -DENABLE_DOCS=0 -DCMAKE_INSTALL_PREFIX=$PREFIX
make
make install

echo '\n--------------------'
echo 'Building libavif'
echo '--------------------\n'
mkdir -p $BASEDIR/libavif
tar -xzf $SRCDIR/libavif-1.1.1.tar.gz -C $BASEDIR/libavif --strip-components 1
mkdir -p $BUILDDIR/libavif
cd $BUILDDIR/libavif
cmake $BASEDIR/libavif \
-DAVIF_CODEC_AOM=SYSTEM \
-DAVIF_BUILD_APPS=OFF \
-DLIBYUV_LIBRARY=$PREFIX/lib/libyuv.a \
-DLIBYUV_INCLUDE_DIR=$PREFIX/include \
-DAOM_LIBRARY=$PREFIX/lib/libaom.a \
-DAOM_INCLUDE_DIR=$PREFIX/include \
-DJPEG_INCLUDE_DIR=$PREFIX/include \
-DJPEG_LIBRARY=$PREFIX/lib/libjpeg.a \
-DPNG_PNG_INCLUDE_DIR=$PREFIX/include \
-DPNG_LIBRARY=$PREFIX/lib/libpng.a \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=$PREFIX
make
make install

rm -rf $BASEDIR/linux/$ARCH/bin
rm -f $BASEDIR/linux/$ARCH/**/*.cmake

Expand Down
91 changes: 91 additions & 0 deletions deps/build-deps-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ rm -rf giflib
rm -rf opencv
rm -rf bzip2
rm -rf ffmpeg
rm -rf libyuv
rm -rf aom
rm -rf libavif

if [ ! -d "$SRCDIR" ]; then
git clone https://github.com/discord/lilliput-dep-source "$SRCDIR"
Expand Down Expand Up @@ -351,6 +354,94 @@ $BASEDIR/ffmpeg/configure --prefix=$PREFIX --disable-doc --disable-programs --di
make
make install

echo '\n--------------------'
echo 'Building libyuv'
echo '--------------------\n'
mkdir -p $BASEDIR/libyuv
tar -xzf $SRCDIR/libyuv-eb6e7bb63738e29efd82ea3cf2a115238a89fa51-2024-12-12.tar.gz -C $BASEDIR/libyuv
cd $BASEDIR/libyuv
patch -p0 < $BASEDIR/patches/0002-fix-libyuv-cmake-for-osx.patch
mkdir -p $BUILDDIR/libyuv
cd $BUILDDIR/libyuv

cmake $BASEDIR/libyuv \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
-DCMAKE_C_FLAGS="-arch arm64 -fPIC -O3 -march=armv8-a+crc+crypto -mtune=apple-m1" \
-DCMAKE_CXX_FLAGS="-arch arm64 -fPIC -O3 -march=armv8-a+crc+crypto -mtune=apple-m1" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DJPEG_LIBRARY=$PREFIX/lib/libjpeg.a \
-DJPEG_INCLUDE_DIR=$PREFIX/include \
-DCMAKE_EXE_LINKER_FLAGS="-L$PREFIX/lib" \
-DCMAKE_SHARED_LINKER_FLAGS="-L$PREFIX/lib" \
-DLIBYUV_BUILD_SHARED_LIBS=OFF \
-DLIBYUV_DISABLE_SHARED=ON \
-DLIBYUV_ENABLE_STATIC=ON

make
make install

# Remove any dylib if it was created
rm -f $PREFIX/lib/libyuv.dylib

echo '\n--------------------'
echo 'Building libaom'
echo '--------------------\n'
mkdir -p $BASEDIR/aom
tar -xzf $SRCDIR/libaom-3.11.0.tar.gz -C $BASEDIR/aom
mkdir -p $BUILDDIR/aom
cd $BUILDDIR/aom
cmake $BASEDIR/aom \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
-DCMAKE_C_FLAGS="-O3 -march=armv8-a+crc+crypto -mtune=apple-m1" \
-DCMAKE_CXX_FLAGS="-O3 -march=armv8-a+crc+crypto -mtune=apple-m1" \
-DENABLE_SHARED=0 \
-DENABLE_STATIC=1 \
-DENABLE_TESTS=0 \
-DENABLE_TOOLS=0 \
-DENABLE_DOCS=0 \
-DENABLE_NEON=1 \
-DENABLE_VSX=0 \
-DCONFIG_MULTITHREAD=1 \
-DCONFIG_RUNTIME_CPU_DETECT=1 \
-DCMAKE_INSTALL_PREFIX=$PREFIX
make
make install

echo '\n--------------------'
echo 'Building libavif'
echo '--------------------\n'
mkdir -p $BASEDIR/libavif
tar -xzf $SRCDIR/libavif-1.1.1.tar.gz -C $BASEDIR/libavif --strip-components 1
mkdir -p $BUILDDIR/libavif
cd $BUILDDIR/libavif
cmake $BASEDIR/libavif \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
-DCMAKE_C_FLAGS="-O3 -march=armv8-a+crc+crypto -mtune=apple-m1" \
-DCMAKE_CXX_FLAGS="-O3 -march=armv8-a+crc+crypto -mtune=apple-m1" \
-DAVIF_CODEC_AOM=SYSTEM \
-DAVIF_BUILD_APPS=OFF \
-DAVIF_ENABLE_NEON=ON \
-DLIBYUV_LIBRARY=$PREFIX/lib/libyuv.a \
-DLIBYUV_INCLUDE_DIR=$PREFIX/include \
-DAOM_LIBRARY=$PREFIX/lib/libaom.a \
-DAOM_INCLUDE_DIR=$PREFIX/include \
-DJPEG_INCLUDE_DIR=$PREFIX/include \
-DJPEG_LIBRARY=$PREFIX/lib/libjpeg.a \
-DPNG_PNG_INCLUDE_DIR=$PREFIX/include \
-DPNG_LIBRARY=$PREFIX/lib/libpng.a \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=$PREFIX
make
make install

rm -rf $BASEDIR/osx/$ARCH/bin
rm -f $BASEDIR/osx/$ARCH/**/*.cmake

Expand Down
81 changes: 81 additions & 0 deletions deps/patches/0002-fix-libyuv-cmake-for-osx.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--- CMakeLists.txt.orig 2024-12-12 17:06:48
+++ CMakeLists.txt 2024-12-12 17:07:22
@@ -5,6 +5,7 @@
PROJECT ( YUV C CXX ) # "C" is required even for C++ projects
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
OPTION( TEST "Built unit tests" OFF )
+OPTION( BUILD_SHARED_LIBS "Build shared libraries" OFF )

SET ( ly_base_dir ${PROJECT_SOURCE_DIR} )
SET ( ly_src_dir ${ly_base_dir}/source )
@@ -12,7 +13,6 @@
SET ( ly_tst_dir ${ly_base_dir}/unit_test )
SET ( ly_lib_name yuv )
SET ( ly_lib_static ${ly_lib_name} )
-SET ( ly_lib_shared ${ly_lib_name}_shared )

FILE ( GLOB_RECURSE ly_source_files ${ly_src_dir}/*.cc )
LIST ( SORT ly_source_files )
@@ -22,26 +22,33 @@

INCLUDE_DIRECTORIES( BEFORE ${ly_inc_dir} )

+INCLUDE ( FindJPEG )
+if (JPEG_FOUND)
+ include_directories( ${JPEG_INCLUDE_DIR} )
+ add_definitions( -DHAVE_JPEG )
+endif()
+
# this creates the static library (.a)
ADD_LIBRARY ( ${ly_lib_static} STATIC ${ly_source_files} )
+if (JPEG_FOUND)
+ target_link_libraries( ${ly_lib_static} ${JPEG_LIBRARY} )
+endif()

-# this creates the shared library (.so)
-ADD_LIBRARY ( ${ly_lib_shared} SHARED ${ly_source_files} )
-SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES OUTPUT_NAME "${ly_lib_name}" )
-SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES PREFIX "lib" )
+if (BUILD_SHARED_LIBS)
+ # this creates the shared library (.so)
+ SET ( ly_lib_shared ${ly_lib_name}_shared )
+ ADD_LIBRARY ( ${ly_lib_shared} SHARED ${ly_source_files} )
+ SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES OUTPUT_NAME "${ly_lib_name}" )
+ SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES PREFIX "lib" )
+ if (JPEG_FOUND)
+ target_link_libraries( ${ly_lib_shared} ${JPEG_LIBRARY} )
+ endif()
+endif()

# this creates the conversion tool
ADD_EXECUTABLE ( yuvconvert ${ly_base_dir}/util/yuvconvert.cc )
TARGET_LINK_LIBRARIES ( yuvconvert ${ly_lib_static} )

-
-INCLUDE ( FindJPEG )
-if (JPEG_FOUND)
- include_directories( ${JPEG_INCLUDE_DIR} )
- target_link_libraries( yuvconvert ${JPEG_LIBRARY} )
- add_definitions( -DHAVE_JPEG )
-endif()
-
if(TEST)
find_library(GTEST_LIBRARY gtest)
if(GTEST_LIBRARY STREQUAL "GTEST_LIBRARY-NOTFOUND")
@@ -73,13 +80,13 @@
endif()
endif()

-
# install the conversion tool, .so, .a, and all the header files
INSTALL ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert DESTINATION bin )
INSTALL ( TARGETS ${ly_lib_static} DESTINATION lib )
-INSTALL ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin )
+if (BUILD_SHARED_LIBS)
+ INSTALL ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin )
+endif()
INSTALL ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include )

# create the .deb and .rpm packages using cpack
INCLUDE ( CM_linux_packages.cmake )
-

0 comments on commit 7d42794

Please sign in to comment.