Skip to content

Commit

Permalink
Add infrastructure to build WebAssembly static libs via wasm-vips
Browse files Browse the repository at this point in the history
Co-authored-by: Ingvar Stepanyan <[email protected]>
  • Loading branch information
lovell and RReverser committed Nov 6, 2023
1 parent c74b5ff commit 571ca14
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
libvips*
*.log
build/wasm-vips-*
deps/
target/
npm/*/*
!npm/*/package.json
!npm/dev-wasm32/THIRD-PARTY-NOTICES.md
npm/img-sharp-libvips-*.tgz
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ The dylib files are compiled within the same build script as Linux.

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

### WebAssembly

The scripts from [wasm-vips](https://github.com/kleisauke/wasm-vips)
are [used to compile](build/wasm.sh) libvips and its dependencies
as static Wasm libraries ready for further compilation into a single,
statically-linked sharp shared library.

## Licences

These scripts are licensed under the terms of the [Apache 2.0 Licence](LICENSE).
Expand Down
32 changes: 32 additions & 0 deletions build/wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -e

VERSION_WASM_VIPS="56f151b"

DIR="wasm-vips-${VERSION_WASM_VIPS}"
TAG="wasm-vips:${VERSION_WASM_VIPS}"

echo "Using ${TAG}"
cd "${0%/*}"

if [ ! -d "$DIR" ]; then
# Download specific version of wasm-vips
mkdir "${DIR}"
curl -Ls https://github.com/kleisauke/wasm-vips/archive/${VERSION_WASM_VIPS}.tar.gz | tar xzC "${DIR}" --strip-components=1
fi

if [ -z "$(docker images -q ${TAG})" ]; then
# Create container with emscripten
pushd "${DIR}"
docker build -t "${TAG}" .
popd
fi

if [ ! -d "$DIR/build/target/lib" ]; then
# Build libvips and dependencies as static Wasm libraries via emscripten
docker run --rm -v "$PWD/${DIR}":/src "${TAG}" -c "./build.sh --disable-bindings --disable-modules --disable-jxl --enable-libvips-cpp"
fi

# Copy only the files we need
cp -r --no-preserve=mode,ownership ${DIR}/build/target/{include,lib,versions.json} ../npm/dev-wasm32
rm -r ../npm/dev-wasm32/lib/cmake
31 changes: 31 additions & 0 deletions npm/dev-wasm32/THIRD-PARTY-NOTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Third-party notices

This software contains third-party libraries
used under the terms of the following licences:

| Library | Used under the terms of |
|---------------|-----------------------------------------------------------------------------------------------------------|
| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
| cgif | MIT Licence |
| expat | MIT Licence |
| glib | LGPLv3 |
| highway | Apache-2.0 License, BSD 3-Clause |
| lcms | MIT Licence |
| libexif | LGPLv3 |
| libffi | MIT Licence |
| libheif | LGPLv3 |
| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
| libnsgif | MIT Licence |
| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
| libvips | LGPLv3 |
| libwebp | New BSD License |
| resvg | MPL-2.0 License |
| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |

Use of libraries under the terms of the LGPLv3 is via the
"any later version" clause of the LGPLv2 or LGPLv2.1.

Please report any errors or omissions via
https://github.com/lovell/sharp-libvips/issues/new
31 changes: 31 additions & 0 deletions npm/dev-wasm32/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@img/sharp-libvips-dev-wasm32",
"version": "0.0.3",
"description": "Header files and static wasm32 libraries for libvips and dependencies to build sharp as wasm32",
"author": "Lovell Fuller <[email protected]>",
"homepage": "https://sharp.pixelplumbing.com",
"repository": {
"type": "git",
"url": "git+https://github.com/lovell/sharp-libvips.git",
"directory": "npm/dev-wasm32"
},
"license": "LGPL-3.0-or-later",
"funding": {
"url": "https://opencollective.com/libvips"
},
"preferUnplugged": true,
"publishConfig": {
"access": "public"
},
"files": [
"include",
"lib",
"versions.json"
],
"type": "commonjs",
"exports": {
"./include": "./include/index.js",
"./lib": "./lib/index.js",
"./versions": "./versions.json"
}
}
1 change: 1 addition & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": "true",
"workspaces": [
"dev",
"dev-wasm32",
"darwin-x64",
"darwin-arm64",
"linux-arm",
Expand Down
4 changes: 2 additions & 2 deletions npm/populate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ generate_index() {

remove_unused() {
PACKAGE="$1"
if [ "$PACKAGE" != "dev" ]; then
if [[ "$PACKAGE" != "dev"* ]]; then
rm -r "npm/$PACKAGE/include"
rm "npm/$PACKAGE/THIRD-PARTY-NOTICES.md"
fi
rm "npm/$PACKAGE/THIRD-PARTY-NOTICES.md"
}

# Download and extract per-platform binaries
Expand Down

0 comments on commit 571ca14

Please sign in to comment.