|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +if [ $# -lt 1 ]; then |
| 5 | + echo |
| 6 | + echo "Usage: $0 VERSION_VIPS [VERSION_WASM_VIPS]" |
| 7 | + echo "Use wasm-vips to build wasm32 static libraries for libvips and its dependencies" |
| 8 | + echo |
| 9 | + echo "Please specify the libvips VERSION_VIPS, e.g. 8.15.0" |
| 10 | + echo "Optionally provide a specific VERSION_WASM_VIPS commit, e.g. abc1234" |
| 11 | + echo |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | +VERSION_VIPS="$1" |
| 15 | +VERSION_WASM_VIPS="${2:-56f151b}" # TODO: fetch latest wasm-vips commit as default |
| 16 | + |
| 17 | +DIR="wasm-vips-${VERSION_WASM_VIPS}" |
| 18 | +TAG="wasm-vips:${VERSION_WASM_VIPS}" |
| 19 | + |
| 20 | +echo "Using ${TAG} to build libvips ${VERSION_VIPS}" |
| 21 | +cd "${0%/*}" |
| 22 | + |
| 23 | +# Download specific version of wasm-vips |
| 24 | +if [ ! -d "$DIR" ]; then |
| 25 | + mkdir "${DIR}" |
| 26 | + curl -Ls https://github.com/kleisauke/wasm-vips/archive/${VERSION_WASM_VIPS}.tar.gz | tar xzC "${DIR}" --strip-components=1 |
| 27 | +fi |
| 28 | + |
| 29 | +# Check libvips versions match |
| 30 | +VERSION_VIPS_UPSTREAM=$(grep -Po "^VERSION_VIPS=\K[^ ]*" "${DIR}/build.sh") |
| 31 | +if [ "$VERSION_VIPS" != "$VERSION_VIPS_UPSTREAM" ]; then |
| 32 | + echo "Expected libvips $VERSION_VIPS, found $VERSION_VIPS_UPSTREAM upstream" # TODO: modify build.sh on-the-fly? |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Create container with emscripten |
| 37 | +if [ -z "$(docker images -q ${TAG})" ]; then |
| 38 | + pushd "${DIR}" |
| 39 | + docker build -t "${TAG}" . |
| 40 | + popd |
| 41 | +fi |
| 42 | + |
| 43 | +# Build libvips and dependencies as static Wasm libraries via emscripten |
| 44 | +if [ ! -d "$DIR/build/target/lib" ]; then |
| 45 | + docker run --rm -v "$PWD/${DIR}":/src "${TAG}" -c "./build.sh --disable-bindings --disable-modules --disable-jxl --enable-libvips-cpp" |
| 46 | +fi |
| 47 | + |
| 48 | +# Copy only the files we need |
| 49 | +cp -r --no-preserve=mode,ownership ${DIR}/build/target/{include,lib,versions.json} ../npm/dev-wasm32 |
| 50 | +rm -r ../npm/dev-wasm32/lib/cmake |
0 commit comments