Skip to content

Commit

Permalink
Use patch for static local builds
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Sep 23, 2023
1 parent 080aa40 commit adaac6b
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
]
libavif-version: [ "0.11.0" ]
include:
- python-version: "3.9"
os: "ubuntu-20.04"
libavif-version: "1.0.1"
- python-version: "3.7"
PYTHONOPTIMIZE: 1
- python-version: "3.8"
Expand Down
6 changes: 6 additions & 0 deletions depends/install_libavif.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ else
PREFIX=/usr
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

PKGCONFIG=${PKGCONFIG:-pkg-config}

export CFLAGS="-fPIC -O3 $CFLAGS"
Expand All @@ -26,6 +28,10 @@ curl -sLo - \
pushd libavif-$LIBAVIF_VERSION
echo "::endgroup::"

if [ "$LIBAVIF_VERSION" == "1.0.1" ]; then
patch -p1 < "${SCRIPT_DIR}/libavif-1.0.1-local-static.patch"
fi

HAS_DECODER=0
HAS_ENCODER=0

Expand Down
148 changes: 148 additions & 0 deletions depends/libavif-1.0.1-local-static.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
From f8f4ed7ecec80a596f60a4a7e1392c09cedbf7ed Mon Sep 17 00:00:00 2001
From: Frankie Dintino <[email protected]>
Date: Tue, 12 Sep 2023 05:47:43 -0400
Subject: [PATCH] ci: link shared library build against static local

---
CMakeLists.txt | 33 +++++++++++++--------------------
ext/libyuv.cmd | 2 +-
2 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f0cde1..521560e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,10 +78,10 @@ endif()

