Skip to content

Commit 07c1d2f

Browse files
committed
Improve build and packaging scripts
1 parent 90d70ee commit 07c1d2f

16 files changed

+498
-335
lines changed

.gitignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# Build output
2+
packaging/vips*
3+
packaging/vipsdisp*
4+
5+
# VIM swap files
16
.*.swp
2-
vips-dev-*
3-
vips-pdb-*
7+
8+
# Wine
49
.update-timestamp

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ The above "all" variant can optionally be built with [libde265] and [x265] to pr
191191
HEIC images. This can be turned on with the `--with-hevc` argument. For example:
192192

193193
```bash
194-
./build.sh all --with-hevc
194+
./build.sh vips-all --with-hevc
195195
```
196196

197197
These dependencies include HEVC-related logic and are therefore not included in the

build.sh

+71-50
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
11
#!/usr/bin/env bash
22

3+
# exit on error
4+
set -e
5+
36
function usage()
47
{
58
cat <<EOF
6-
Usage: $(basename "$0") [OPTIONS] [DEPS] [ARCH] [TYPE]
9+
Usage: $(basename "$0") [OPTIONS] [PKGS...]
710
Build Windows binaries for libvips in a container
811
912
OPTIONS:
1013
--help Show the help and exit
14+
-t, --target <MXE_TARGET> The binary target (this can be specified multiple times)
1115
-c, --commit <COMMIT> The commit to build libvips from
1216
-r, --ref <REF> The branch or tag to build libvips from
1317
--nightly Build libvips from tip-of-tree (alias of -r master)
1418
--with-ffi-compat Ensure compatibility with the FFI-bindings when building static binaries
15-
--with-disp Build vipsdisp image viewer
1619
--with-hevc Build libheif with the HEVC-related dependencies
1720
--with-debug Build binaries without optimizations to improve debuggability
1821
--with-jpegli Build binaries with jpegli instead of mozjpeg
1922
--with-jpeg-turbo Build binaries with libjpeg-turbo instead of mozjpeg
2023
--without-prebuilt Avoid using a prebuilt OCI image from GitHub Container Registry
2124
--without-zlib-ng Build binaries with vanilla zlib
2225
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'
3729
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
4133
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
4440
EOF
4541

4642
if [ -n "$1" ]; then
@@ -49,11 +45,11 @@ EOF
4945
}
5046

5147
# Default arguments
48+
mxe_targets=()
5249
git_commit=""
5350
git_ref=""
5451
jpeg_impl="mozjpeg"
5552
with_ffi_compat=false
56-
with_disp=false
5753
with_hevc=false
5854
with_debug=false
5955
with_prebuilt=true
@@ -65,11 +61,11 @@ POSITIONAL=()
6561
while [ $# -gt 0 ]; do
6662
case $1 in
6763
-h|--help) usage 0 ;;
64+
-t|--target) mxe_targets+=("$2"); shift ;;
6865
-c|--commit) git_commit="$2"; shift ;;
6966
-r|--ref) git_ref="$2"; shift ;;
7067
--nightly) git_ref="master" ;;
7168
--with-ffi-compat) with_ffi_compat=true ;;
72-
--with-disp) with_disp=true ;;
7369
--with-hevc) with_hevc=true ;;
7470
--with-debug) with_debug=true ;;
7571
--with-jpegli) jpeg_impl="jpegli" ;;
@@ -89,26 +85,54 @@ done
8985
# Restore positional parameters
9086
set -- "${POSITIONAL[@]}"
9187

92-
deps="${1:-web}"
93-
arch="${2:-x86_64}"
94-
type="${3:-shared}"
88+
pkgs=("$@")
9589

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
97116
echo "ERROR: The HEVC-related dependencies can only be built for the \"all\" variant." >&2
98117
exit 1
99118
fi
100119

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
102126
echo "ERROR: Distributing a statically linked library against GPL libraries, without releasing the code as GPL, violates the GPL license." >&2
103127
exit 1
104128
fi
105129

