Skip to content

Commit

Permalink
Test build for Emscripten PR 21701
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Apr 24, 2024
1 parent 9a0856d commit aff81f8
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Uses libvips v8.15.2, compiled with Emscripten v3.1.57.

### Changed

- Inline worker scripts (`*.worker.js`) into the main output file.
[emscripten-core/emscripten#21701](https://github.com/emscripten-core/emscripten/pull/21701)

## [v0.0.8] - 2024-03-17

Uses libvips v8.15.2, compiled with Emscripten v3.1.56.
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://github.com/emscripten-core/emsdk
FROM docker.io/emscripten/emsdk:3.1.57
FROM docker.io/emscripten/emsdk:3.1.58

# Path settings
ENV \
Expand All @@ -24,7 +24,7 @@ RUN \

# Emscripten patches
RUN \
curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.57...kleisauke:wasm-vips-3.1.57.patch | patch -p1 -d $EMSDK/upstream/emscripten && \
curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.58...kleisauke:wasm-vips-3.1.58.patch | patch -p1 -d $EMSDK/upstream/emscripten && \
emcc --clear-cache && embuilder build sysroot --force

# Rust
Expand All @@ -33,7 +33,7 @@ RUN \
--no-modify-path \
--profile minimal \
--target wasm32-unknown-emscripten \
--default-toolchain nightly-2024-04-13 \
--default-toolchain nightly-2024-04-24 \
--component rust-src

# Cache settings
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ yarn add wasm-vips

### Browser

Requires `vips.js`, `vips.wasm` and `vips.worker.js` to be served from
the same directory. Additionally, when using ES6 modules, it's necessary
to also serve the `vips-es6.js` and `vips-es6.worker.js` files.
Requires `vips.js` (or `vips-es6.js`) and `vips.wasm` to be served from
the same directory.

Since wasm-vips requires [the `SharedArrayBuffer` API](
https://caniuse.com/sharedarraybuffer), the website needs to opt-in to
a cross-origin isolated state, by serving the following HTTP headers on
both the main document and worker script (`*.worker.js`):
both the main document and `vips*.js` script:

```http
Cross-Origin-Embedder-Policy: require-corp
Expand Down
9 changes: 4 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ done
# Handy for debugging
#COMMON_FLAGS="-Og -gsource-map -pthread"
#export EMCC_DEBUG=1
#export EMCC_DEBUG_SAVE=1

# Handy for catching bugs
#COMMON_FLAGS="-Os -gsource-map -fsanitize=address -pthread"
Expand All @@ -108,7 +109,7 @@ done
#export LDFLAGS+=" --source-map-base http://localhost:3000/lib/"

# Rust flags
export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+nontrapping-fptoint"
export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+nontrapping-fptoint -Zdefault-hidden-visibility=yes"

# Common compiler flags
COMMON_FLAGS="-O3 -pthread"
Expand Down Expand Up @@ -174,10 +175,10 @@ VERSION_JXL=0.10.2 # https://github.com/libjxl/libjxl
VERSION_SPNG=0.7.4 # https://github.com/randy408/libspng
VERSION_IMAGEQUANT=2.4.1 # https://github.com/lovell/libimagequant
VERSION_CGIF=0.4.0 # https://github.com/dloebl/cgif
VERSION_WEBP=1.3.2 # https://chromium.googlesource.com/webm/libwebp
VERSION_WEBP=1.4.0 # https://chromium.googlesource.com/webm/libwebp
VERSION_TIFF=4.6.0 # https://gitlab.com/libtiff/libtiff
VERSION_RESVG=0.41.0 # https://github.com/RazrFalcon/resvg
VERSION_AOM=3.8.2 # https://aomedia.googlesource.com/aom
VERSION_AOM=3.9.0 # https://aomedia.googlesource.com/aom
VERSION_HEIF=1.17.6 # https://github.com/strukturag/libheif
VERSION_VIPS=8.15.2 # https://github.com/libvips/libvips

Expand Down Expand Up @@ -529,9 +530,7 @@ node --version

# Omit -es6 suffix from Node.js files
mv $SOURCE_DIR/lib/vips-node-es6.mjs $SOURCE_DIR/lib/vips-node.mjs
mv $SOURCE_DIR/lib/vips-node-es6.worker.mjs $SOURCE_DIR/lib/vips-node.worker.mjs
sed -i 's/vips-node-es6/vips-node/g' $SOURCE_DIR/lib/vips-node.mjs
sed -i 's/vips-node-es6/vips-node/g' $SOURCE_DIR/lib/vips-node.worker.mjs

# Print the target features section
echo -n "Used Wasm features: "
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"devDependencies": {
"semistandard": "^17.0.0",
"serve": "^14.2.1"
"serve": "^14.2.2"
},
"engines": {
"node": ">=16.4.0"
Expand All @@ -65,8 +65,8 @@
"ignore": [
"src/closure-externs/wasm-vips.js",
"src/fixed-threadpool-web.js",
"src/locatefile-cors-pre.js",
"src/modules-pre.js"
"src/modules-pre.js",
"src/workaround-cors-pre.js"
],
"env": [
"browser",
Expand Down
4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"css-loader": "^7.1.1",
"fflate": "^0.8.2",
"html-webpack-plugin": "^5.6.0",
"mini-css-extract-plugin": "^2.8.1",
"monaco-editor": "^0.47.0",
"mini-css-extract-plugin": "^2.9.0",
"monaco-editor": "^0.48.0",
"monaco-editor-webpack-plugin": "^7.1.0",
"terser-webpack-plugin": "^5.3.10",
"webpack": "^5.91.0",
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ endif()

if ("web" IN_LIST ENVIRONMENT)
set(WEB_CORS_WORKAROUND
--pre-js=${CMAKE_CURRENT_SOURCE_DIR}/locatefile-cors-pre.js
--pre-js=${CMAKE_CURRENT_SOURCE_DIR}/workaround-cors-pre.js
)
set(WEB_FIXED_THREADPOOL
--js-library=${CMAKE_CURRENT_SOURCE_DIR}/fixed-threadpool-web.js
Expand Down
16 changes: 0 additions & 16 deletions src/locatefile-cors-pre.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/workaround-cors-pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://stackoverflow.com/q/25458104
if (Module['workaroundCors']) {
Module['mainScriptUrlOrBlob'] = Module['mainScriptUrlOrBlob'] ||
URL.createObjectURL(new Blob(
[`importScripts('${_scriptName}');`],
{'type': 'application/javascript'}));
}

0 comments on commit aff81f8

Please sign in to comment.