Skip to content

Commit 281517d

Browse files
lovellRReverser
andcommitted
Add infrastructure to build WebAssembly static libs via wasm-vips
Co-authored-by: Ingvar Stepanyan <[email protected]>
1 parent c57d14e commit 281517d

File tree

7 files changed

+106
-2
lines changed

7 files changed

+106
-2
lines changed

.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/wasm.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
VERSION_WASM_VIPS="56f151b"
5+
6+
DIR="wasm-vips-${VERSION_WASM_VIPS}"
7+
TAG="wasm-vips:${VERSION_WASM_VIPS}"
8+
9+
echo "Using ${TAG}"
10+
cd "${0%/*}"
11+
12+
if [ ! -d "$DIR" ]; then
13+
# Download specific version of wasm-vips
14+
mkdir "${DIR}"
15+
curl -Ls https://github.com/kleisauke/wasm-vips/archive/${VERSION_WASM_VIPS}.tar.gz | tar xzC "${DIR}" --strip-components=1
16+
fi
17+
18+
if [ -z "$(docker images -q ${TAG})" ]; then
19+
# Create container with emscripten
20+
pushd "${DIR}"
21+
docker build -t "${TAG}" .
22+
popd
23+
fi
24+
25+
if [ ! -d "$DIR/build/target/lib" ]; then
26+
# Build libvips and dependencies as static Wasm libraries via emscripten
27+
docker run --rm -v "$PWD/${DIR}":/src "${TAG}" -c "./build.sh --disable-bindings --disable-modules --disable-jxl --enable-libvips-cpp"
28+
fi
29+
30+
# Copy only the files we need
31+
cp -r --no-preserve=mode,ownership ${DIR}/build/target/{include,lib,versions.json} ../npm/dev-wasm32
32+
rm -r ../npm/dev-wasm32/lib/cmake

npm/dev-wasm32/THIRD-PARTY-NOTICES.md

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)