106-
if [ "$type" = "static" ] && [ "$with_disp" = "true" ]; then
130+
if [ "$targets_static" = true ] && [ "$build_vipsdisp" = true ]; then
107131
echo "ERROR: GTK cannot be built as a statically linked library on Windows." >&2
108132
exit 1
109133
fi
110134

111-
if [ "$type" = "shared" ] && [ "$with_ffi_compat" = "true" ]; then
135+
if [ "$targets_shared" = true ] && [ "$with_ffi_compat" = true ]; then
112136
echo "WARNING: The --with-ffi-compat option makes only sense when building static binaries." >&2
113137
with_ffi_compat=false
114138
fi
@@ -129,18 +153,17 @@ fi
129153
# GitHub's tarball API requires the short SHA commit as the directory name
130154
git_commit="${git_commit:0:7}"
131155

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}")
136159
fi
137160

138-
if [ "$with_disp" = "true" ]; then
139-
target+=".disp"
161+
if [ "$with_ffi_compat" = true ]; then
162+
mxe_targets=("${mxe_targets[@]/%/.ffi}")
140163
fi
141164

142-
if [ "$with_debug" = "true" ]; then
143-
target+=".debug"
165+
if [ "$with_debug" = true ]; then
166+
mxe_targets=("${mxe_targets[@]/%/.debug}")
144167
fi
145168

146169
# Check whether we can build and run OCI-compliant containers
@@ -155,7 +178,7 @@ fi
155178

156179
image="ghcr.io/libvips/build-win64-mxe:latest"
157180

158-
if [ "$with_prebuilt" = "false" ]; then
181+
if [ "$with_prebuilt" = false ]; then
159182
image="libvips-build-win-mxe-base"
160183

161184
# Ensure latest Debian stable base image
@@ -176,15 +199,15 @@ if [ "$jpeg_impl" != "libjpeg-turbo" ]; then
176199
plugin_dirs+=" /data/plugins/$jpeg_impl"
177200
fi
178201

179-
if [ "$with_disp" = "true" ]; then
202+
if [ "$build_vipsdisp" = true ]; then
180203
plugin_dirs+=" /data/plugins/vipsdisp"
181204
fi
182205

183-
if [ "$with_hevc" = "true" ]; then
206+
if [ "$with_hevc" = true ]; then
184207
plugin_dirs+=" /data/plugins/hevc"
185208
fi
186209

187-
if [ "$with_zlib_ng" = "true" ]; then
210+
if [ "$with_zlib_ng" = true ]; then
188211
plugin_dirs+=" /data/plugins/zlib-ng"
189212
fi
190213

@@ -197,13 +220,13 @@ fi
197220
# https://github.com/libvips/libvips/issues/1637
198221
plugin_dirs+=" /data/plugins/proxy-libintl"
199222

200-
# Build libvips (+ dependencies) and optional GTK4 apps
223+
# Build requested packages
201224
$oci_runtime build \
202225
-t libvips-build-win-mxe \
203226
-f container/Dockerfile \
204227
--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[*]}" \
207230
--build-arg DEBUG="$with_debug" \
208231
--build-arg PLUGIN_DIRS="$plugin_dirs" \
209232
--build-arg GIT_COMMIT="$git_commit" \
@@ -218,13 +241,11 @@ $oci_runtime build \
218241
# packaging dir mounted at /data/packaging.
219242
$oci_runtime run --rm -t \
220243
-v $PWD/packaging:/data/packaging \
221-
-e GIT_COMMIT="$git_commit" \
244+
-e PKGS="${pkgs[*]}" \
245+
-e MXE_TARGETS="${mxe_targets[*]}" \
222246
-e FFI_COMPAT="$with_ffi_compat" \
223247
-e JPEG_IMPL="$jpeg_impl" \
224-
-e DISP="$with_disp" \
225248
-e HEVC="$with_hevc" \
226249
-e DEBUG="$with_debug" \
227250
-e ZLIB_NG="$with_zlib_ng" \
228-
libvips-build-win-mxe \
229-
$deps \
230-
$target
251+
libvips-build-win-mxe

build/overrides.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$(info == General overrides: $(lastword $(MAKEFILE_LIST)))
1+
$(info [overrides] $(lastword $(MAKEFILE_LIST)))
22

