1
1
#! /usr/bin/env bash
2
2
3
+ # exit on error
4
+ set -e
5
+
3
6
function usage()
4
7
{
5
8
cat << EOF
6
- Usage: $( basename " $0 " ) [OPTIONS] [DEPS] [ARCH] [TYPE ]
9
+ Usage: $( basename " $0 " ) [OPTIONS] [PKGS... ]
7
10
Build Windows binaries for libvips in a container
8
11
9
12
OPTIONS:
10
13
--help Show the help and exit
14
+ -t, --target <MXE_TARGET> The binary target (this can be specified multiple times)
11
15
-c, --commit <COMMIT> The commit to build libvips from
12
16
-r, --ref <REF> The branch or tag to build libvips from
13
17
--nightly Build libvips from tip-of-tree (alias of -r master)
14
18
--with-ffi-compat Ensure compatibility with the FFI-bindings when building static binaries
15
- --with-disp Build vipsdisp image viewer
16
19
--with-hevc Build libheif with the HEVC-related dependencies
17
20
--with-debug Build binaries without optimizations to improve debuggability
18
21
--with-jpegli Build binaries with jpegli instead of mozjpeg
19
22
--with-jpeg-turbo Build binaries with libjpeg-turbo instead of mozjpeg
20
23
--without-prebuilt Avoid using a prebuilt OCI image from GitHub Container Registry
21
24
--without-zlib-ng Build binaries with vanilla zlib
22
25
23
- DEPS:
24
- The group of dependencies to build libvips with,
25
- defaults to 'web'
26
- Possible values are:
27
- - web
28
- - all
29
-
30
- ARCH:
31
- The Windows architecture to target,
32
- defaults to 'x86_64'
33
- Possible values are:
34
- - x86_64
35
- - i686
36
- - aarch64
26
+ PKGS:
27
+ The packages and their dependencies to build,
28
+ defaults to 'vips-web'
37
29
38
- TYPE :
39
- Specifies the type of binary to be created ,
40
- defaults to 'shared'
30
+ MXE_TARGET :
31
+ The binary target ,
32
+ defaults to building for all possible targets
41
33
Possible values are:
42
- - shared
43
- - static
34
+ - x86_64-w64-mingw32.shared
35
+ - x86_64-w64-mingw32.static
36
+ - i686-w64-mingw32.shared
37
+ - i686-w64-mingw32.static
38
+ - aarch64-w64-mingw32.shared
39
+ - aarch64-w64-mingw32.static
44
40
EOF
45
41
46
42
if [ -n " $1 " ]; then
49
45
}
50
46
51
47
# Default arguments
48
+ mxe_targets=()
52
49
git_commit=" "
53
50
git_ref=" "
54
51
jpeg_impl=" mozjpeg"
55
52
with_ffi_compat=false
56
- with_disp=false
57
53
with_hevc=false
58
54
with_debug=false
59
55
with_prebuilt=true
@@ -65,11 +61,11 @@ POSITIONAL=()
65
61
while [ $# -gt 0 ]; do
66
62
case $1 in
67
63
-h|--help) usage 0 ;;
64
+ -t|--target) mxe_targets+=(" $2 " ); shift ;;
68
65
-c|--commit) git_commit=" $2 " ; shift ;;
69
66
-r|--ref) git_ref=" $2 " ; shift ;;
70
67
--nightly) git_ref=" master" ;;
71
68
--with-ffi-compat) with_ffi_compat=true ;;
72
- --with-disp) with_disp=true ;;
73
69
--with-hevc) with_hevc=true ;;
74
70
--with-debug) with_debug=true ;;
75
71
--with-jpegli) jpeg_impl=" jpegli" ;;
89
85
# Restore positional parameters
90
86
set -- " ${POSITIONAL[@]} "
91
87
92
- deps=" ${1:- web} "
93
- arch=" ${2:- x86_64} "
94
- type=" ${3:- shared} "
88
+ pkgs=(" $@ " )
95
89
96
- if [ " $with_hevc " = " true" ] && [ " $deps " = " web" ]; then
90
+ if [ ${# pkgs[@]} -eq 0 ]; then
91
+ pkgs=(vips-web)
92
+ fi
93
+
94
+ # Note: vipsdisp depends on vips-all
95
+ [[ ${pkgs[*]} =~ " vipsdisp" ]] && build_vipsdisp=true || build_vipsdisp=false
96
+ [[ ${pkgs[*]} =~ " vips-all" ]] && build_all_variant=true || build_all_variant=$build_vipsdisp
97
+ [[ ${pkgs[*]} =~ " vips-web" ]] && build_web_variant=true || build_web_variant=false
98
+
99
+ if [ ${# mxe_targets[@]} -eq 0 ]; then
100
+ if [ " $build_all_variant " = true ]; then
101
+ # Omit static builds by default for the "all" variant
102
+ mxe_targets=({x86_64,i686,aarch64}-w64-mingw32.shared)
103
+ elif [ " $with_ffi_compat " = true ]; then
104
+ # Omit shared builds by default for the --with-ffi-compat option
105
+ mxe_targets=({x86_64,i686,aarch64}-w64-mingw32.static)
106
+ else
107
+ # Default to all possible targets otherwise
108
+ mxe_targets=({x86_64,i686,aarch64}-w64-mingw32.{shared,static})
109
+ fi
110
+ fi
111
+
112
+ [[ ${mxe_targets[*]} =~ " .static" ]] && targets_static=true || targets_static=false
113
+ [[ ${mxe_targets[*]} =~ " .shared" ]] && targets_shared=true || targets_shared=false
114
+
115
+ if [ " $with_hevc " = true ] && [ " $build_web_variant " = true ]; then
97
116
echo " ERROR: The HEVC-related dependencies can only be built for the \" all\" variant." >&2
98
117
exit 1
99
118
fi
100
119
101
- if [ " $type " = " static" ] && [ " $deps " = " all" ]; then
120
+ if [ " $build_web_variant " = true ] && [ " $build_all_variant " = true ]; then
121
+ echo " ERROR: Cannot build both vips-web and vips-all simultaneously." >&2
122
+ exit 1
123
+ fi
124
+
125
+ if [ " $targets_static " = true ] && [ " $build_all_variant " = true ]; then
102
126
echo " ERROR: Distributing a statically linked library against GPL libraries, without releasing the code as GPL, violates the GPL license." >&2
103
127
exit 1
104
128
fi
105
129
106
- if [ " $type " = " static " ] && [ " $with_disp " = " true" ]; then
130
+ if [ " $targets_static " = true ] && [ " $build_vipsdisp " = true ]; then
107
131
echo " ERROR: GTK cannot be built as a statically linked library on Windows." >&2
108
132
exit 1
109
133
fi
110
134
111
- if [ " $type " = " shared " ] && [ " $with_ffi_compat " = " true" ]; then
135
+ if [ " $targets_shared " = true ] && [ " $with_ffi_compat " = true ]; then
112
136
echo " WARNING: The --with-ffi-compat option makes only sense when building static binaries." >&2
113
137
with_ffi_compat=false
114
138
fi
129
153
# GitHub's tarball API requires the short SHA commit as the directory name
130
154
git_commit=" ${git_commit: 0: 7} "
131
155
132
- target=" $arch -w64-mingw32.$type "
133
-
134
- if [ " $with_ffi_compat " = " true" ]; then
135
- target+=" .ffi"
156
+ # Ensure separate build targets
157
+ if [ " $build_all_variant " = true ]; then
158
+ mxe_targets=(" ${mxe_targets[@]/%/ .all} " )
136
159
fi
137
160
138
- if [ " $with_disp " = " true" ]; then
139
- target+= " .disp "
161
+ if [ " $with_ffi_compat " = true ]; then
162
+ mxe_targets=( " ${mxe_targets[@] /%/ .ffi} " )
140
163
fi
141
164
142
- if [ " $with_debug " = " true" ]; then
143
- target+= " .debug"
165
+ if [ " $with_debug " = true ]; then
166
+ mxe_targets=( " ${mxe_targets[@] /%/ .debug} " )
144
167
fi
145
168
146
169
# Check whether we can build and run OCI-compliant containers
155
178
156
179
image=" ghcr.io/libvips/build-win64-mxe:latest"
157
180
158
- if [ " $with_prebuilt " = " false" ]; then
181
+ if [ " $with_prebuilt " = false ]; then
159
182
image=" libvips-build-win-mxe-base"
160
183
161
184
# Ensure latest Debian stable base image
@@ -176,15 +199,15 @@ if [ "$jpeg_impl" != "libjpeg-turbo" ]; then
176
199
plugin_dirs+=" /data/plugins/$jpeg_impl "
177
200
fi
178
201
179
- if [ " $with_disp " = " true" ]; then
202
+ if [ " $build_vipsdisp " = true ]; then
180
203
plugin_dirs+=" /data/plugins/vipsdisp"
181
204
fi
182
205
183
- if [ " $with_hevc " = " true" ]; then
206
+ if [ " $with_hevc " = true ]; then
184
207
plugin_dirs+=" /data/plugins/hevc"
185
208
fi
186
209
187
- if [ " $with_zlib_ng " = " true" ]; then
210
+ if [ " $with_zlib_ng " = true ]; then
188
211
plugin_dirs+=" /data/plugins/zlib-ng"
189
212
fi
190
213
197
220
# https://github.com/libvips/libvips/issues/1637
198
221
plugin_dirs+=" /data/plugins/proxy-libintl"
199
222
200
- # Build libvips (+ dependencies) and optional GTK4 apps
223
+ # Build requested packages
201
224
$oci_runtime build \
202
225
-t libvips-build-win-mxe \
203
226
-f container/Dockerfile \
204
227
--build-arg BASE_IMAGE=" $image " \
205
- --build-arg DEPS =" $deps " \
206
- --build-arg TARGET =" $target " \
228
+ --build-arg PKGS =" ${pkgs[*]} " \
229
+ --build-arg MXE_TARGETS =" ${mxe_targets[*]} " \
207
230
--build-arg DEBUG=" $with_debug " \
208
231
--build-arg PLUGIN_DIRS=" $plugin_dirs " \
209
232
--build-arg GIT_COMMIT=" $git_commit " \
@@ -218,13 +241,11 @@ $oci_runtime build \
218
241
# packaging dir mounted at /data/packaging.
219
242
$oci_runtime run --rm -t \
220
243
-v $PWD /packaging:/data/packaging \
221
- -e GIT_COMMIT=" $git_commit " \
244
+ -e PKGS=" ${pkgs[*]} " \
245
+ -e MXE_TARGETS=" ${mxe_targets[*]} " \
222
246
-e FFI_COMPAT=" $with_ffi_compat " \
223
247
-e JPEG_IMPL=" $jpeg_impl " \
224
- -e DISP=" $with_disp " \
225
248
-e HEVC=" $with_hevc " \
226
249
-e DEBUG=" $with_debug " \
227
250
-e ZLIB_NG=" $with_zlib_ng " \
228
- libvips-build-win-mxe \
229
- $deps \
230
- $target
251
+ libvips-build-win-mxe
0 commit comments