Skip to content

Commit 7bed122

Browse files
committed
Install libraries only if required
1 parent 32ebfa0 commit 7bed122

File tree

2 files changed

+141
-28
lines changed

2 files changed

+141
-28
lines changed

.github/workflows/create-images.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,50 @@ jobs:
9393
-
9494
name: Update apt packages
9595
run: docker exec -t imagine-${{ matrix.php-version }} apt-get upgrade -qy
96+
-
97+
name: Inspect container environment
98+
id: inspect
99+
run: |
100+
if docker exec -t imagine-${{ matrix.php-version }} /installer.sh support-avif; then
101+
echo 'AVIF is supported'
102+
AVIF_SUPPORT=yes
103+
else
104+
AVIF_SUPPORT=no
105+
fi
106+
if docker exec -t imagine-${{ matrix.php-version }} /installer.sh support-heic; then
107+
echo 'HEIC is supported'
108+
HEIC_SUPPORT=yes
109+
else
110+
HEIC_SUPPORT=no
111+
fi
112+
echo "::set-output name=avif-support::$AVIF_SUPPORT"
113+
echo "::set-output name=heic-support::$HEIC_SUPPORT"
96114
-
97115
name: Install git
98116
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh git $GIT_VERSION
99117
-
100118
name: Install libaom ${{ env.LIBAOM_VERSION }}
119+
if: ${{ steps.inspect.outputs.avif-support == 'yes' || steps.inspect.outputs.heic-support == 'yes' }}
101120
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libaom $LIBAOM_VERSION
102121
-
103122
name: Install libdav1d ${{ env.LIBDAV1D_VERSION }}
123+
if: ${{ steps.inspect.outputs.avif-support == 'yes' }}
104124
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libdav1d $LIBDAV1D_VERSION
105125
-
106126
name: Install libyuv
127+
if: ${{ steps.inspect.outputs.avif-support == 'yes' || steps.inspect.outputs.heic-support == 'yes' }}
107128
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libyuv
108129
-
109130
name: Install libavif ${{ env.LIBAVIF_VERSION }}
131+
if: ${{ steps.inspect.outputs.avif-support == 'yes' }}
110132
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libavif $LIBAVIF_VERSION
111133
-
112134
name: Install libde265 ${{ env.LIBDE265_VERSION }}
135+
if: ${{ steps.inspect.outputs.heic-support == 'yes' }}
113136
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libde265 $LIBDE265_VERSION
114137
-
115138
name: Install libheif ${{ env.LIBHEIF_VERSION }}
139+
if: ${{ steps.inspect.outputs.heic-support == 'yes' }}
116140
run: docker exec -t imagine-${{ matrix.php-version }} /installer.sh libheif $LIBHEIF_VERSION
117141
-
118142
name: Install Composer

docker/installer.sh

Lines changed: 117 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ installGit() {
3131
git version --build-options
3232
}
3333