33
## Update dependencies
44

@@ -440,6 +440,7 @@ endef
440440
define libjpeg-turbo_BUILD
441441
cd '$(BUILD_DIR)' && $(TARGET)-cmake \
442442
-DWITH_TURBOJPEG=OFF \
443+
-DPNG_SUPPORTED=OFF \
443444
-DENABLE_SHARED=$(CMAKE_SHARED_BOOL) \
444445
-DENABLE_STATIC=$(CMAKE_STATIC_BOOL) \
445446
-DCMAKE_ASM_NASM_COMPILER='$(PREFIX)/$(BUILD)/bin/nasm' \

build/plugins/mozjpeg/mozjpeg.mk

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ $(PKG)_DEPS := cc $(BUILD)~nasm
1313
define $(PKG)_BUILD
1414
cd '$(BUILD_DIR)' && $(TARGET)-cmake \
1515
-DWITH_TURBOJPEG=OFF \
16+
-DPNG_SUPPORTED=OFF \
1617
-DENABLE_SHARED=$(CMAKE_SHARED_BOOL) \
1718
-DENABLE_STATIC=$(CMAKE_STATIC_BOOL) \
1819
-DCMAKE_ASM_NASM_COMPILER='$(PREFIX)/$(BUILD)/bin/nasm' \

build/plugins/vipsdisp/graphene.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PKG := graphene
22
$(PKG)_WEBSITE := https://github.com/ebassi/graphene
3-
$(PKG)_DESCR := A thin layer of graphic data types
3+
$(PKG)_DESCR := A thin layer of graphic data types
44
$(PKG)_IGNORE :=
55
# https://github.com/ebassi/graphene/tarball/0cfa05ff62f244e4d5e7ac35a1979a23f25c5151
66
$(PKG)_VERSION := 0cfa05f

build/plugins/vipsdisp/vipsdisp.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ $(PKG)_VERSION := 3.1.0
66
$(PKG)_CHECKSUM := 53c9dc008b2f6ace62dc2a985cebf1958205d4d5c6df32392d2f98ed96b6453e
77
$(PKG)_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/patches/$(PKG)-[0-9]*.patch)))
88
$(PKG)_GH_CONF := jcupitt/vipsdisp/tags,v
9-
$(PKG)_DEPS := cc meson-wrapper gtk4 $(foreach TARGET,$(MXE_TARGETS),vips-$(lastword $(call split,.,$(TARGET))))
9+
$(PKG)_DEPS := cc meson-wrapper gtk4 vips-all
1010

1111
define $(PKG)_PRE_CONFIGURE
1212
(printf '{\n'; \
1313
printf ' "epoxy": "$(libepoxy_VERSION)",\n'; \
1414
printf ' "graphene": "$(graphene_VERSION)",\n'; \
1515
printf ' "gtk": "$(gtk4_VERSION)",\n'; \
16-
printf ' "vipsdisp": "$(vipsdisp_VERSION)",\n'; \
16+
printf ' "vipsdisp": "$(vipsdisp_VERSION)"\n'; \
1717
printf '}';) \
18-
> '$(PREFIX)/$(TARGET)/vips-packaging/versions-disp.json'
18+
> '$(PREFIX)/$(TARGET)/vips-packaging/versions-vipsdisp.json'
1919
endef
2020

2121
define $(PKG)_BUILD

build/vips-all.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ $(PKG)_GH_CONF := libvips/libvips/releases,v,,,,.tar.xz
99
$(PKG)_SUBDIR := vips-$($(PKG)_VERSION)
1010
$(PKG)_FILE := vips-$($(PKG)_VERSION).tar.xz
1111
$(PKG)_DEPS := cc meson-wrapper libwebp librsvg glib pango libarchive \
12-
libjpeg-turbo tiff lcms libexif libheif libpng \
13-
libspng libimagequant highway imagemagick matio openexr \
12+
libjpeg-turbo tiff lcms libexif libheif libspng \
13+
libimagequant highway imagemagick matio openexr \
1414
cfitsio nifticlib poppler fftw openslide libjxl cgif
1515

