Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAssembly build #3522

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/libvips/* linguist-vendored
build/Release/sharp-emscripten-wasm32.node.* linguist-generated
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
CI:
permissions:
contents: write # for npx prebuild to make release
name: ${{ matrix.container || matrix.os }} - Node.js ${{ matrix.nodejs_version }} ${{ matrix.nodejs_arch }} ${{ matrix.prebuild && '- prebuild' }}
name: ${{ matrix.container || matrix.os }} - Node.js ${{ matrix.nodejs_version }} ${{ matrix.addon_arch || matrix.nodejs_arch }} ${{ matrix.prebuild && '- prebuild' }}
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
strategy:
Expand All @@ -31,6 +31,9 @@ jobs:
container: node:16-alpine3.12
- os: ubuntu-22.04
container: node:18-alpine3.14
- os: ubuntu-22.04
container: node:18-alpine3.14
addon_arch: wasm32
- os: macos-11
nodejs_version: 14
prebuild: true
Expand Down Expand Up @@ -95,9 +98,17 @@ jobs:
if: matrix.container
run: chown root.root .
- name: Install
if: matrix.addon_arch != 'wasm32'
run: npm install --build-from-source --unsafe-perm
- name: Install (WebAssembly)
if: matrix.addon_arch == 'wasm32'
run: npm install --ignore-scripts
- name: Test
if: matrix.addon_arch != 'wasm32'
run: npm test
- name: Test (WebAssembly)
if: matrix.addon_arch == 'wasm32'
run: npx --arch=wasm32 mocha
- name: Prebuild
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
env:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
build
build/*
!build/Release
build/Release/*
!build/Release/sharp-emscripten-wasm32.node.*
node_modules
/coverage
test/bench/node_modules
Expand All @@ -16,3 +19,4 @@ vendor
package-lock.json
.idea
.firebase
/wasm-scripts/wasm-vips
39 changes: 38 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@
'libvips-cpp'
],
'variables': {
'runtime_link%': 'shared',
'conditions': [
['OS != "emscripten"', {
'runtime_link%': 'shared',
}, {
'runtime_link%': 'static',
}],
RReverser marked this conversation as resolved.
Show resolved Hide resolved
['OS != "win"', {
'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
'use_global_libvips': '<!(node -p "Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString()")'
Expand All @@ -101,6 +105,39 @@
'<!(node -p "require(\'node-addon-api\').include_dir")',
],
'conditions': [
['OS == "emscripten"', {
# .js because that's how Emscripten knows what to build, and .node
# in front so that `require('[...].node')` would just work.
'product_extension': 'node.js',
'defines': [
# Limit to 1 async task to avoid stealing threads from the pool
# that are intended for libvips.
'EMNAPI_WORKER_POOL_SIZE=1',
],
'cflags': ['-g2'],
'ldflags': [
'-g2',
'-fexceptions',
# We don't know in advance how large images will be, best to allow growth
# rather than overallocate in resource-constrained environments.
'-sALLOW_MEMORY_GROWTH',
# Building for Node.js, we want sync instantiation for compat with native
'-sWASM_ASYNC_COMPILATION=0',
# Re-export emnapi bindings as the main exports
'--pre-js=<!(node -p "require.resolve(\'./wasm-scripts/pre.js\')")',
# Using JS implementation of text decoder is actually faster when using pthreads.
'-sTEXTDECODER=0',
# Support 64-bit integers.
'-sWASM_BIGINT',

# We're building only for Node.js for now
'-sENVIRONMENT=node',
# Propagate filesystem to Node.js.
'-sNODERAWFS',
# Exit helpers
'-sEXPORTED_FUNCTIONS=["_vips_shutdown", "_uv_library_shutdown"]',
],
}],
['use_global_libvips == "true"', {
# Use pkg-config for include and lib
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
Expand Down
Loading