if(BUILD_SHARED_LIBS)
set(AVIF_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}")
- set(AVIF_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
set(AVIF_LIBRARY_PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}")
- set(AVIF_LIBRARY_SUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ # This is needed to get shared libraries (e.g. pixbufloader-avif) to compile against a static libavif.
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

set(AVIF_PLATFORM_DEFINITIONS)
@@ -112,7 +112,7 @@ if(AVIF_LOCAL_ZLIBPNG)
set(PREV_ANDROID ${ANDROID})
set(ANDROID TRUE)
set(PNG_BUILD_ZLIB "${CMAKE_CURRENT_SOURCE_DIR}/ext/zlib" CACHE STRING "" FORCE)
- set(PNG_SHARED ${BUILD_SHARED_LIBS} CACHE BOOL "")
+ set(PNG_SHARED OFF CACHE BOOL "")
set(PNG_TESTS OFF CACHE BOOL "")
add_subdirectory(ext/libpng)
set(PNG_PNG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libpng")
@@ -135,7 +135,7 @@ if(AVIF_LOCAL_JPEG)
endif()
option(AVIF_LOCAL_LIBYUV "Build libyuv by providing your own copy inside the ext subdir." OFF)
if(AVIF_LOCAL_LIBYUV)
- set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/build/${AVIF_LIBRARY_PREFIX}yuv${AVIF_LIBRARY_SUFFIX}")
+ set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/build/${AVIF_LIBRARY_PREFIX}yuv${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif(AVIF_LOCAL_LIBYUV): ${LIB_FILENAME} is missing, bailing out")
endif()
@@ -146,13 +146,6 @@ if(AVIF_LOCAL_LIBYUV)
set(LIBYUV_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/include" PARENT_SCOPE)
set(LIBYUV_LIBRARY ${LIB_FILENAME} PARENT_SCOPE)
endif()
- if(BUILD_SHARED_LIBS)
- # Fix "libyuv.so: undefined reference to `jpeg_read_raw_data'" errors.
- if(NOT AVIF_LOCAL_JPEG)
- find_package(JPEG REQUIRED)
- endif()
- set(LIBYUV_LIBRARY ${LIBYUV_LIBRARY} ${JPEG_LIBRARY})
- endif()
set(libyuv_FOUND TRUE)
message(STATUS "libavif: local libyuv found; libyuv-based fast paths enabled.")
else(AVIF_LOCAL_LIBYUV)
@@ -184,7 +177,7 @@ if(libyuv_FOUND)
endif(libyuv_FOUND)
option(AVIF_LOCAL_LIBSHARPYUV "Build libsharpyuv by providing your own copy inside the ext subdir." OFF)
if(AVIF_LOCAL_LIBSHARPYUV)
- set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libwebp/build/libsharpyuv${AVIF_LIBRARY_SUFFIX}")
+ set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libwebp/build/libsharpyuv${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif(AVIF_LOCAL_LIBSHARPYUV): ${LIB_FILENAME} is missing, bailing out")
endif()
@@ -309,16 +302,16 @@ if(AVIF_CODEC_DAV1D)
if(DEFINED ANDROID_ABI)
set(AVIF_DAV1D_BUILD_DIR "${AVIF_DAV1D_BUILD_DIR}/${ANDROID_ABI}")
endif()
- set(LIB_FILENAME "${AVIF_DAV1D_BUILD_DIR}/src/libdav1d${AVIF_LIBRARY_SUFFIX}")
+ set(LIB_FILENAME "${AVIF_DAV1D_BUILD_DIR}/src/libdav1d${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
- if("${AVIF_LIBRARY_SUFFIX}" STREQUAL ".a")
+ if("${CMAKE_STATIC_LIBRARY_SUFFIX}" STREQUAL ".a")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} is missing, bailing out")
else()
# On windows, meson will produce a libdav1d.a instead of the expected libdav1d.dll/.lib.
# See https://github.com/mesonbuild/meson/issues/8153.
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/dav1d/build/src/libdav1d.a")
if(NOT EXISTS "${LIB_FILENAME}")
- message(FATAL_ERROR "libavif: ${LIB_FILENAME} (or libdav1d${AVIF_LIBRARY_SUFFIX}) is missing, bailing out")
+ message(FATAL_ERROR "libavif: ${LIB_FILENAME} (or libdav1d${CMAKE_STATIC_LIBRARY_SUFFIX}) is missing, bailing out")
endif()
endif()
endif()
@@ -353,7 +346,7 @@ if(AVIF_CODEC_LIBGAV1)
if(DEFINED ANDROID_ABI)
set(AVIF_LIBGAV1_BUILD_DIR "${AVIF_LIBGAV1_BUILD_DIR}/${ANDROID_ABI}")
endif()
- set(LIB_FILENAME "${AVIF_LIBGAV1_BUILD_DIR}/libgav1${AVIF_LIBRARY_SUFFIX}")
+ set(LIB_FILENAME "${AVIF_LIBGAV1_BUILD_DIR}/libgav1${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} is missing, bailing out")
endif()
@@ -378,7 +371,7 @@ if(AVIF_CODEC_RAV1E)

if(AVIF_LOCAL_RAV1E)
set(LIB_FILENAME
- "${CMAKE_CURRENT_SOURCE_DIR}/ext/rav1e/build.libavif/usr/lib/${AVIF_LIBRARY_PREFIX}rav1e${AVIF_LIBRARY_SUFFIX}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/ext/rav1e/build.libavif/usr/lib/${AVIF_LIBRARY_PREFIX}rav1e${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: compiled rav1e library is missing (in ext/rav1e/build.libavif/usr/lib), bailing out")
@@ -411,7 +404,7 @@ if(AVIF_CODEC_SVT)

if(AVIF_LOCAL_SVT)
set(LIB_FILENAME
- "${CMAKE_CURRENT_SOURCE_DIR}/ext/SVT-AV1/Bin/Release/${AVIF_LIBRARY_PREFIX}SvtAv1Enc${AVIF_LIBRARY_SUFFIX}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/ext/SVT-AV1/Bin/Release/${AVIF_LIBRARY_PREFIX}SvtAv1Enc${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: compiled svt library is missing (in ext/SVT-AV1/Bin/Release), bailing out")
@@ -450,7 +443,7 @@ if(AVIF_CODEC_AOM)
endif()
set(AVIF_SRCS ${AVIF_SRCS} src/codec_aom.c)
if(AVIF_LOCAL_AOM)
- set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/aom/build.libavif/${AVIF_LIBRARY_PREFIX}aom${AVIF_LIBRARY_SUFFIX}")
+ set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/aom/build.libavif/${AVIF_LIBRARY_PREFIX}aom${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} is missing, bailing out")
endif()
@@ -482,7 +475,7 @@ if(AVIF_CODEC_AVM)
set(AVIF_SRCS ${AVIF_SRCS} src/codec_avm.c)
if(AVIF_LOCAL_AVM)
# Building the avm repository generates files such as "libaom.a" because it is a fork of aom.
- set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/avm/build.libavif/${AVIF_LIBRARY_PREFIX}aom${AVIF_LIBRARY_SUFFIX}")
+ set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/avm/build.libavif/${AVIF_LIBRARY_PREFIX}aom${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} (from avm) is missing, bailing out")
endif()
diff --git a/ext/libyuv.cmd b/ext/libyuv.cmd
index c959777..1186156 100755
--- a/ext/libyuv.cmd
+++ b/ext/libyuv.cmd
@@ -22,6 +22,6 @@ git checkout 464c51a0
mkdir build
cd build

-cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
+cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF ..
ninja yuv
cd ../..
--
2.30.0

32 changes: 8 additions & 24 deletions wheelbuild/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,9 @@ function build_libsharpyuv {
-DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_LIBDIR=lib \
"${cmake_flags[@]}" \
&& ninja sharpyuv)

if [ -n "$IS_MACOS" ]; then
CP="sudo cp"
MKDIR="sudo mkdir"
else
CP="cp"
MKDIR="mkdir"
fi

$CP libwebp-$LIBWEBP_SHA/build/libsharpyuv.a $BUILD_PREFIX/lib
$CP libwebp-$LIBWEBP_SHA/build/sharpyuv/libsharpyuv.pc $BUILD_PREFIX/lib/pkgconfig
$MKDIR -p $BUILD_PREFIX/include/webp/sharpyuv
$CP libwebp-$LIBWEBP_SHA/sharpyuv/*.h $BUILD_PREFIX/include/webp/sharpyuv

require_package libsharpyuv
group_end
touch libsharpyuv-stamp
}
Expand All @@ -424,18 +409,10 @@ function build_libyuv {
&& cmake -G Ninja .. \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
"${cmake_flags[@]}" .. \
&& ninja yuv)

if [ -n "$IS_MACOS" ]; then
CP="sudo cp"
else
CP="cp"
fi

$CP libyuv-$LIBYUV_SHA/build/libyuv.a $BUILD_PREFIX/lib
$CP -a libyuv-$LIBYUV_SHA/include/* $BUILD_PREFIX/include

group_end
touch libyuv-stamp
}
Expand Down Expand Up @@ -495,9 +472,16 @@ function build_libavif {

group_end

(cd libavif-$LIBAVIF_VERSION \
&& patch -p1 -i $CONFIG_DIR/libavif-1.0.1-local-static.patch)

build_libsharpyuv
mv libwebp-$LIBWEBP_SHA libavif-$LIBAVIF_VERSION/ext/libwebp
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_LOCAL_LIBSHARPYUV=ON)

build_libyuv
mv libyuv-$LIBYUV_SHA libavif-$LIBAVIF_VERSION/ext/libyuv
LIBAVIF_CMAKE_FLAGS+=(-DAVIF_LOCAL_LIBYUV=ON)

group_start "Build libavif"

Expand Down

0 comments on commit adaac6b

Please sign in to comment.