1616
define $(PKG)_PRE_CONFIGURE
1717
# Copy some files to the packaging directory
18-
mkdir -p $(PREFIX)/$(TARGET)/vips-packaging
18+
mkdir -p '$(PREFIX)/$(TARGET)/vips-packaging'
1919
$(foreach f, ChangeLog LICENSE README.md, \
2020
cp '$(SOURCE_DIR)/$(f)' '$(PREFIX)/$(TARGET)/vips-packaging';)
2121

build/vips-web.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ $(PKG)_GH_CONF := libvips/libvips/releases,v,,,,.tar.xz
99
$(PKG)_SUBDIR := vips-$($(PKG)_VERSION)
1010
$(PKG)_FILE := vips-$($(PKG)_VERSION).tar.xz
1111
$(PKG)_DEPS := cc meson-wrapper libwebp librsvg glib pango libarchive \
12-
libjpeg-turbo tiff lcms libexif libheif libpng \
13-
libspng libimagequant highway cgif
12+
libjpeg-turbo tiff lcms libexif libheif libspng \
13+
libimagequant highway cgif
1414

1515
define $(PKG)_PRE_CONFIGURE
1616
# Copy some files to the packaging directory
17-
mkdir -p $(PREFIX)/$(TARGET)/vips-packaging
17+
mkdir -p '$(PREFIX)/$(TARGET)/vips-packaging'
1818
$(foreach f, ChangeLog LICENSE README.md, \
1919
cp '$(SOURCE_DIR)/$(f)' '$(PREFIX)/$(TARGET)/vips-packaging';)
2020

container/Dockerfile

+8-17
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,32 @@ FROM $BASE_IMAGE
55
COPY . /data
66
WORKDIR /usr/local/mxe
77

8-
ARG DEPS
9-
ARG TARGET
8+
ARG PKGS
9+
ARG MXE_TARGETS
1010
ARG DEBUG
1111
ARG GIT_COMMIT
1212
ARG PLUGIN_DIRS
1313

1414
RUN \
15-
if [ "$DEBUG" = "true" ]; then \
15+
if [ "$DEBUG" = true ]; then \
1616
cp -f /data/settings/debug.mk settings.mk; \
1717
else \
1818
cp -f /data/settings/release.mk settings.mk; \
1919
fi
2020

21-
# Build gendef (a tool for generating def files from DLLs)
22-
# and libvips (+ dependencies)
21+
# Build requested packages and gendef (a tool for generating def files from DLLs)
2322
RUN --mount=type=cache,id=mxe-download,target=/usr/local/mxe/pkg \
24-
make gendef vips-$DEPS \
23+
make gendef $PKGS \
2524
MXE_PLUGIN_DIRS="$PLUGIN_DIRS" \
26-
MXE_TARGETS=$TARGET.$DEPS \
25+
MXE_TARGETS="$MXE_TARGETS" \
2726
GIT_COMMIT=$GIT_COMMIT
2827

29-
# Build GTK4 apps if requested
30-
RUN --mount=type=cache,id=mxe-download,target=/usr/local/mxe/pkg \
31-
if [ "${TARGET#*.gtk4}" != "$TARGET" ]; then \
32-
make vipsdisp nip4 \
33-
MXE_PLUGIN_DIRS="$PLUGIN_DIRS" \
34-
MXE_TARGETS=$TARGET.$DEPS; \
35-
fi
36-
3728
# Build and bundle llvm-mingw tests when debugging
3829
RUN --mount=type=cache,id=mxe-download,target=/usr/local/mxe/pkg \
39-
if [ "$DEBUG" = "true" ]; then \
30+
if [ "$DEBUG" = true ]; then \
4031
make test-llvm-mingw \
4132
MXE_PLUGIN_DIRS="$PLUGIN_DIRS" \
42-
MXE_TARGETS=$TARGET.$DEPS; \
33+
MXE_TARGETS="$MXE_TARGETS"; \
4334
fi
4435

4536
# The packaging dir is mounted here

0 commit comments

Comments
 (0)