From 2a49dee017cbaf4b4f18e48e089dcbb821ef9c31 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 19 Oct 2022 22:16:45 +0100 Subject: [PATCH 01/39] Experiment with resvg --- Dockerfile | 6 +++++- build.sh | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 249517d3e..279d3a07f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,11 @@ FROM docker.io/emscripten/emsdk:3.1.29 # Avoid using bundled Node from emsdk -ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ +ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/root/.cargo/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ # Enable Emscripten sysroot cache EM_CACHE=/src/build/emcache \ + # Enable Rust cache + CARGO_HOME="/src/build/cargo-cache" \ # Enable ccache CCACHE_DIR=/src/build/ccache \ _EMCC_CCACHE=1 @@ -30,3 +32,5 @@ RUN apt-get update \ RUN curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:wasm-vips-3.1.29.patch | patch -p1 -d /emsdk/upstream/emscripten && \ curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:dylink-deno-compat.patch | patch -p1 -d /emsdk/upstream/emscripten && \ emcc --clear-cache && embuilder build sysroot --force + +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain nightly --component rust-src diff --git a/build.sh b/build.sh index b81ee4223..253d5640b 100755 --- a/build.sh +++ b/build.sh @@ -158,6 +158,8 @@ export LDFLAGS="$COMMON_FLAGS -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_ if [ "$WASM_BIGINT" = "true" ]; then export LDFLAGS+=" -sWASM_BIGINT"; fi if [ "$WASM_FS" = "true" ]; then export LDFLAGS+=" -sWASMFS"; fi +export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals,+nontrapping-fptoint" + # Build paths export CPATH="$TARGET/include" export PKG_CONFIG_PATH="$TARGET/lib/pkgconfig" @@ -188,6 +190,7 @@ VERSION_WEBP=1.2.4 # https://chromium.googlesource.com/webm/libwebp VERSION_TIFF=4.5.0 # https://gitlab.com/libtiff/libtiff VERSION_AOM=3.5.0 # https://aomedia.googlesource.com/aom VERSION_HEIF=1.14.2 # https://github.com/strukturag/libheif +VERSION_RESVG=0.28.0 # https://github.com/RazrFalcon/resvg VERSION_VIPS=8.13.3 # https://github.com/libvips/libvips # Remove patch version component @@ -403,6 +406,22 @@ node --version make install SUBDIRS='libtiff' noinst_PROGRAMS= dist_doc_DATA= ) +[ -f "$TARGET/lib/libresvg.a" ] || ( + stage "Compiling resvg" + mkdir -p $DEPS/resvg + curl -Ls https://github.com/RazrFalcon/resvg/releases/download/v$VERSION_RESVG/resvg-$VERSION_RESVG.tar.xz | tar xJC $DEPS/resvg --strip-components=1 + cd $DEPS/resvg/c-api + # Vendor dir doesn't work with -Zbuild-std right now due to https://github.com/rust-lang/wg-cargo-std-aware/issues/23 + # Just delete the config so that all deps are downloaded off the internet. + rm ../.cargo/config + # We don't want to build the shared library + sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml + # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 + RUSTFLAGS="$RUSTFLAGS -Clink-args=--no-entry" cargo build --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter + cp $DEPS/resvg/target/wasm32-unknown-emscripten/debug/libresvg.a $TARGET/lib/ + cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ +) + [ -f "$TARGET/lib/pkgconfig/aom.pc" ] || [ -n "$DISABLE_AVIF" ] || ( stage "Compiling aom" mkdir $DEPS/aom @@ -458,7 +477,8 @@ node --version -Ddeprecated=false -Dintrospection=false -Dauto_features=disabled ${ENABLE_MODULES:+-Dmodules=enabled} \ -Dcgif=enabled -Dexif=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \ -Djpeg-xl-module=enabled -Dlcms=enabled -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true \ - -Dppm=true -Danalyze=true -Dradiance=true ${ENABLE_AVIF:+-Dheif=enabled} -Dheif-module=enabled + -Dppm=true -Danalyze=true -Dradiance=true \ + -Dresvg=enabled ${ENABLE_AVIF:+-Dheif=enabled} -Dheif-module=enabled meson install -C _build --tag runtime,devel # Emscripten requires linking to side modules to find the necessary symbols to export module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1) From 5d9e24ee9e89a006da258fc4d1efa90317378335 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 11 Jan 2023 15:19:07 +0000 Subject: [PATCH 02/39] Fixups --- Dockerfile | 2 +- build.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 279d3a07f..5dfe18385 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM docker.io/emscripten/emsdk:3.1.29 # Avoid using bundled Node from emsdk -ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/root/.cargo/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ +ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ # Enable Emscripten sysroot cache EM_CACHE=/src/build/emcache \ # Enable Rust cache diff --git a/build.sh b/build.sh index 253d5640b..cef6bf812 100755 --- a/build.sh +++ b/build.sh @@ -471,6 +471,8 @@ node --version else sed -i "/subdir('cplusplus')/d" meson.build fi + # resvg patch + curl -Ls https://github.com/RReverser/libvips/commit/53657294d5fa6dfeff3055363bdb6048a0a32068.patch | patch -p1 # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \ From 761535955fd85b9b313966d3fc584e68c0153516 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 11 Jan 2023 17:34:42 +0000 Subject: [PATCH 03/39] More fixes for Rust integration --- build.sh | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index cef6bf812..dfae0d23b 100755 --- a/build.sh +++ b/build.sh @@ -56,6 +56,9 @@ JXL=true # Support for AVIF, enabled by default AVIF=true +# Partial support for SVG via resvg, disabled by default because it disables some opts. +SVG=false + # Build libvips C++ API, disabled by default LIBVIPS_CPP=false @@ -72,6 +75,7 @@ while [ $# -gt 0 ]; do --disable-wasm-bigint) WASM_BIGINT=false ;; --disable-jxl) JXL=false ;; --disable-avif) AVIF=false ;; + --enable-svg) SVG=true ;; --disable-modules) PIC=false MODULES=false @@ -105,6 +109,11 @@ if [ "$AVIF" = "true" ]; then else DISABLE_AVIF=true fi +if [ "$SVG" = "true" ]; then + ENABLE_SVG=true +else + DISABLE_SVG=true +fi if [ "$LIBVIPS_CPP" = "true" ]; then ENABLE_LIBVIPS_CPP=true else @@ -134,17 +143,24 @@ if [ "$PIC" = "true" ]; then PIC_FLAG=--pic; fi # Specify location where source maps are published (browser specific) #export LDFLAGS+=" --source-map-base http://localhost:3000/lib/" +# Rust flags +export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals,+nontrapping-fptoint" + # Common compiler flags -COMMON_FLAGS="-O3 -pthread" +COMMON_FLAGS="-pthread" if [ "$LTO" = "true" ]; then COMMON_FLAGS+=" -flto"; fi if [ "$WASM_EH" = "true" ]; then COMMON_FLAGS+=" -fwasm-exceptions -sSUPPORT_LONGJMP=wasm" + export RUSTFLAGS+=",+exception-handling" else COMMON_FLAGS+=" -fexceptions" fi -export CFLAGS="$COMMON_FLAGS -mnontrapping-fptoint" -if [ "$SIMD" = "true" ]; then export CFLAGS+=" -msimd128 -DWASM_SIMD_COMPAT_SLOW"; fi +export CFLAGS="$COMMON_FLAGS -O3 -mnontrapping-fptoint" +if [ "$SIMD" = "true" ]; then + export CFLAGS+=" -msimd128 -DWASM_SIMD_COMPAT_SLOW" + export RUSTFLAGS+=",+simd128" +fi if [ "$WASM_BIGINT" = "true" ]; then # libffi needs to detect WASM_BIGINT support at compile time export CFLAGS+=" -DWASM_BIGINT" @@ -154,12 +170,15 @@ if [ "$PIC" = "true" ]; then export CFLAGS+=" -fPIC"; fi export CXXFLAGS="$CFLAGS" -export LDFLAGS="$COMMON_FLAGS -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_LIBRARIES=0" +LD_OPT_LEVEL=3 +# The least-invasive workaround for +# https://github.com/rust-lang/rust/issues/91628 / https://github.com/emscripten-core/emscripten/issues/15722 +if [ "$ENABLE_SVG" = "true" ]; then LD_OPT_LEVEL=1; fi + +export LDFLAGS="$COMMON_FLAGS $LD_OPT_LEVEL -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_LIBRARIES=0" if [ "$WASM_BIGINT" = "true" ]; then export LDFLAGS+=" -sWASM_BIGINT"; fi if [ "$WASM_FS" = "true" ]; then export LDFLAGS+=" -sWASMFS"; fi -export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals,+nontrapping-fptoint" - # Build paths export CPATH="$TARGET/include" export PKG_CONFIG_PATH="$TARGET/lib/pkgconfig" @@ -417,8 +436,8 @@ node --version # We don't want to build the shared library sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 - RUSTFLAGS="$RUSTFLAGS -Clink-args=--no-entry" cargo build --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter - cp $DEPS/resvg/target/wasm32-unknown-emscripten/debug/libresvg.a $TARGET/lib/ + cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter + cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ ) From bf5104ef6ba890374ea04f205b31d931c86c2dff Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 11 Jan 2023 17:53:39 +0000 Subject: [PATCH 04/39] Various fixes for Rust --- build.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index dfae0d23b..60b906022 100755 --- a/build.sh +++ b/build.sh @@ -148,10 +148,13 @@ export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals,+nontr # Common compiler flags COMMON_FLAGS="-pthread" -if [ "$LTO" = "true" ]; then COMMON_FLAGS+=" -flto"; fi +if [ "$LTO" = "true" ]; then + COMMON_FLAGS+=" -flto" + export RUSTFLAGS+=" -Clto -Cembed-bitcode=yes" +fi if [ "$WASM_EH" = "true" ]; then COMMON_FLAGS+=" -fwasm-exceptions -sSUPPORT_LONGJMP=wasm" - export RUSTFLAGS+=",+exception-handling" + export RUSTFLAGS+=" -Ctarget-feature=+exception-handling" else COMMON_FLAGS+=" -fexceptions" fi @@ -159,7 +162,7 @@ fi export CFLAGS="$COMMON_FLAGS -O3 -mnontrapping-fptoint" if [ "$SIMD" = "true" ]; then export CFLAGS+=" -msimd128 -DWASM_SIMD_COMPAT_SLOW" - export RUSTFLAGS+=",+simd128" + export RUSTFLAGS+=" -Ctarget-feature=+simd128" fi if [ "$WASM_BIGINT" = "true" ]; then # libffi needs to detect WASM_BIGINT support at compile time @@ -175,7 +178,7 @@ LD_OPT_LEVEL=3 # https://github.com/rust-lang/rust/issues/91628 / https://github.com/emscripten-core/emscripten/issues/15722 if [ "$ENABLE_SVG" = "true" ]; then LD_OPT_LEVEL=1; fi -export LDFLAGS="$COMMON_FLAGS $LD_OPT_LEVEL -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_LIBRARIES=0" +export LDFLAGS="$COMMON_FLAGS -O$LD_OPT_LEVEL -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_LIBRARIES=0" if [ "$WASM_BIGINT" = "true" ]; then export LDFLAGS+=" -sWASM_BIGINT"; fi if [ "$WASM_FS" = "true" ]; then export LDFLAGS+=" -sWASMFS"; fi @@ -425,7 +428,7 @@ node --version make install SUBDIRS='libtiff' noinst_PROGRAMS= dist_doc_DATA= ) -[ -f "$TARGET/lib/libresvg.a" ] || ( +[ -f "$TARGET/lib/libresvg.a" ] || [ -n "$DISABLE_SVG" ] || ( stage "Compiling resvg" mkdir -p $DEPS/resvg curl -Ls https://github.com/RazrFalcon/resvg/releases/download/v$VERSION_RESVG/resvg-$VERSION_RESVG.tar.xz | tar xJC $DEPS/resvg --strip-components=1 From 5d07bc5f2a60ad2ee8d2c3f6d6fa4b0a88bd58be Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Thu, 12 Jan 2023 15:34:26 +0000 Subject: [PATCH 05/39] Revert problematic fix --- build.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/build.sh b/build.sh index 60b906022..a5aaa99dc 100755 --- a/build.sh +++ b/build.sh @@ -147,7 +147,7 @@ if [ "$PIC" = "true" ]; then PIC_FLAG=--pic; fi export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals,+nontrapping-fptoint" # Common compiler flags -COMMON_FLAGS="-pthread" +COMMON_FLAGS="-O3 -pthread" if [ "$LTO" = "true" ]; then COMMON_FLAGS+=" -flto" export RUSTFLAGS+=" -Clto -Cembed-bitcode=yes" @@ -159,7 +159,7 @@ else COMMON_FLAGS+=" -fexceptions" fi -export CFLAGS="$COMMON_FLAGS -O3 -mnontrapping-fptoint" +export CFLAGS="$COMMON_FLAGS -mnontrapping-fptoint" if [ "$SIMD" = "true" ]; then export CFLAGS+=" -msimd128 -DWASM_SIMD_COMPAT_SLOW" export RUSTFLAGS+=" -Ctarget-feature=+simd128" @@ -173,12 +173,7 @@ if [ "$PIC" = "true" ]; then export CFLAGS+=" -fPIC"; fi export CXXFLAGS="$CFLAGS" -LD_OPT_LEVEL=3 -# The least-invasive workaround for -# https://github.com/rust-lang/rust/issues/91628 / https://github.com/emscripten-core/emscripten/issues/15722 -if [ "$ENABLE_SVG" = "true" ]; then LD_OPT_LEVEL=1; fi - -export LDFLAGS="$COMMON_FLAGS -O$LD_OPT_LEVEL -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_LIBRARIES=0" +export LDFLAGS="$COMMON_FLAGS -L$TARGET/lib -sAUTO_JS_LIBRARIES=0 -sAUTO_NATIVE_LIBRARIES=0" if [ "$WASM_BIGINT" = "true" ]; then export LDFLAGS+=" -sWASM_BIGINT"; fi if [ "$WASM_FS" = "true" ]; then export LDFLAGS+=" -sWASMFS"; fi @@ -439,8 +434,8 @@ node --version # We don't want to build the shared library sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 - cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter - cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ + cargo build --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter + cp $DEPS/resvg/target/wasm32-unknown-emscripten/debug/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ ) From 3c5866c6e08d72e57570052dba5973c6a2441d91 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 13 Jan 2023 00:28:43 +0000 Subject: [PATCH 06/39] Patch Rust with a fix for link issue --- Dockerfile | 3 ++- build.sh | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5dfe18385..3cda2813f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,5 @@ RUN curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...klei curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:dylink-deno-compat.patch | patch -p1 -d /emsdk/upstream/emscripten && \ emcc --clear-cache && embuilder build sysroot --force -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain nightly --component rust-src +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain nightly-2023-01-12 --component rust-src +RUN curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust diff --git a/build.sh b/build.sh index a5aaa99dc..2ee4ac49d 100755 --- a/build.sh +++ b/build.sh @@ -434,8 +434,8 @@ node --version # We don't want to build the shared library sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 - cargo build --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter - cp $DEPS/resvg/target/wasm32-unknown-emscripten/debug/libresvg.a $TARGET/lib/ + cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter + cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ ) From 91069fdd072a140cdda03a311fdd05c3ddd0b4ad Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 13 Jan 2023 00:36:18 +0000 Subject: [PATCH 07/39] Fix patch path --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3cda2813f..306cc922d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,4 +34,4 @@ RUN curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...klei emcc --clear-cache && embuilder build sysroot --force RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain nightly-2023-01-12 --component rust-src -RUN curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust +RUN curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d /root/.rustup/toolchains/nightly-2023-01-12-x86_64-unknown-linux-gnu/lib/rustlib/src/rust From e0346bf35566c934cdc242015972f1cea0d43d16 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 13 Jan 2023 01:33:52 +0000 Subject: [PATCH 08/39] Extract RUSTUP_TOOLCHAIN var --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 306cc922d..56b3361ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ # https://github.com/emscripten-core/emsdk FROM docker.io/emscripten/emsdk:3.1.29 -# Avoid using bundled Node from emsdk -ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ +ENV RUSTUP_TOOLCHAIN=nightly-2023-01-12 + +ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/root/.rustup/toolchains/$RUSTUP_TOOLCHAIN-x86_64-unknown-linux-gnu/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ # Enable Emscripten sysroot cache EM_CACHE=/src/build/emcache \ # Enable Rust cache @@ -33,5 +34,5 @@ RUN curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...klei curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:dylink-deno-compat.patch | patch -p1 -d /emsdk/upstream/emscripten && \ emcc --clear-cache && embuilder build sysroot --force -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain nightly-2023-01-12 --component rust-src -RUN curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d /root/.rustup/toolchains/nightly-2023-01-12-x86_64-unknown-linux-gnu/lib/rustlib/src/rust +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain $RUSTUP_TOOLCHAIN --component rust-src +RUN curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d /root/.rustup/toolchains/$RUSTUP_TOOLCHAIN-x86_64-unknown-linux-gnu/lib/rustlib/src/rust From 66a5d48117dfa8bff26cdf482872440c0f00f95a Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 13 Jan 2023 03:00:01 +0000 Subject: [PATCH 09/39] Bump libvips+resvg --- build.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 2ee4ac49d..4dc5e67fd 100755 --- a/build.sh +++ b/build.sh @@ -488,8 +488,10 @@ node --version else sed -i "/subdir('cplusplus')/d" meson.build fi - # resvg patch - curl -Ls https://github.com/RReverser/libvips/commit/53657294d5fa6dfeff3055363bdb6048a0a32068.patch | patch -p1 + if [ -n "$ENABLE_SVG" ]; then + # resvg patch + curl -Ls https://github.com/RReverser/libvips/commit/53657294d5fa6dfeff3055363bdb6048a0a32068.patch | patch -p1 + fi # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \ From df60d23bdab99b3bd2d0644b6b648b78dcff14cf Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 14 Jan 2023 13:12:39 +0000 Subject: [PATCH 10/39] Add raster_images feature to SVG --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 4dc5e67fd..df65c6948 100755 --- a/build.sh +++ b/build.sh @@ -434,7 +434,7 @@ node --version # We don't want to build the shared library sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 - cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter + cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter,raster_images cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ ) From c0c6ca05acb52e284fed292601c8ad2bd9dc919d Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 14 Jan 2023 13:16:10 +0000 Subject: [PATCH 11/39] Bump libvips --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index df65c6948..2bf44cf6b 100755 --- a/build.sh +++ b/build.sh @@ -490,7 +490,7 @@ node --version fi if [ -n "$ENABLE_SVG" ]; then # resvg patch - curl -Ls https://github.com/RReverser/libvips/commit/53657294d5fa6dfeff3055363bdb6048a0a32068.patch | patch -p1 + curl -Ls https://github.com/RReverser/libvips/commit/185c842a405549c8297d35fd15edddf98092adfa.patch | patch -p1 fi # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build From b0bd5217606ddf466899015855d64d2fc9d00a20 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 14 Jan 2023 14:32:42 +0000 Subject: [PATCH 12/39] Rename feature --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 2bf44cf6b..539656dbf 100755 --- a/build.sh +++ b/build.sh @@ -434,7 +434,7 @@ node --version # We don't want to build the shared library sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 - cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter,raster_images + cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ ) From 112408de5b45ef209740b17b5634979bdd20400c Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 14 Jan 2023 14:46:04 +0000 Subject: [PATCH 13/39] Use dynamic resvg patch URL --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 539656dbf..701f7bbe7 100755 --- a/build.sh +++ b/build.sh @@ -490,7 +490,7 @@ node --version fi if [ -n "$ENABLE_SVG" ]; then # resvg patch - curl -Ls https://github.com/RReverser/libvips/commit/185c842a405549c8297d35fd15edddf98092adfa.patch | patch -p1 + curl -Ls https://github.com/RReverser/libvips/compare/wasm-vips..wasm-vips-resvg.patch | patch -p1 fi # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build From 330e1f76bfa6bc9fee4aef0689049e702157a076 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 14 Jan 2023 16:03:25 +0000 Subject: [PATCH 14/39] Update comment --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 701f7bbe7..8fd06232c 100755 --- a/build.sh +++ b/build.sh @@ -56,7 +56,7 @@ JXL=true # Support for AVIF, enabled by default AVIF=true -# Partial support for SVG via resvg, disabled by default because it disables some opts. +# Partial support for SVG via resvg, disabled by default because it's incomplete and relatively rarely useful feature. SVG=false # Build libvips C++ API, disabled by default From ca18715fb35bf05e0c8bb374e4ebac8477304f6b Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 14 Jan 2023 22:44:28 +0000 Subject: [PATCH 15/39] Update build.sh --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 8fd06232c..b86e4f190 100755 --- a/build.sh +++ b/build.sh @@ -499,7 +499,7 @@ node --version -Dcgif=enabled -Dexif=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \ -Djpeg-xl-module=enabled -Dlcms=enabled -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true \ -Dppm=true -Danalyze=true -Dradiance=true \ - -Dresvg=enabled ${ENABLE_AVIF:+-Dheif=enabled} -Dheif-module=enabled + ${ENABLE_SVG:+-Dresvg=enabled} ${ENABLE_AVIF:+-Dheif=enabled} -Dheif-module=enabled meson install -C _build --tag runtime,devel # Emscripten requires linking to side modules to find the necessary symbols to export module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1) From 2e45045ee0a017a28c1aa8032139a20348344e2a Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 17 Jan 2023 14:00:55 +0000 Subject: [PATCH 16/39] Update build.sh Co-authored-by: Kleis Auke Wolthuizen --- build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sh b/build.sh index b86e4f190..5694cde44 100755 --- a/build.sh +++ b/build.sh @@ -433,7 +433,6 @@ node --version rm ../.cargo/config # We don't want to build the shared library sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml - # Note: --release dosn't work right now due to https://github.com/rust-lang/rust/issues/91628 cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ From d3cbd281a408ec0aea789bf4687e56682683154e Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 17 Jan 2023 14:04:08 +0000 Subject: [PATCH 17/39] Add cargo cache to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e4fda8f30..cd96fd9f1 100644 --- a/.gitignore +++ b/.gitignore @@ -88,6 +88,7 @@ test/bench/images/output* # Build caches build/emcache build/ccache +build/cargo-cache # Include type definitions !lib/vips.d.ts From df73ea0dded68ae125406c243463db611fb9cb16 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 17 Jan 2023 18:11:32 +0100 Subject: [PATCH 18/39] Reorder flags --- build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 5694cde44..057b8c729 100755 --- a/build.sh +++ b/build.sh @@ -494,11 +494,11 @@ node --version # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \ - -Ddeprecated=false -Dintrospection=false -Dauto_features=disabled ${ENABLE_MODULES:+-Dmodules=enabled} \ - -Dcgif=enabled -Dexif=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \ - -Djpeg-xl-module=enabled -Dlcms=enabled -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true \ - -Dppm=true -Danalyze=true -Dradiance=true \ - ${ENABLE_SVG:+-Dresvg=enabled} ${ENABLE_AVIF:+-Dheif=enabled} -Dheif-module=enabled + -Ddeprecated=false -Dintrospection=false -Dauto_features=disabled \ + ${ENABLE_MODULES:+-Dmodules=enabled} -Dcgif=enabled -Dexif=enabled ${ENABLE_AVIF:+-Dheif=enabled} \ + -Dheif-module=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \ + -Djpeg-xl-module=enabled -Dlcms=enabled ${ENABLE_SVG:+-Dresvg=enabled} \ + -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true -Dppm=true -Danalyze=true -Dradiance=true meson install -C _build --tag runtime,devel # Emscripten requires linking to side modules to find the necessary symbols to export module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1) From 0982aef90b206fcb17bc7e78bab289671d0b1643 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 17 Jan 2023 19:26:05 +0100 Subject: [PATCH 19/39] Test build for kleisauke/libvips@349a7b7 --- build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 057b8c729..597bef584 100755 --- a/build.sh +++ b/build.sh @@ -56,8 +56,8 @@ JXL=true # Support for AVIF, enabled by default AVIF=true -# Partial support for SVG via resvg, disabled by default because it's incomplete and relatively rarely useful feature. -SVG=false +# Partial support for SVG load via resvg, enabled by default +SVG=true # Build libvips C++ API, disabled by default LIBVIPS_CPP=false @@ -75,7 +75,7 @@ while [ $# -gt 0 ]; do --disable-wasm-bigint) WASM_BIGINT=false ;; --disable-jxl) JXL=false ;; --disable-avif) AVIF=false ;; - --enable-svg) SVG=true ;; + --disable-svg) SVG=false ;; --disable-modules) PIC=false MODULES=false @@ -489,7 +489,7 @@ node --version fi if [ -n "$ENABLE_SVG" ]; then # resvg patch - curl -Ls https://github.com/RReverser/libvips/compare/wasm-vips..wasm-vips-resvg.patch | patch -p1 + curl -Ls https://github.com/kleisauke/libvips/compare/wasm-vips...RReverser-wasm-vips-resvg.patch | patch -p1 fi # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build @@ -497,7 +497,7 @@ node --version -Ddeprecated=false -Dintrospection=false -Dauto_features=disabled \ ${ENABLE_MODULES:+-Dmodules=enabled} -Dcgif=enabled -Dexif=enabled ${ENABLE_AVIF:+-Dheif=enabled} \ -Dheif-module=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \ - -Djpeg-xl-module=enabled -Dlcms=enabled ${ENABLE_SVG:+-Dresvg=enabled} \ + -Djpeg-xl-module=enabled -Dlcms=enabled ${ENABLE_SVG:+-Dresvg=enabled} -Dresvg-module=enabled \ -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true -Dppm=true -Danalyze=true -Dradiance=true meson install -C _build --tag runtime,devel # Emscripten requires linking to side modules to find the necessary symbols to export From 7d3c5c5770e50346239fe1d22828d693994a60eb Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 17 Jan 2023 19:49:03 +0100 Subject: [PATCH 20/39] Port libvips' SVG tests to wasm-vips --- test/unit/helpers.js | 8 ++++- test/unit/images/logo.svg | 31 ++++++++++++++++++ test/unit/images/logo.svg.gz | Bin 0 -> 2328 bytes test/unit/images/logo.svgz | Bin 0 -> 2328 bytes test/unit/index.html | 2 ++ test/unit/node-helper.js | 3 ++ test/unit/test_foreign.js | 59 +++++++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/unit/images/logo.svg create mode 100644 test/unit/images/logo.svg.gz create mode 100644 test/unit/images/logo.svgz diff --git a/test/unit/helpers.js b/test/unit/helpers.js index 903642be3..a00f93c27 100644 --- a/test/unit/helpers.js +++ b/test/unit/helpers.js @@ -20,6 +20,9 @@ export const avifFile = getPath('avif-orientation-6.avif'); export const avifFileHuge = getPath('16x17000.avif'); export const rgbaFile = getPath('rgba.png'); export const rgbaCorrectFile = getPath('rgba-correct.ppm'); +export const svgFile = getPath('logo.svg'); +export const svgzFile = getPath('logo.svgz'); +export const svgGzFile = getPath('logo.svg.gz'); export const mosaicFiles = [ getPath('cd1.1.jpg'), getPath('cd1.2.jpg'), getPath('cd2.1.jpg'), getPath('cd2.2.jpg'), @@ -45,7 +48,10 @@ export const testFiles = [ avifFileHuge, srgbFile, rgbaFile, - rgbaCorrectFile + rgbaCorrectFile, + svgFile, + svgzFile, + svgGzFile ].concat(analyzeFiles).concat(mosaicFiles); export const mosaicMarks = [ diff --git a/test/unit/images/logo.svg b/test/unit/images/logo.svg new file mode 100644 index 000000000..b378eb1da --- /dev/null +++ b/test/unit/images/logo.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/test/unit/images/logo.svg.gz b/test/unit/images/logo.svg.gz new file mode 100644 index 0000000000000000000000000000000000000000..62bfce6524506f80d50751eea3e1f7c3d859938b GIT binary patch literal 2328 zcmV+z3Fr17iwFqd=1N@v18i?+Z!U9oXLMoBFY_`Rj;G~*z1$u4n}^x{F#GxO-Tm>)hj+s;aCm>bTdy8wA5W)G zcZ;)ouIgd9yrizid{Ar>DdI*iP<`KfT)g zyncV({qpiMz4*4t)>;?FEu5RPV}AU$KP|t`-yX%rA02hZm<8W%JO6aom+j`|uZOP> zGc%YW`!vMp+J}#u?T3%2huLNQvR$7(KFrwC&)wo`n_#+o$D+ zjXe1azTPixAKq*}efzYzUD~gG-W(5~pI4h7CU?Dh+Un5aU#IPE_jf6o4U6wC-JW)v z$ELIYym+xVyK#1M@yg5l#U%!9wcflx-om3*I;*+=v^;&hebOpeUuIpTSPrhbDaLH< z7>u7PKjN?&=GGz|=V?lzx?%3@luJfn9Y1XJi1;OepOVYL4m%EY$rOFAaWMR}W^y%H z_jchY$38cC0GiNty?pXuwhSn-$%Q)3^Au8yX>firF-G6@#Z)5tY@G_ypsTqtl{#=| zETN2M3egmK;wN8Hibzt(VF+>Z&bctUFqLe49YW%)!yuQYY*QFG>k9EOQwcR@tTV>D z(Q?uUA6dIx+~_f~l;*gZ;^?KoqX7e5ut~Q6AA#Y*GAe);4S!sgYHg2C@ZYcHqn#4r zDJ>a3S+5A%sgzQaGL~z}c2Ih(^KBF9El2_}v?VoBaj6tccM~qfJkCvvbnQV+wT_Bu zs%+wR+2BhY(`0K2UMBD@j`nJk@{`A&9AdWXId(1h_%Oak!tHlQi~!?}73}GsgvrL_%jhDaR5PMDRiCnZCBh5qD{1Fz!V;745`QsYcjU=9FMyHaO7iL;cRjcA zZ%H8~Sz@fuiWhk%lFc|*ibSN^Ns}PLyU0)pD8G)2vY)a zQWSjm8MR3S_WSUUA$Y1X8EC6Myg=Wab7dqatvoldL`jr%u0=T+K(Se zCL%miC=r@(8tEY15A-~Y-u8GClM^~96ZNzt zLd}#AO(8_MdLA==6S~oJ%!36;3c?Cdwk_0PGO=y48QvQ`kW8kXBVMUMF^B>MCUhnR z5N&`wHY|D*s4$R6BMDAegz;hMs|1^qrywf*jH)6H@RcwJO=kuw+sd^(|=Z4{FviM@WEAgd~+d0&=wto&BMv zUWf${&p|^f!G(*+T}8eXw)!S@5#pQGd3z{jtOZG@RU6dkIPR^J>r>dw!+8T`U`D`lP@quyGT)i>MJ^Zlz5o znV0SN0w=`CMQ=MK)1(PFXi%X|sR0OWLYIpDJXLr~Urf&Eq=DAZYglow0?v@*otMLO z(?$#tV*<$N1q1?0mxCClv>Lk&g0O2;O2hD)rW?B>I!pX3$-G`fk(_H9CLKVyHokXa zEnnK00UrWaHFAKLFENUt7l~*Fw1o3R045V(Xi%dMl}6>%NFj3SNnWwgN3VI#Oy?D| zioHZbS#nlodahE=*mL0IA@gEsfv6fhqDox@eC+`30s_YTA!OT@O4@%PX+TaZ{Ag7! zt;h6hoi}Yzyr_w$o;&!|ZDJC2u1)w+4+zS#*6){kQiTxJZAf)vk3<_Ve&cI%s*a zwV4Qpbs{9_+AG4s1^oo~n7OFbKJ4+-3#HM5Fai>3%YM|ju3WDMaL9D3$3sn)(g20( z+>X&IL~5tm-vrzNNvV5Lk=W0?F`(1%6w(-8Bjg#>a=jn*wn$lFbZ|u*3vq5xt8R}l ypa$2vTi2rXI>w~)Bl~#zw%a_+-fwriyPr(^Ymf7L{ddFTyZ-?X+&k`E5&!@lTzNeJ literal 0 HcmV?d00001 diff --git a/test/unit/images/logo.svgz b/test/unit/images/logo.svgz new file mode 100644 index 0000000000000000000000000000000000000000..62bfce6524506f80d50751eea3e1f7c3d859938b GIT binary patch literal 2328 zcmV+z3Fr17iwFqd=1N@v18i?+Z!U9oXLMoBFY_`Rj;G~*z1$u4n}^x{F#GxO-Tm>)hj+s;aCm>bTdy8wA5W)G zcZ;)ouIgd9yrizid{Ar>DdI*iP<`KfT)g zyncV({qpiMz4*4t)>;?FEu5RPV}AU$KP|t`-yX%rA02hZm<8W%JO6aom+j`|uZOP> zGc%YW`!vMp+J}#u?T3%2huLNQvR$7(KFrwC&)wo`n_#+o$D+ zjXe1azTPixAKq*}efzYzUD~gG-W(5~pI4h7CU?Dh+Un5aU#IPE_jf6o4U6wC-JW)v z$ELIYym+xVyK#1M@yg5l#U%!9wcflx-om3*I;*+=v^;&hebOpeUuIpTSPrhbDaLH< z7>u7PKjN?&=GGz|=V?lzx?%3@luJfn9Y1XJi1;OepOVYL4m%EY$rOFAaWMR}W^y%H z_jchY$38cC0GiNty?pXuwhSn-$%Q)3^Au8yX>firF-G6@#Z)5tY@G_ypsTqtl{#=| zETN2M3egmK;wN8Hibzt(VF+>Z&bctUFqLe49YW%)!yuQYY*QFG>k9EOQwcR@tTV>D z(Q?uUA6dIx+~_f~l;*gZ;^?KoqX7e5ut~Q6AA#Y*GAe);4S!sgYHg2C@ZYcHqn#4r zDJ>a3S+5A%sgzQaGL~z}c2Ih(^KBF9El2_}v?VoBaj6tccM~qfJkCvvbnQV+wT_Bu zs%+wR+2BhY(`0K2UMBD@j`nJk@{`A&9AdWXId(1h_%Oak!tHlQi~!?}73}GsgvrL_%jhDaR5PMDRiCnZCBh5qD{1Fz!V;745`QsYcjU=9FMyHaO7iL;cRjcA zZ%H8~Sz@fuiWhk%lFc|*ibSN^Ns}PLyU0)pD8G)2vY)a zQWSjm8MR3S_WSUUA$Y1X8EC6Myg=Wab7dqatvoldL`jr%u0=T+K(Se zCL%miC=r@(8tEY15A-~Y-u8GClM^~96ZNzt zLd}#AO(8_MdLA==6S~oJ%!36;3c?Cdwk_0PGO=y48QvQ`kW8kXBVMUMF^B>MCUhnR z5N&`wHY|D*s4$R6BMDAegz;hMs|1^qrywf*jH)6H@RcwJO=kuw+sd^(|=Z4{FviM@WEAgd~+d0&=wto&BMv zUWf${&p|^f!G(*+T}8eXw)!S@5#pQGd3z{jtOZG@RU6dkIPR^J>r>dw!+8T`U`D`lP@quyGT)i>MJ^Zlz5o znV0SN0w=`CMQ=MK)1(PFXi%X|sR0OWLYIpDJXLr~Urf&Eq=DAZYglow0?v@*otMLO z(?$#tV*<$N1q1?0mxCClv>Lk&g0O2;O2hD)rW?B>I!pX3$-G`fk(_H9CLKVyHokXa zEnnK00UrWaHFAKLFENUt7l~*Fw1o3R045V(Xi%dMl}6>%NFj3SNnWwgN3VI#Oy?D| zioHZbS#nlodahE=*mL0IA@gEsfv6fhqDox@eC+`30s_YTA!OT@O4@%PX+TaZ{Ag7! zt;h6hoi}Yzyr_w$o;&!|ZDJC2u1)w+4+zS#*6){kQiTxJZAf)vk3<_Ve&cI%s*a zwV4Qpbs{9_+AG4s1^oo~n7OFbKJ4+-3#HM5Fai>3%YM|ju3WDMaL9D3$3sn)(g20( z+>X&IL~5tm-vrzNNvV5Lk=W0?F`(1%6w(-8Bjg#>a=jn*wn$lFbZ|u*3vq5xt8R}l ypa$2vTi2rXI>w~)Bl~#zw%a_+-fwriyPr(^Ymf7L{ddFTyZ-?X+&k`E5&!@lTzNeJ literal 0 HcmV?d00001 diff --git a/test/unit/index.html b/test/unit/index.html index 3de601a3b..e05c8c718 100644 --- a/test/unit/index.html +++ b/test/unit/index.html @@ -104,6 +104,8 @@ print: (stdout) => console.log(stdout.replace(/\033\[[0-9;]*m/g, "")), // Uncomment to disable dynamic modules // dynamicLibraries: [], + // Test all available dynamic modules + dynamicLibraries: ['vips-jxl.wasm', 'vips-heif.wasm', 'vips-resvg.wasm'], preRun: (module) => { module.setAutoDeleteLater(true); module.setDelayFunction(fn => { diff --git a/test/unit/node-helper.js b/test/unit/node-helper.js index 2bb9b65d4..9c91a5421 100644 --- a/test/unit/node-helper.js +++ b/test/unit/node-helper.js @@ -12,6 +12,9 @@ export async function mochaGlobalSetup () { // Uncomment to disable dynamic modules // dynamicLibraries: [], preRun: (module) => { + // Ensure we also test the vips-resvg dynamic module + module.dynamicLibraries.push('../vips-resvg.wasm'); + module.setAutoDeleteLater(true); module.setDelayFunction(fn => { globalThis.cleanup = fn; diff --git a/test/unit/test_foreign.js b/test/unit/test_foreign.js index a3878b4c2..374f8d6d2 100644 --- a/test/unit/test_foreign.js +++ b/test/unit/test_foreign.js @@ -16,6 +16,7 @@ describe('foreign', () => { jpegload: file => vips.Image.jpegload(file), jxlload: file => vips.Image.jxlload(file), heifload: file => vips.Image.heifload(file), + svgload: file => vips.Image.svgload(file), pngload: file => vips.Image.pngload(file), webpload: file => vips.Image.webpload(file), tiffload: file => vips.Image.tiffload(file), @@ -27,6 +28,7 @@ describe('foreign', () => { jpegload_buffer: buffer => vips.Image.jpegloadBuffer(buffer), jxlload_buffer: buffer => vips.Image.jxlloadBuffer(buffer), heifload_buffer: buffer => vips.Image.heifloadBuffer(buffer), + svgload_buffer: buffer => vips.Image.svgloadBuffer(buffer), pngload_buffer: buffer => vips.Image.pngloadBuffer(buffer), webpload_buffer: buffer => vips.Image.webploadBuffer(buffer), tiffload_buffer: buffer => vips.Image.tiffloadBuffer(buffer), @@ -861,6 +863,63 @@ describe('foreign', () => { saveBufferTempfile('radsave_buffer', '.hdr', rad, 0); }); + it('svgload', function () { + // Needs SVG load support + if (!Helpers.have('svgload')) { + return this.skip(); + } + + const svgValid = (im) => { + const a = im.getpoint(10, 10); + Helpers.assertAlmostEqualObjects(a, [0, 0, 0, 0]); + expect(im.width).to.equal(736); + expect(im.height).to.equal(552); + expect(im.bands).to.equal(4); + }; + + fileLoader('svgload', Helpers.svgFile, svgValid); + bufferLoader('svgload_buffer', Helpers.svgFile, svgValid); + + // FIXME(kleisauke): resvg doesn't seem to support gzip compressed SVG images. + /* fileLoader('svgload', Helpers.svgzFile, svgValid); + bufferLoader('svgload_buffer', Helpers.svgzFile, svgValid); + + fileLoader('svgload', Helpers.svgGzFile, svgValid); + + let im = vips.Image.newFromFile(Helpers.svgzFile); + let x = vips.Image.newFromFile(Helpers.svgzFile, { scale: 2 }); + expect(Math.abs(im.width * 2 - x.width)).to.be.below(2); + expect(Math.abs(im.height * 2 - x.height)).to.be.below(2); + + im = vips.Image.newFromFile(Helpers.svgzFile); + x = vips.Image.newFromFile(Helpers.svgzFile, { dpi: 144 }); + expect(Math.abs(im.width * 2 - x.width)).to.be.below(2); + expect(Math.abs(im.height * 2 - x.height)).to.be.below(2); */ + + Helpers.expectCppException(() => { + const svg = ''; + vips.Image.newFromBuffer(svg, ''); + }).to.throw('failed to parse SVG data'); + + // FIXME(kleisauke): Doesn't seem to work with resvg. + // recognize dimensions for SVGs without width/height + /* let svg = ''; + im = vips.Image.newFromBuffer(svg, ''); + expect(im.width).to.equal(100); + expect(im.height).to.equal(100); + + svg = ''; + im = vips.Image.newFromBuffer(svg, ''); + expect(im.width).to.equal(100); + expect(im.height).to.equal(100); + + // width and height of 0.5 is valid + svg = ''; + im = vips.Image.newFromBuffer(svg, ''); + expect(im.width).to.equal(1); + expect(im.height).to.equal(1); */ + }); + it('heifload', function () { // Needs AVIF load support if (!Helpers.have('heifload')) { From 2eed1c3daa034fcebf23aadc50b41aba11862348 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 17 Jan 2023 19:49:54 +0100 Subject: [PATCH 21/39] Ensure `vips-resvg.wasm` module is distributed --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1eb79c869..3577826cc 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "lib/vips.d.ts", "lib/vips.wasm", "lib/vips-heif.wasm", - "lib/vips-jxl.wasm" + "lib/vips-jxl.wasm", + "lib/vips-resvg.wasm" ], "scripts": { "build": "docker build -t wasm-vips . && docker run -it --rm -v $(pwd):/src wasm-vips ./build.sh", From 49e233d954e16a21ba691cc9109d632cd8bf6d18 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 17 Jan 2023 20:29:21 +0100 Subject: [PATCH 22/39] Add support for gzip compressed SVG images --- build.sh | 3 ++- test/unit/test_foreign.js | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 597bef584..c9c0c36c3 100755 --- a/build.sh +++ b/build.sh @@ -498,7 +498,8 @@ node --version ${ENABLE_MODULES:+-Dmodules=enabled} -Dcgif=enabled -Dexif=enabled ${ENABLE_AVIF:+-Dheif=enabled} \ -Dheif-module=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \ -Djpeg-xl-module=enabled -Dlcms=enabled ${ENABLE_SVG:+-Dresvg=enabled} -Dresvg-module=enabled \ - -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true -Dppm=true -Danalyze=true -Dradiance=true + -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true -Dppm=true -Danalyze=true -Dradiance=true \ + -Dzlib=enabled meson install -C _build --tag runtime,devel # Emscripten requires linking to side modules to find the necessary symbols to export module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1) diff --git a/test/unit/test_foreign.js b/test/unit/test_foreign.js index 374f8d6d2..fed2cb311 100644 --- a/test/unit/test_foreign.js +++ b/test/unit/test_foreign.js @@ -880,8 +880,7 @@ describe('foreign', () => { fileLoader('svgload', Helpers.svgFile, svgValid); bufferLoader('svgload_buffer', Helpers.svgFile, svgValid); - // FIXME(kleisauke): resvg doesn't seem to support gzip compressed SVG images. - /* fileLoader('svgload', Helpers.svgzFile, svgValid); + fileLoader('svgload', Helpers.svgzFile, svgValid); bufferLoader('svgload_buffer', Helpers.svgzFile, svgValid); fileLoader('svgload', Helpers.svgGzFile, svgValid); @@ -894,7 +893,7 @@ describe('foreign', () => { im = vips.Image.newFromFile(Helpers.svgzFile); x = vips.Image.newFromFile(Helpers.svgzFile, { dpi: 144 }); expect(Math.abs(im.width * 2 - x.width)).to.be.below(2); - expect(Math.abs(im.height * 2 - x.height)).to.be.below(2); */ + expect(Math.abs(im.height * 2 - x.height)).to.be.below(2); Helpers.expectCppException(() => { const svg = ''; From a23b339f3567e1f743ed293e86f6e8566b4d1dac Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 18 Jan 2023 11:07:14 +0100 Subject: [PATCH 23/39] Revise Dockerfile --- Dockerfile | 54 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 56b3361ff..417e9122e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,25 @@ # https://github.com/emscripten-core/emsdk FROM docker.io/emscripten/emsdk:3.1.29 -ENV RUSTUP_TOOLCHAIN=nightly-2023-01-12 +# Path settings +ENV \ + RUSTUP_HOME="/usr/local/rustup" \ + PATH="/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -ENV PATH=$EMSDK:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/root/.rustup/toolchains/$RUSTUP_TOOLCHAIN-x86_64-unknown-linux-gnu/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ - # Enable Emscripten sysroot cache - EM_CACHE=/src/build/emcache \ - # Enable Rust cache - CARGO_HOME="/src/build/cargo-cache" \ - # Enable ccache - CCACHE_DIR=/src/build/ccache \ - _EMCC_CCACHE=1 +# Cache settings +ENV \ + # Enable Emscripten sysroot cache + EM_CACHE="/src/build/emcache" \ + # Enable Rust cache + CARGO_HOME="/src/build/cargo-cache" \ + # Enable ccache + CCACHE_DIR="/src/build/ccache" \ + _EMCC_CCACHE=1 -RUN apt-get update \ - && curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \ - && apt-get install -qqy \ +RUN \ + apt-get update && \ + curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ + apt-get install -qqy \ autoconf \ build-essential \ ccache \ @@ -25,14 +30,25 @@ RUN apt-get update \ # needed for Meson ninja-build \ python3-pip \ + && \ + curl https://sh.rustup.rs -sSf | sh -s -- -y \ + --no-modify-path \ + --profile minimal \ + --target wasm32-unknown-emscripten \ + --default-toolchain nightly \ + --component rust-src \ + && \ # https://github.com/mesonbuild/meson/pull/10969 - && pip3 install git+https://github.com/kleisauke/meson@wasm-vips \ + pip3 install git+https://github.com/kleisauke/meson@wasm-vips && \ # Prefer the default system-installed version of Node.js - && echo "NODE_JS = '$(which node)'" >> $EMSDK/.emscripten + echo "NODE_JS = '$(which node)'" >> $EMSDK/.emscripten -RUN curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:wasm-vips-3.1.29.patch | patch -p1 -d /emsdk/upstream/emscripten && \ - curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:dylink-deno-compat.patch | patch -p1 -d /emsdk/upstream/emscripten && \ - emcc --clear-cache && embuilder build sysroot --force +# Emscripten patches +RUN \ + curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:wasm-vips-3.1.29.patch | patch -p1 -d $EMSDK/upstream/emscripten && \ + curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.29...kleisauke:dylink-deno-compat.patch | patch -p1 -d $EMSDK/upstream/emscripten && \ + emcc --clear-cache && embuilder build sysroot --force -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten --default-toolchain $RUSTUP_TOOLCHAIN --component rust-src -RUN curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d /root/.rustup/toolchains/$RUSTUP_TOOLCHAIN-x86_64-unknown-linux-gnu/lib/rustlib/src/rust +# Rust patches +RUN \ + curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d $RUSTUP_HOME/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust From 94e67b1617fc096d2a65b64f4243a7b64f5f4559 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 18 Jan 2023 11:10:39 +0100 Subject: [PATCH 24/39] Patch Rust to avoid /dev/urandom usage See: https://github.com/kleisauke/rust/commit/c705a6a9b68b0262a01ddc50d80fbf8571580cfc https://github.com/kleisauke/libc/commit/dc597aff818dd32856758feab0d9c530d15985c4 --- Dockerfile | 8 +++++++- build.sh | 17 +++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 417e9122e..1e5798539 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,4 +51,10 @@ RUN \ # Rust patches RUN \ - curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d $RUSTUP_HOME/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust + curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust && \ + curl -Ls https://github.com/kleisauke/rust/commit/c705a6a9b68b0262a01ddc50d80fbf8571580cfc.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust + +# Copy the Cargo.lock for Rust to places `vendor` will see +# https://github.com/rust-lang/wg-cargo-std-aware/issues/23#issuecomment-720455524 +RUN \ + cp $(rustc --print sysroot)/lib/rustlib/src/rust/Cargo.lock $(rustc --print sysroot)/lib/rustlib/src/rust/library/test diff --git a/build.sh b/build.sh index c9c0c36c3..c16cfa7bf 100755 --- a/build.sh +++ b/build.sh @@ -427,13 +427,18 @@ node --version stage "Compiling resvg" mkdir -p $DEPS/resvg curl -Ls https://github.com/RazrFalcon/resvg/releases/download/v$VERSION_RESVG/resvg-$VERSION_RESVG.tar.xz | tar xJC $DEPS/resvg --strip-components=1 - cd $DEPS/resvg/c-api - # Vendor dir doesn't work with -Zbuild-std right now due to https://github.com/rust-lang/wg-cargo-std-aware/issues/23 - # Just delete the config so that all deps are downloaded off the internet. - rm ../.cargo/config + cd $DEPS/resvg + # Allow building vendored sources with `-Zbuild-std`, see: + # https://github.com/rust-lang/wg-cargo-std-aware/issues/23#issuecomment-720455524 + cargo vendor -s $(rustc --print sysroot)/lib/rustlib/src/rust/library/test/Cargo.toml + # Patch libc + curl -Ls https://github.com/kleisauke/libc/commit/dc597aff818dd32856758feab0d9c530d15985c4.patch | patch -p1 -d vendor/libc + # Update expected Cargo SHA256 hashes for the vendored files we have patched + sed -i 's/6ef4652dfb94e3c58aed5133ece982ad30569d46b6b1054552cd61905fa61690/8ff63140fc57d10a185f0883d02564d08c93120dcbbaa0410f753154efde3a71/' vendor/libc/.cargo-checksum.json # We don't want to build the shared library - sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' Cargo.toml - cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images + sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' c-api/Cargo.toml + cargo build --manifest-path=c-api/Cargo.toml --release --target wasm32-unknown-emscripten --locked \ + -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ ) From 54bce444a611966e885b053b90f57598b8af2eb1 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 23 Jan 2023 10:32:43 +0100 Subject: [PATCH 25/39] SVG namespace is mandatory in resvg --- test/unit/test_foreign.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/unit/test_foreign.js b/test/unit/test_foreign.js index 0ae867fcb..b3a501d3e 100644 --- a/test/unit/test_foreign.js +++ b/test/unit/test_foreign.js @@ -896,27 +896,26 @@ describe('foreign', () => { expect(Math.abs(im.height * 2 - x.height)).to.be.below(2); expect(() => { - const svg = ''; + const svg = ''; vips.Image.newFromBuffer(svg, ''); - }).to.throw('failed to parse SVG data'); + }).to.throw('SVG doesn\'t have a valid size'); - // FIXME(kleisauke): Doesn't seem to work with resvg. // recognize dimensions for SVGs without width/height - /* let svg = ''; + let svg = ''; im = vips.Image.newFromBuffer(svg, ''); expect(im.width).to.equal(100); expect(im.height).to.equal(100); - svg = ''; + svg = ''; im = vips.Image.newFromBuffer(svg, ''); expect(im.width).to.equal(100); expect(im.height).to.equal(100); // width and height of 0.5 is valid - svg = ''; + svg = ''; im = vips.Image.newFromBuffer(svg, ''); expect(im.width).to.equal(1); - expect(im.height).to.equal(1); */ + expect(im.height).to.equal(1); }); it('heifload', function () { From 80d1458acd079c6e0c69bd10deea7d48e2e334a3 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 23 Jan 2023 15:09:11 +0100 Subject: [PATCH 26/39] Simplify libc patching --- Dockerfile | 7 +++---- build.sh | 12 ++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 61e3ee497..0c9e3c400 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,9 +51,8 @@ RUN \ # Rust patches RUN \ curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust && \ - curl -Ls https://github.com/kleisauke/rust/commit/c705a6a9b68b0262a01ddc50d80fbf8571580cfc.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust + curl -Ls https://github.com/rust-lang/rust/pull/107221.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust -# Copy the Cargo.lock for Rust to places `vendor` will see -# https://github.com/rust-lang/wg-cargo-std-aware/issues/23#issuecomment-720455524 +# https://github.com/rust-lang/libc/pull/3087 RUN \ - cp $(rustc --print sysroot)/lib/rustlib/src/rust/Cargo.lock $(rustc --print sysroot)/lib/rustlib/src/rust/library/test + sed -i 's|version = "0.2.138"|git = "https://github.com/kleisauke/libc", branch = "getentropy-emscripten"|' $(rustc --print sysroot)/lib/rustlib/src/rust/library/std/Cargo.toml diff --git a/build.sh b/build.sh index c16cfa7bf..4a7960a0d 100755 --- a/build.sh +++ b/build.sh @@ -428,15 +428,11 @@ node --version mkdir -p $DEPS/resvg curl -Ls https://github.com/RazrFalcon/resvg/releases/download/v$VERSION_RESVG/resvg-$VERSION_RESVG.tar.xz | tar xJC $DEPS/resvg --strip-components=1 cd $DEPS/resvg - # Allow building vendored sources with `-Zbuild-std`, see: - # https://github.com/rust-lang/wg-cargo-std-aware/issues/23#issuecomment-720455524 - cargo vendor -s $(rustc --print sysroot)/lib/rustlib/src/rust/library/test/Cargo.toml - # Patch libc - curl -Ls https://github.com/kleisauke/libc/commit/dc597aff818dd32856758feab0d9c530d15985c4.patch | patch -p1 -d vendor/libc - # Update expected Cargo SHA256 hashes for the vendored files we have patched - sed -i 's/6ef4652dfb94e3c58aed5133ece982ad30569d46b6b1054552cd61905fa61690/8ff63140fc57d10a185f0883d02564d08c93120dcbbaa0410f753154efde3a71/' vendor/libc/.cargo-checksum.json + # Vendor dir doesn't work with -Zbuild-std due to https://github.com/rust-lang/wg-cargo-std-aware/issues/23 + # Just delete the config so that all deps are downloaded from the internet + rm .cargo/config # We don't want to build the shared library - sed -i 's/crate-type = .*/crate-type = ["staticlib"]/' c-api/Cargo.toml + sed -i '/^crate-type =/s/"cdylib", //' c-api/Cargo.toml cargo build --manifest-path=c-api/Cargo.toml --release --target wasm32-unknown-emscripten --locked \ -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ From f73d9630aaf56ee4dfb27aa19b7d7ad95a22a614 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 23 Jan 2023 15:10:27 +0100 Subject: [PATCH 27/39] nit: re-order `VERSION_*` vars --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 4a7960a0d..793708018 100755 --- a/build.sh +++ b/build.sh @@ -205,9 +205,9 @@ VERSION_IMAGEQUANT=2.4.1 # https://github.com/lovell/libimagequant VERSION_CGIF=0.3.0 # https://github.com/dloebl/cgif VERSION_WEBP=1.2.4 # https://chromium.googlesource.com/webm/libwebp VERSION_TIFF=4.5.0 # https://gitlab.com/libtiff/libtiff +VERSION_RESVG=0.28.0 # https://github.com/RazrFalcon/resvg VERSION_AOM=3.5.0 # https://aomedia.googlesource.com/aom VERSION_HEIF=1.14.2 # https://github.com/strukturag/libheif -VERSION_RESVG=0.28.0 # https://github.com/RazrFalcon/resvg VERSION_VIPS=8.13.3 # https://github.com/libvips/libvips # Remove patch version component From 4c3976712d76cf3fb7ddcc973389e6637cf938a2 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 23 Jan 2023 15:48:07 +0100 Subject: [PATCH 28/39] Prefer relative paths --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 793708018..ed6c09576 100755 --- a/build.sh +++ b/build.sh @@ -435,8 +435,8 @@ node --version sed -i '/^crate-type =/s/"cdylib", //' c-api/Cargo.toml cargo build --manifest-path=c-api/Cargo.toml --release --target wasm32-unknown-emscripten --locked \ -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images - cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ - cp $DEPS/resvg/c-api/resvg.h $TARGET/include/ + cp target/wasm32-unknown-emscripten/release/libresvg.a $TARGET/lib/ + cp c-api/resvg.h $TARGET/include/ ) [ -f "$TARGET/lib/pkgconfig/aom.pc" ] || [ -n "$DISABLE_AVIF" ] || ( From c2b9b03367e014fbeab8604d4ee704527db6bb46 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 24 Jan 2023 10:58:58 +0100 Subject: [PATCH 29/39] Fix build with `--disable-svg` --- build.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index ed6c09576..a37b6eded 100755 --- a/build.sh +++ b/build.sh @@ -488,10 +488,8 @@ node --version else sed -i "/subdir('cplusplus')/d" meson.build fi - if [ -n "$ENABLE_SVG" ]; then - # resvg patch - curl -Ls https://github.com/kleisauke/libvips/compare/wasm-vips...RReverser-wasm-vips-resvg.patch | patch -p1 - fi + # resvg patch + curl -Ls https://github.com/kleisauke/libvips/compare/wasm-vips...RReverser-wasm-vips-resvg.patch | patch -p1 # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \ From b7c89ebe4025bbf7122f9e96ed0fb1ae0f41d45c Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 24 Jan 2023 11:17:51 +0100 Subject: [PATCH 30/39] Pin Rust nightly to 2023-01-24 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0c9e3c400..48907b063 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/emscripten/emsdk:3.1.30 # Path settings ENV \ RUSTUP_HOME="/usr/local/rustup" \ - PATH="/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + PATH="/usr/local/rustup/toolchains/nightly-2023-01-24-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Cache settings ENV \ @@ -35,7 +35,7 @@ RUN \ --no-modify-path \ --profile minimal \ --target wasm32-unknown-emscripten \ - --default-toolchain nightly \ + --default-toolchain nightly-2023-01-24 \ --component rust-src \ && \ # https://github.com/mesonbuild/meson/pull/10969 From cdad4511d649bcb0f89ab7b85dd24af54d4dcd85 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 24 Jan 2023 14:00:11 +0100 Subject: [PATCH 31/39] Remove Rust build path prefixes from the binaries --- build.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.sh b/build.sh index a37b6eded..ac94c0c2e 100755 --- a/build.sh +++ b/build.sh @@ -189,6 +189,13 @@ export MESON_CROSS="$SOURCE_DIR/build/emscripten-crossfile.meson" # Run as many parallel jobs as there are available CPU cores export MAKEFLAGS="-j$(nproc)" +# Ensure Rust build path prefixes are removed from the resulting binaries +# https://reproducible-builds.org/docs/build-path/ +# TODO(kleisauke): Switch to -Ctrim-paths=all once supported - https://github.com/rust-lang/rfcs/pull/3127 +export RUSTFLAGS+=" --remap-path-prefix=$(rustc --print sysroot)/lib/rustlib/src/rust/library/=" +export RUSTFLAGS+=" --remap-path-prefix=$CARGO_HOME/registry/src/=" +export RUSTFLAGS+=" --remap-path-prefix=$DEPS/=" + # Dependency version numbers VERSION_ZLIBNG=2.0.6 # https://github.com/zlib-ng/zlib-ng VERSION_FFI=3.4.4 # https://github.com/libffi/libffi From 3168aa38e09e86aeed17b9df779fdb386b7a797e Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 24 Jan 2023 14:04:27 +0100 Subject: [PATCH 32/39] Update after merge of kleisauke/libvips#2 --- build.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.sh b/build.sh index ac94c0c2e..d45491c28 100755 --- a/build.sh +++ b/build.sh @@ -495,8 +495,6 @@ node --version else sed -i "/subdir('cplusplus')/d" meson.build fi - # resvg patch - curl -Ls https://github.com/kleisauke/libvips/compare/wasm-vips...RReverser-wasm-vips-resvg.patch | patch -p1 # Disable building man pages, gettext po files, tools, and (fuzz-)tests sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \ From ac8497e5e2d94a1342f6aa7bc317b050593ede3b Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 26 Jan 2023 14:23:12 +0100 Subject: [PATCH 33/39] Update Rust and associated patches --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 48907b063..268dada9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/emscripten/emsdk:3.1.30 # Path settings ENV \ RUSTUP_HOME="/usr/local/rustup" \ - PATH="/usr/local/rustup/toolchains/nightly-2023-01-24-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + PATH="/usr/local/rustup/toolchains/nightly-2023-01-26-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Cache settings ENV \ @@ -35,7 +35,7 @@ RUN \ --no-modify-path \ --profile minimal \ --target wasm32-unknown-emscripten \ - --default-toolchain nightly-2023-01-24 \ + --default-toolchain nightly-2023-01-26 \ --component rust-src \ && \ # https://github.com/mesonbuild/meson/pull/10969 @@ -50,9 +50,9 @@ RUN \ # Rust patches RUN \ - curl -Ls https://github.com/rust-lang/rust/pull/106779.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust && \ + curl -Ls https://github.com/rust-lang/rust/commit/cc92bdb9c99b944b77833f3f2cd0e362c94bf861.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust && \ curl -Ls https://github.com/rust-lang/rust/pull/107221.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust -# https://github.com/rust-lang/libc/pull/3087 +# https://github.com/rust-lang/libc/commit/1df1e22876c36b3c00de679e9a57226f12c8f266 RUN \ - sed -i 's|version = "0.2.138"|git = "https://github.com/kleisauke/libc", branch = "getentropy-emscripten"|' $(rustc --print sysroot)/lib/rustlib/src/rust/library/std/Cargo.toml + sed -i 's|version = "0.2.138"|git = "https://github.com/rust-lang/libc", branch = "master"|' $(rustc --print sysroot)/lib/rustlib/src/rust/library/std/Cargo.toml From 390597f7383b838acbbd747449f5494ee9a2b3ed Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 29 Jan 2023 13:48:05 +0100 Subject: [PATCH 34/39] Add sample SVG image to playground --- playground/samples/filter/duotone/sample.js | 1 + playground/src/images/INFO.md | 5 +++++ playground/src/images/alphachannel.svg | 5 +++++ playground/src/playground-runner.html | 7 ++++++- playground/src/samples.js | 1 + 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 playground/src/images/alphachannel.svg diff --git a/playground/samples/filter/duotone/sample.js b/playground/samples/filter/duotone/sample.js index 25f586a70..390483fd9 100644 --- a/playground/samples/filter/duotone/sample.js +++ b/playground/samples/filter/duotone/sample.js @@ -22,6 +22,7 @@ let im = vips.Image.newFromFile('owl.jpg'); // let im = vips.Image.newFromFile('owl.tif'); // let im = vips.Image.newFromFile('owl.jxl'); // let im = vips.Image.newFromFile('owl.avif'); +// let im = vips.Image.newFromFile('alphachannel.svg'); // let im = vips.Image.newFromFile('transparency_demo.png'); // let im = vips.Image.newFromFile('banana.webp', { n: -1 }); // let im = vips.Image.newFromFile('banana.gif', { n: -1 }); diff --git a/playground/src/images/INFO.md b/playground/src/images/INFO.md index c36bf2b90..8560a8ebb 100644 --- a/playground/src/images/INFO.md +++ b/playground/src/images/INFO.md @@ -25,6 +25,11 @@ vips copy owl.jpg owl.jxl vips copy owl.jpg owl.avif[effort=9] ``` +[`alphachannel.svg`](alphachannel.svg): +``` +https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/alphachannel.svg +``` + [`transparency_demo.png`](transparency_demo.png): ``` https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png diff --git a/playground/src/images/alphachannel.svg b/playground/src/images/alphachannel.svg new file mode 100644 index 000000000..be7bf45d0 --- /dev/null +++ b/playground/src/images/alphachannel.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/playground/src/playground-runner.html b/playground/src/playground-runner.html index 894efcf0e..ca1f199fe 100644 --- a/playground/src/playground-runner.html +++ b/playground/src/playground-runner.html @@ -68,7 +68,12 @@ // module.ENV.VIPS_LEAK = '1'; // Preload playground files - for (const image of ['owl.jpg', 'owl.tif', 'owl.webp', 'owl.jxl', 'owl.avif', 'banana.webp', 'banana.gif', 'transparency_demo.png']) + const images = [ + 'owl.jpg', 'owl.tif', 'owl.webp', 'owl.jxl', 'owl.avif', + 'banana.webp', 'banana.gif', + 'alphachannel.svg', 'transparency_demo.png' + ]; + for (const image of images) module.FS.createPreloadedFile('/', image, 'assets/images/' + image, true, false); }, postRun: (module) => { diff --git a/playground/src/samples.js b/playground/src/samples.js index de1757b5d..47ebc4332 100644 --- a/playground/src/samples.js +++ b/playground/src/samples.js @@ -5,6 +5,7 @@ import './images/owl.jxl'; import './images/owl.avif'; import './images/banana.webp'; import './images/banana.gif'; +import './images/alphachannel.svg'; import './images/transparency_demo.png'; export const playSamples = [ From 1511222f08e08f9edb1caab27ade78791e74ab8d Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 29 Jan 2023 13:51:47 +0100 Subject: [PATCH 35/39] Playground: improve dynamic modules support Remove `?disableModules` in favor of `?modules=`, for example: `?modules=jxl,heif,svg` or `?modules=`, etc. --- playground/src/playground-runner.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/playground/src/playground-runner.html b/playground/src/playground-runner.html index ca1f199fe..dfcff6b68 100644 --- a/playground/src/playground-runner.html +++ b/playground/src/playground-runner.html @@ -109,9 +109,15 @@ } }; - // Disable dynamic modules whenever the ?disableModules query string is passed - if (document.referrer.includes('disableModules')) { - options.dynamicLibraries = []; + // Control the dynamic modules via the ?modules= query string + const params = new URL(document.referrer).searchParams; + if (params.has('modules')) { + const enabledModules = params.get('modules').split(',').filter(e => e); + options.dynamicLibraries = [ + 'vips-jxl.wasm', // enabled by default + 'vips-heif.wasm', // enabled by default + 'vips-resvg.wasm' // disabled by default + ].filter(m => enabledModules.some(e => m.includes(e))); } globalThis.vips = await Vips(options); From 3563202bb6b3517099e217f9cc6535cc1cd080cb Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 29 Jan 2023 13:53:28 +0100 Subject: [PATCH 36/39] Update Rust and associated patches --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 268dada9b..1bee4ec22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/emscripten/emsdk:3.1.30 # Path settings ENV \ RUSTUP_HOME="/usr/local/rustup" \ - PATH="/usr/local/rustup/toolchains/nightly-2023-01-26-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + PATH="/usr/local/rustup/toolchains/nightly-2023-01-29-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Cache settings ENV \ @@ -35,7 +35,7 @@ RUN \ --no-modify-path \ --profile minimal \ --target wasm32-unknown-emscripten \ - --default-toolchain nightly-2023-01-26 \ + --default-toolchain nightly-2023-01-29 \ --component rust-src \ && \ # https://github.com/mesonbuild/meson/pull/10969 @@ -48,9 +48,8 @@ RUN \ curl -Ls https://github.com/emscripten-core/emscripten/compare/3.1.30...kleisauke:wasm-vips-3.1.30.patch | patch -p1 -d $EMSDK/upstream/emscripten && \ emcc --clear-cache && embuilder build sysroot --force -# Rust patches +# https://github.com/rust-lang/rust/pull/107221 RUN \ - curl -Ls https://github.com/rust-lang/rust/commit/cc92bdb9c99b944b77833f3f2cd0e362c94bf861.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust && \ curl -Ls https://github.com/rust-lang/rust/pull/107221.patch | patch -p1 -d $(rustc --print sysroot)/lib/rustlib/src/rust # https://github.com/rust-lang/libc/commit/1df1e22876c36b3c00de679e9a57226f12c8f266 From 7297186e960d350d1882c7e75c8a478118d276ce Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 30 Jan 2023 11:03:08 +0100 Subject: [PATCH 37/39] Fix testsuite when building with `--disable-modules` --- test/unit/node-helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/node-helper.js b/test/unit/node-helper.js index 9c91a5421..e7e6553d4 100644 --- a/test/unit/node-helper.js +++ b/test/unit/node-helper.js @@ -13,7 +13,7 @@ export async function mochaGlobalSetup () { // dynamicLibraries: [], preRun: (module) => { // Ensure we also test the vips-resvg dynamic module - module.dynamicLibraries.push('../vips-resvg.wasm'); + module.dynamicLibraries?.push('../vips-resvg.wasm'); module.setAutoDeleteLater(true); module.setDelayFunction(fn => { From 39884a349596c49ff5a88b977351e4565c2979ad Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 8 Feb 2023 14:36:14 +0100 Subject: [PATCH 38/39] Update Rust and resvg --- Dockerfile | 4 ++-- build.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb9a886ce..ea394d723 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/emscripten/emsdk:3.1.31 # Path settings ENV \ RUSTUP_HOME="/usr/local/rustup" \ - PATH="/usr/local/rustup/toolchains/nightly-2023-01-29-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + PATH="/usr/local/rustup/toolchains/nightly-2023-02-08-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Cache settings ENV \ @@ -35,7 +35,7 @@ RUN \ --no-modify-path \ --profile minimal \ --target wasm32-unknown-emscripten \ - --default-toolchain nightly-2023-01-29 \ + --default-toolchain nightly-2023-02-08 \ --component rust-src \ && \ # https://github.com/mesonbuild/meson/pull/10969 diff --git a/build.sh b/build.sh index a4fd659ce..bac78be68 100755 --- a/build.sh +++ b/build.sh @@ -212,7 +212,7 @@ VERSION_IMAGEQUANT=2.4.1 # https://github.com/lovell/libimagequant VERSION_CGIF=0.3.0 # https://github.com/dloebl/cgif VERSION_WEBP=1.3.0 # https://chromium.googlesource.com/webm/libwebp VERSION_TIFF=4.5.0 # https://gitlab.com/libtiff/libtiff -VERSION_RESVG=0.28.0 # https://github.com/RazrFalcon/resvg +VERSION_RESVG=0.29.0 # https://github.com/RazrFalcon/resvg VERSION_AOM=3.6.0 # https://aomedia.googlesource.com/aom VERSION_HEIF=1.14.2 # https://github.com/strukturag/libheif VERSION_VIPS=8.13.3 # https://github.com/libvips/libvips From 29069acc31c079aa0c73a3f2e6d7d8dd95e4248d Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 10 Feb 2023 12:32:05 +0100 Subject: [PATCH 39/39] Update Rust --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea394d723..dc00b571e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM docker.io/emscripten/emsdk:3.1.31 # Path settings ENV \ RUSTUP_HOME="/usr/local/rustup" \ - PATH="/usr/local/rustup/toolchains/nightly-2023-02-08-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + PATH="/usr/local/rustup/toolchains/nightly-2023-02-10-x86_64-unknown-linux-gnu/bin:$EMSDK/upstream/emscripten:$EMSDK/upstream/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Cache settings ENV \ @@ -35,7 +35,7 @@ RUN \ --no-modify-path \ --profile minimal \ --target wasm32-unknown-emscripten \ - --default-toolchain nightly-2023-02-08 \ + --default-toolchain nightly-2023-02-10 \ --component rust-src \ && \ # https://github.com/mesonbuild/meson/pull/10969