Skip to content

Commit e219aea

Browse files
lovellRReverser
andauthored
Add infrastructure to build WebAssembly static libs via wasm-vips (#205)
Co-authored-by: Ingvar Stepanyan <[email protected]>
1 parent c57d14e commit e219aea

File tree

9 files changed

+131
-2
lines changed

9 files changed

+131
-2
lines changed

.github/workflows/build-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
- 'linuxmusl-x64'
2929
- 'linuxmusl-arm64v8'
3030
- 'linux-s390x'
31+
- 'wasm32'
3132
- 'win32-ia32'
3233
- 'win32-x64'
3334
- 'win32-arm64v8'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
libvips*
22
*.log
3+
build/wasm-vips-*
34
deps/
45
target/
56
npm/*/*
67
!npm/*/package.json
8+
!npm/dev-wasm32/THIRD-PARTY-NOTICES.md
79
npm/img-sharp-libvips-*.tgz

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ The dylib files are compiled within the same build script as Linux.
4040

4141
Dependency paths are modified to use the relative `@rpath` with `install_name_tool`.
4242

43+
### WebAssembly
44+
45+
The scripts from [wasm-vips](https://github.com/kleisauke/wasm-vips)
46+
are [used to compile](build/wasm.sh) libvips and its dependencies
47+
as static Wasm libraries ready for further compilation into a single,
48+
statically-linked sharp shared library.
49+
4350
## Licences
4451

4552
These scripts are licensed under the terms of the [Apache 2.0 Licence](LICENSE).

build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ if ! [ -x "$(command -v docker)" ]; then
7979
exit 1
8080
fi
8181

82+
# WebAssembly
83+
if [ "$PLATFORM" == "wasm32" ]; then
84+
./build/wasm.sh "${VERSION_VIPS}"
85+
exit 0
86+
fi
87+
8288
# Update base images
8389
for baseimage in alpine:3.15 amazonlinux:2 debian:bullseye debian:buster; do
8490
docker pull $baseimage

build/wasm.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Third-party notices
2+
3+
This software contains third-party libraries
4+
used under the terms of the following licences:
5+
6+
| Library | Used under the terms of |
7+
|---------------|-----------------------------------------------------------------------------------------------------------|
8+
| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
9+
| cgif | MIT Licence |
10+
| expat | MIT Licence |
11+
| glib | LGPLv3 |
12+
| highway | Apache-2.0 License, BSD 3-Clause |
13+
| lcms | MIT Licence |
14+
| libexif | LGPLv3 |
15+
| libffi | MIT Licence |
16+
| libheif | LGPLv3 |
17+
| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
18+
| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
19+
| libnsgif | MIT Licence |
20+
| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
21+
| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
22+
| libvips | LGPLv3 |
23+
| libwebp | New BSD License |
24+
| resvg | MPL-2.0 License |
25+
| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
26+
27+
Use of libraries under the terms of the LGPLv3 is via the
28+
"any later version" clause of the LGPLv2 or LGPLv2.1.
29+
30+
Please report any errors or omissions via
31+
https://github.com/lovell/sharp-libvips/issues/new

npm/dev-wasm32/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@img/sharp-libvips-dev-wasm32",
3+
"version": "0.0.3",
4+
"description": "Header files and static wasm32 libraries for libvips and dependencies to build sharp as wasm32",
5+
"author": "Lovell Fuller <[email protected]>",
6+
"homepage": "https://sharp.pixelplumbing.com",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/lovell/sharp-libvips.git",
10+
"directory": "npm/dev-wasm32"
11+
},
12+
"license": "LGPL-3.0-or-later",
13+
"funding": {
14+
"url": "https://opencollective.com/libvips"
15+
},
16+
"preferUnplugged": true,
17+
"publishConfig": {
18+
"access": "public"
19+
},
20+
"files": [
21+
"include",
22+
"lib",
23+
"versions.json"
24+
],
25+
"type": "commonjs",
26+
"exports": {
27+
"./include": "./include/index.js",
28+
"./lib": "./lib/index.js",
29+
"./versions": "./versions.json"
30+
}
31+
}

npm/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": "true",
55
"workspaces": [
66
"dev",
7+
"dev-wasm32",
78
"darwin-x64",
89
"darwin-arm64",
910
"linux-arm",

npm/populate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ generate_index() {
3838

3939
remove_unused() {
4040
PACKAGE="$1"
41-
if [ "$PACKAGE" != "dev" ]; then
41+
if [[ "$PACKAGE" != "dev"* ]]; then
4242
rm -r "npm/$PACKAGE/include"
43+
rm "npm/$PACKAGE/THIRD-PARTY-NOTICES.md"
4344
fi
44-
rm "npm/$PACKAGE/THIRD-PARTY-NOTICES.md"
4545
}
4646

4747
# Download and extract per-platform binaries

0 commit comments

Comments
 (0)