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

Add SVG support via resvg #40

Merged
merged 41 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2a49dee
Experiment with resvg
RReverser Oct 19, 2022
5d9e24e
Fixups
RReverser Jan 11, 2023
7615359
More fixes for Rust integration
RReverser Jan 11, 2023
bf5104e
Various fixes for Rust
RReverser Jan 11, 2023
5d07bc5
Revert problematic fix
RReverser Jan 12, 2023
3c5866c
Patch Rust with a fix for link issue
RReverser Jan 13, 2023
91069fd
Fix patch path
RReverser Jan 13, 2023
e0346bf
Extract RUSTUP_TOOLCHAIN var
RReverser Jan 13, 2023
66a5d48
Bump libvips+resvg
RReverser Jan 13, 2023
df60d23
Add raster_images feature to SVG
RReverser Jan 14, 2023
c0c6ca0
Bump libvips
RReverser Jan 14, 2023
b0bd521
Rename feature
RReverser Jan 14, 2023
112408d
Use dynamic resvg patch URL
RReverser Jan 14, 2023
330e1f7
Update comment
RReverser Jan 14, 2023
ca18715
Update build.sh
RReverser Jan 14, 2023
2e45045
Update build.sh
RReverser Jan 17, 2023
d3cbd28
Add cargo cache to .gitignore
RReverser Jan 17, 2023
df73ea0
Reorder flags
kleisauke Jan 17, 2023
0982aef
Test build for kleisauke/libvips@349a7b7
kleisauke Jan 17, 2023
7d3c5c5
Port libvips' SVG tests to wasm-vips
kleisauke Jan 17, 2023
2eed1c3
Ensure `vips-resvg.wasm` module is distributed
kleisauke Jan 17, 2023
49e233d
Add support for gzip compressed SVG images
kleisauke Jan 17, 2023
a23b339
Revise Dockerfile
kleisauke Jan 18, 2023
94e67b1
Patch Rust to avoid /dev/urandom usage
kleisauke Jan 18, 2023
8b43d57
Merge branch 'master' into RReverser-libresvg
kleisauke Jan 18, 2023
54bce44
SVG namespace is mandatory in resvg
kleisauke Jan 23, 2023
80d1458
Simplify libc patching
kleisauke Jan 23, 2023
f73d963
nit: re-order `VERSION_*` vars
kleisauke Jan 23, 2023
4c39767
Prefer relative paths
kleisauke Jan 23, 2023
c2b9b03
Fix build with `--disable-svg`
kleisauke Jan 24, 2023
b7c89eb
Pin Rust nightly to 2023-01-24
kleisauke Jan 24, 2023
cdad451
Remove Rust build path prefixes from the binaries
kleisauke Jan 24, 2023
3168aa3
Update after merge of kleisauke/libvips#2
kleisauke Jan 24, 2023
ac8497e
Update Rust and associated patches
kleisauke Jan 26, 2023
390597f
Add sample SVG image to playground
kleisauke Jan 29, 2023
1511222
Playground: improve dynamic modules support
kleisauke Jan 29, 2023
3563202
Update Rust and associated patches
kleisauke Jan 29, 2023
7297186
Fix testsuite when building with `--disable-modules`
kleisauke Jan 30, 2023
a7f8a26
Merge branch 'master'
kleisauke Feb 8, 2023
39884a3
Update Rust and resvg
kleisauke Feb 8, 2023
29069ac
Update Rust
kleisauke Feb 10, 2023
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
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# 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:/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
CARGO_HOME="/src/build/cargo-cache" \
RReverser marked this conversation as resolved.
Show resolved Hide resolved
# Enable ccache
CCACHE_DIR=/src/build/ccache \
_EMCC_CCACHE=1
Expand All @@ -30,3 +33,6 @@ 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 $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
47 changes: 44 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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's incomplete and relatively rarely useful feature.
SVG=false
kleisauke marked this conversation as resolved.
Show resolved Hide resolved

# Build libvips C++ API, disabled by default
LIBVIPS_CPP=false

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -134,17 +143,27 @@ 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"
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+=" -Ctarget-feature=+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
if [ "$SIMD" = "true" ]; then
export CFLAGS+=" -msimd128 -DWASM_SIMD_COMPAT_SLOW"
export RUSTFLAGS+=" -Ctarget-feature=+simd128"
fi
if [ "$WASM_BIGINT" = "true" ]; then
# libffi needs to detect WASM_BIGINT support at compile time
export CFLAGS+=" -DWASM_BIGINT"
Expand Down Expand Up @@ -188,6 +207,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
Expand Down Expand Up @@ -403,6 +423,22 @@ node --version
make install SUBDIRS='libtiff' noinst_PROGRAMS= dist_doc_DATA=
)

[ -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
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
RReverser marked this conversation as resolved.
Show resolved Hide resolved
cargo build --release --target wasm32-unknown-emscripten --locked -Zbuild-std=panic_abort,std --no-default-features --features filter,raster-images
kleisauke marked this conversation as resolved.
Show resolved Hide resolved
cp $DEPS/resvg/target/wasm32-unknown-emscripten/release/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
Expand Down Expand Up @@ -452,13 +488,18 @@ node --version
else
sed -i "/subdir('cplusplus')/d" meson.build
fi
if [ -n "$ENABLE_SVG" ]; then
# resvg patch
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
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_AVIF:+-Dheif=enabled} -Dheif-module=enabled
-Dppm=true -Danalyze=true -Dradiance=true \
${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)
Expand Down