34-
# Try to install libaom.
34+
# Install libaom.
3535
#
3636
# Arguments:
3737
# $1: the version to be installed
38+
#
39+
# Return:
40+
# 0 in case of success
41+
# 1 in case of errors
3842
installLibaom() {
39-
if ! isCMakeAtLeastVersion '3.6'; then
40-
echo 'libaom not installed because cmake is too old' >&2
41-
return
43+
if ! isAvifSupported 2>/dev/null && ! isHeicSupported 2>/dev/null; then
44+
echo 'libaom not installed because the system does not support neither AVIF nor HEIC' >&2
45+
return 1
4246
fi
4347
installAptPackages '' 'cmake ninja-build nasm'
4448
printf 'Downloading libaom v%s... ' "$1"
@@ -54,16 +58,21 @@ installLibaom() {
5458
ldconfig
5559
markPackagesAsInstalledByRegex '^(lib)?aom([0-9]|-dev)'
5660
pkg-config --list-all | grep -E '^(lib)?aom\s'
61+
return 0
5762
}
5863

59-
# Try to install libdav1d.
64+
# Install libdav1d.
6065
#
6166
# Arguments:
6267
# $1: the version to be installed
68+
#
69+
# Return:
70+
# 0 in case of success
71+
# 1 in case of errors
6372
installLibdav1d() {
64-
if ! isMesonAtLeastVersion '0.44'; then
65-
echo 'libdav1d not installed because meson is too old' >&2
66-
return
73+
if ! isAvifSupported 2>/dev/null; then
74+
echo 'libdav1d not installed because the system does not support AVIF' >&2
75+
return 1
6776
fi
6877
installAptPackages '' 'meson ninja-build nasm'
6978
printf 'Downloading libdav1d v%s... ' "$1"
@@ -82,16 +91,21 @@ installLibdav1d() {
8291
ldconfig
8392
markPackagesAsInstalledByRegex '^(lib)?dav1d([0-9]|-dev)'
8493
pkg-config --list-all | grep -E '^(lib)?dav1d\s'
94+
return 0
8595
}
8696

87-
# Try to install libyuv.
97+
# Install libyuv.
8898
#
8999
# Arguments:
90100
# $1: the version to be installed
101+
#
102+
# Return:
103+
# 0 in case of success
104+
# 1 in case of errors
91105
installLibyuv() {
92-
if ! isGccAtLeastVersion '4.9.3'; then
93-
echo 'libyuv not installed because gcc is too old' >&2
94-
return
106+
if ! isAvifSupported 2>/dev/null && ! isHeicSupported 2>/dev/null; then
107+
echo 'libyuv not installed because the system does not support neither AVIF nor HEIC' >&2
108+
return 1
95109
fi
96110
installAptPackages '^libjpeg[0-9]*-turbo' 'cmake ^libjpeg[0-9]*-turbo-dev'
97111
printf 'Downloading libyuv... '
@@ -127,20 +141,33 @@ EOT
127141
ldconfig
128142
markPackagesAsInstalledByRegex '^(lib)?yuv([0-9]|-dev)'
129143
pkg-config --list-all | grep -E '^(lib)?yuv\s'
144+
return 0
130145
}
131146

132-
# Try to install libavif.
147+
# Install libavif.
133148
#
134149
# Arguments:
135150
# $1: the version to be installed
151+
#
152+
# Return:
153+
# 0 in case of success
154+
# 1 in case of errors
136155
installLibavif() {
156+
if ! isAvifSupported 2>/dev/null; then
157+
echo 'libavif not installed because the system does not support AVIF' >&2
158+
return 1
159+
fi
137160
if ! pkg-config --list-all | grep -E '^(lib)?aom\s' >/dev/null; then
138161
echo 'libavif not installed because libaom is not installed' >&2
139-
return
162+
return 1
140163
fi
141-
if ! isCMakeAtLeastVersion '3.5'; then
142-
echo 'libavif not installed because cmake is too old' >&2
143-
return
164+
if ! pkg-config --list-all | grep -E '^(lib)?dav1d\s' >/dev/null; then
165+
echo 'libavif not installed because libdav1d is not installed' >&2
166+
return 1
167+
fi
168+
if ! pkg-config --list-all | grep -E '^(lib)?yuv\s' >/dev/null; then
169+
echo 'libavif not installed because libyuv is not installed' >&2
170+
return 1
144171
fi
145172
installAptPackages '' 'cmake'
146173
printf 'Downloading libavif v%s... ' "$1"
@@ -156,19 +183,25 @@ installLibavif() {
156183
ldconfig
157184
markPackagesAsInstalledByRegex '^(lib)?avif([0-9]|-dev)'
158185
pkg-config --list-all | grep -E '^(lib)?avif\s'
186+
return 0
159187
}
160188

161189
# Install libde265.
162190
#
163191
# Arguments:
164192
# $1: the version to be installed
165193
#
194+
# Return:
195+
# 0 in case of success
196+
# 1 in case of errors
197+
#
166198
# @todo:
167199
# configure: WARNING: Did not find libvideogfx or libsdl, video output of dec265 will be disabled.
168200
# configure: WARNING: Did not find libvideogfx or libswscale, compilation of sherlock265 will be disabled.
169201
installLibde265() {
170-
if ! isHeicSupported; then
171-
return
202+
if ! isHeicSupported 2>/dev/null; then
203+
echo 'libde265 not installed because the system does not support HEIC' >&2
204+
return 1
172205
fi
173206
installAptPackages '' 'automake libtool'
174207
printf 'Downloading libde265 v%s... ' "$1"
@@ -184,19 +217,29 @@ installLibde265() {
184217
ldconfig
185218
markPackagesAsInstalledByRegex '^(lib)?de265'
186219
pkg-config --list-all | grep -E '^(lib)?de265\s'
220+
return 0
187221
}
188222

189223
# Install libheif.
190224
#
191225
# Arguments:
192226
# $1: the version to be installed
227+
#
228+
# Return:
229+
# 0 in case of success
230+
# 1 in case of errors
193231
installLibheif() {
194-
if ! isHeicSupported; then
195-
return
232+
if ! isHeicSupported 2>/dev/null; then
233+
echo 'libheif not installed because the system does not support HEIC' >&2
234+
return 1
235+
fi
236+
if ! pkg-config --list-all | grep -E '^(lib)?aom\s' >/dev/null; then
237+
echo 'libheif not installed because libaom is not installed' >&2
238+
return 1
196239
fi
197240
if ! pkg-config --list-all | grep -E '^(lib)?de265\s' >/dev/null; then
198241
echo 'libheif not installed because libde265 is not installed' >&2
199-
return
242+
return 1
200243
fi
201244
installAptPackages '^libjpeg[0-9]*-turbo ^libpng[0-9\-]*$ ^libx265(-[0-9\.\-]+)?$' 'automake libtool ^libjpeg[0-9]*-turbo-dev libpng-dev libx265-dev'
202245
printf 'Downloading libheif v%s... ' "$1"
@@ -212,20 +255,56 @@ installLibheif() {
212255
ldconfig
213256
markPackagesAsInstalledByRegex '^libheif.*'
214257
pkg-config --list-all | grep -E '^(lib)?heif\s'
258+
return 0
259+
}
260+
261+
# Check if AVIF format is supported in this environment
262+
#
263+
# Output (stderr):
264+
# the reason (if any) why it's not supported
265+
#
266+
# Return:
267+
# 0: true
268+
# 1: false
269+
isAvifSupported() {
270+
if ! isCMakeAtLeastVersion '3.6'; then
271+
echo 'AVIF support not provided since compiling libaom requires a more recent cmake version' >&2
272+
return 1
273+
fi
274+
if ! isMesonAtLeastVersion '0.44'; then
275+
echo 'AVIF support not provided since compiling libdav1d requires a more recent meson version' >&2
276+
return 1
277+
fi
278+
if ! isGccAtLeastVersion '4.9.3'; then
279+
echo 'AVIF support not provided since compiling libyuv requires a more recent gcc version' >&2
280+
return 1
281+
fi
282+
if ! isCMakeAtLeastVersion '3.5'; then
283+
echo 'AVIF support not provided since compiling libavif requires a more recent cmake version' >&2
284+
return 1
285+
fi
286+
return 0
215287
}
216288

217-
# Check if HEIC format is supported in this instance
289+
# Check if HEIC format is supported in this environment
218290
#
219-
# Output:
220-
# nothing if HEIC is supported
221-
# the reason why HEIC is not supported (to stderr) otherwise
291+
# Output (stderr):
292+
# the reason (if any) why it's not supported
222293
#
223294
# Return:
224295
# 0: true
225296
# 1: false
226297
isHeicSupported() {
227-
if [ -z getAptPackageAvailableVersion 'libx265(-[0-9\.\-]+)?$' ]; then
228-
echo 'libx265 is not available'
298+
if ! isCMakeAtLeastVersion '3.6'; then
299+
echo 'HEIC support not provided since compiling libaom requires a more recent cmake version' >&2
300+
return 1
301+
fi
302+
if [ -z "$(getAptPackageAvailableVersion 'libx265(-[0-9\.\-]+)?$')" ]; then
303+
echo 'HEIC support not provided since libx265 is not available'
304+
return 1
305+
fi
306+
if ! isGccAtLeastVersion '4.9.3'; then
307+
echo 'HEIC support not provided since compiling libyuv requires a more recent gcc version' >&2
229308
return 1
230309
fi
231310
return 0
@@ -296,6 +375,16 @@ case "$1" in
296375
git)
297376
installGit "$2"
298377
;;
378+
support-avif)
379+
if ! isAvifSupported; then
380+
return 1
381+
fi
382+
;;
383+
support-heic)
384+
if ! isHeicSupported; then
385+
return 1
386+
fi
387+
;;
299388
libaom)
300389
installLibaom "$2"
301390
;;

0 commit comments

Comments
 (0)