Skip to content

wasm: build the gallery and pycvc-gl with ImageMagick ON, and make it work - #801

Merged
transfix merged 2 commits into
masterfrom
fix/wasm-imagemagick-on
Oct 25, 2026
Merged

transfix merged 2 commits into
masterfrom
fix/wasm-imagemagick-on

Conversation

@transfix

@transfix transfix commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

The wasm builds now use ImageMagick like the native ones, and it actually works at run time. libcvc-examples-web (the gallery) and pycvc-gl-cp312's wasm columns used to configure with CVC_ENABLE_IMAGEMAGICK=OFF. Three separate bugs were in the way.

1. The codec libraries were missing from the link (the reason for OFF)

With the static wasm cvc, any executable failed in wasm-ld on undefined BZ2_* / lzma_* / xml* symbols from libMagickCore (publish-cvcgl-wasm run 35070058005, 2026-09-16).

src/cvc/CMakeLists.txt adds MagickCore's static codec libraries (bz2, lzma, libxml2, tiff, webp, Lerc, …) only on its own fallback lookup. CMake ≥ 3.26's FindImageMagick creates ImageMagick::* targets itself, without those libraries, whenever pkg-config can see MagickCore.pc. A cvcpkg build env exports CMAKE_PREFIX_PATH, which FindPkgConfig turns into a pkg-config search path even under emcmake, so those builds took the stock path and never got the codecs.

The codec list is now added for any static MagickCore (wasm, or a libMagickCore*.a), whichever lookup found it, plus zlib. This is the build-side half of #457, which fixed the consumer side (cvcConfig.cmake.in) the same way.

2. The wasm HDRI define was wrong

When pkg-config gave no answer, the configure kept its Q16 / HDRI=0 defaults. The cvcpkg wasm library is libMagickCore-7.Q16HDRI, and ImageMagick's headers take MAGICKCORE_HDRI_ENABLE only from the compile line. So cvc, and every consumer through cvc's public define, compiled against an integer Quantum while the library uses float. The published libcvc 3.7.0+cvc.1 wasm-mt SDK was built this way: run 39392654078 logs ImageMagick found: … (Q16, HDRI=0). The depth and HDRI flag now come from the library name when pkg-config has nothing.

3. The wasm coder registry was empty at run time

MagickCore creates its coder registry lazily, on the first GetMagickInfo. Until then RegisterMagickInfo silently drops every entry.

magick_io.cpp's wasm-only init called RegisterStaticModules() and the Register*Image() functions straight after InitializeMagick. Every coder was dropped, yet RegisterStaticModules still marked each module as registered, so the lazy path never tried again. Every Magick read and write failed ("no 'TIF' encoder", NoDecodeDelegate). This is the failure stb_io.cpp used to blame on duplicated objects in libMagickCore.a; that comment is corrected.

The init now calls GetMagickInfo("*") first, which creates the registry and registers the static coders into it.

Recipes and CI

  • Recipes: libcvc-examples-web and pycvc-gl-cp312 (build-wasm.sh and .ps1) now build with ImageMagick ON. Both list imagemagick plus its codec bundles as wasm build deps (installs are flat): tiff, libjpeg-turbo, libpng, libwebp, lerc, xz, bzip2 and libxml2.
  • Fail when IM is missing: the configure records CVC_IMAGEMAGICK_ENABLED in the cache. build-wasm-demo.sh and the pycvc-gl wasm scripts now fail when ImageMagick was requested but not found, instead of quietly shipping without it.
  • ci.yml ari-wasm: the job builds ari with ImageMagick ON. It passes CMAKE_PREFIX_PATH, so it takes the exact stock path that broke, and ari's cvc::image::load pulls MagickCore into the link. That makes this job a regression test for (1). It also checks that the configure reports (Q16, HDRI=1).
  • Run-time test, image_magick_roundtrip_test: a plain main() like physics_replay_test, built by CVC_BUILD_IMAGE_MAGICK_ROUNDTRIP, and the ari-wasm job now runs it under node. It checks that every extension magick_image_io advertises has a coder that both decodes and encodes. It then round-trips an RGBA image through TIFF (byte-identical) and WEBP (size); stb handles neither format, so both directions go through Magick. This guards against (3). The job's path filter now also covers src/cvc/image.
  • publish-cvcgl-wasm.yml: fails if the wasm-mt SDK's cvcTargets.cmake does not carry MAGICKCORE_HDRI_ENABLE=1.
  • cvc_revision:
    • libcvc 1 → 3 and cvcgl 1 → 3, together: the wasm-mt SDK changes, and native is already at +cvc.2.
    • pycvc-gl-cp312 1 → 3 (linux is at +cvc.2).
    • libcvc-examples-web 1 → 2 (nothing published yet).

Native builds are unchanged: the codec gate applies only to a static MagickCore, the HDRI inference is skipped on WIN32 and wherever pkg-config answers, and the registry change is __EMSCRIPTEN__-only.

Verification

Local, Windows host, emsdk 5.0.7, catalog wasm deps (imagemagick 7.1.2+cvc.23, vtk 9.5.0+cvc.3), single-threaded, configured like build-wasm-demo.sh with CMAKE_PREFIX_PATH exported:

  • master: terrain_lab.js fails in wasm-ld with undefined BZ2_* / lzma_* / xml* from libMagickCore-7.Q16HDRI.a (blob.o, miff.o, profile.o). Same failure as the 09-16 CI run.
  • this branch:
    • The whole gallery builds and links with ImageMagick: all 12 wasm-demos targets and ari. On this 16 GB Windows host, lsystem_forest's post-link wasm-opt -O3 (ASYNCIFY) pass crashed with 0xC0000409 when it ran beside two other wasm-opt jobs. It needs more than 5 GB, so this is memory exhaustion, not ImageMagick; built on its own, it completes.
    • terrain_lab renders in a browser, and nav_city_swarm starts and runs. The only console errors are the expected "no Austin building bundle" / "no trained weights" fallbacks (scene data was not staged locally).
    • ari passes ci.yml's node snapshot check.
    • The exported cvcTargets.cmake names only ImageMagick::Magick++ / ::MagickCore, with no build-machine paths, and carries MAGICKCORE_HDRI_ENABLE=1.
  • Configure without pkg-config: now reports (Q16, HDRI=1) (master reports HDRI=0), and the codec libraries are on the link line.
  • image_magick_roundtrip_test: passes under node. With init_magick_once's GetMagickInfo("*") call removed it reports 11 failures and exits 1: all nine coders unregistered, and both round trips fail with "no encoder".
  • Runtime: a small program linked against the static cvc writes a 7×5 RGBA image as TIFF and reads it back under node, byte-identical. That path goes through Magick and libtiff; stb cannot read or write TIFF. The registry holds 255 formats after cvc's init; before the fix it held 0.

CI: the ari-wasm job passed on this PR with the stock tier (Found ImageMagick: …libMagick++-7.Q16HDRI.a, (Q16, HDRI=1)), linked bin/ari.js, and passed its node snapshot.

Not run: the wasm-mt flavour, and the pycvc-gl wasm build itself. The publish workflows run only on a tag or a dispatch.

… work

The wasm gallery (libcvc-examples-web) and pycvc-gl-cp312's wasm columns
configured with CVC_ENABLE_IMAGEMAGICK=OFF because every executable that linked
the static cvc died in wasm-ld on MagickCore's undefined BZ2_*, lzma_* and xml*
symbols. Three bugs were behind ImageMagick not being usable on wasm.

1. The codec closure was skipped on the stock FindImageMagick tier.
   src/cvc/CMakeLists.txt hung bz2/lzma/libxml2/tiff/webp/Lerc/... off MagickCore
   only on its own raw-libs fallback path. CMake >= 3.26's FindImageMagick makes
   delegate-less ImageMagick::* targets itself whenever pkg-config can see
   MagickCore.pc, and a cvcpkg build env exports CMAKE_PREFIX_PATH, which
   FindPkgConfig turns into a pkg-config search path even under emcmake. Such a
   build took the stock tier and never added the closure. The closure is now added
   for any static MagickCore (wasm, or a libMagickCore*.a), whichever tier found
   it, plus zlib. #457 fixed the consumer side (cvcConfig.cmake.in) the same way.

2. The wasm HDRI define was wrong. With no pkg-config answer the configure kept
   its Q16 / HDRI=0 defaults, but the cvcpkg wasm library is
   libMagickCore-7.Q16HDRI, and ImageMagick's headers take MAGICKCORE_HDRI_ENABLE
   from the compile line alone. cvc and every consumer (through cvc's public
   define) compiled against an integer Quantum while the library uses float. The
   published libcvc 3.7.0+cvc.1 wasm-mt SDK was built that way. The quantum depth
   and HDRI now come from the library name when pkg-config gives nothing.

3. The wasm coder registry was empty at run time. MagickCore creates the
   registry lazily, on the first GetMagickInfo, and RegisterMagickInfo drops every
   entry until then. magick_io.cpp's wasm-only init called RegisterStaticModules()
   and the Register*Image() entry points straight after InitializeMagick, so every
   coder was dropped while each static module was still marked registered, and
   the lazy path never retried. Every Magick read and write failed ("no encoder",
   NoDecodeDelegate). That is what stb_io.cpp's comment blamed on duplicated
   objects in libMagickCore.a. The init now calls GetMagickInfo("*") first, which
   creates the registry and registers the static coders into it.

Recipes and CI:
- libcvc-examples-web and pycvc-gl-cp312 (build-wasm.sh and .ps1) build with
  ImageMagick ON and list imagemagick and its codec bundles (tiff, libjpeg-turbo,
  libpng, libwebp, lerc, xz, bzip2, libxml2) as wasm build deps.
- The configure records CVC_IMAGEMAGICK_ENABLED in the cache. build-wasm-demo.sh
  and the pycvc-gl wasm scripts fail when ImageMagick was asked for and not
  found, instead of shipping without it.
- ci.yml's ari-wasm job links ari with ImageMagick ON. It passes
  CMAKE_PREFIX_PATH, so it takes the stock tier that broke, and ari's
  cvc::image::load pulls MagickCore in. It also checks the configure reports
  (Q16, HDRI=1).
- publish-cvcgl-wasm.yml fails if the wasm-mt SDK's cvcTargets.cmake does not
  carry MAGICKCORE_HDRI_ENABLE=1.
- cvc_revision: libcvc 1 -> 3 and cvcgl 1 -> 3 in lockstep (the wasm-mt SDK
  changes, native is already at +cvc.2), pycvc-gl-cp312 1 -> 3 (linux is at
  +cvc.2), libcvc-examples-web 1 -> 2. Native builds are unchanged: the closure
  gate is static-only, the HDRI inference is skipped on WIN32 and wherever
  pkg-config answers, and the registry change is __EMSCRIPTEN__-only.

Verified locally on Windows with emsdk 5.0.7 against catalog wasm deps
(imagemagick 7.1.2+cvc.23, vtk 9.5.0+cvc.3), single-threaded, configured like
build-wasm-demo.sh with CMAKE_PREFIX_PATH exported:
- master: terrain_lab.js fails in wasm-ld with undefined BZ2_*/lzma_*/xml*
  from libMagickCore-7.Q16HDRI.a (blob.o, miff.o, profile.o), the same failure
  as publish-cvcgl-wasm run 35070058005.
- this change: terrain_lab, bunny_shadow, volren_bunny, volslice_bunny and ari
  link, terrain_lab renders in a browser, and ari passes ci.yml's node snapshot
  check. The exported
  cvcTargets.cmake names only ImageMagick::Magick++/::MagickCore and carries
  MAGICKCORE_HDRI_ENABLE=1.
- no-pkg-config configure: "(Q16, HDRI=1)" (master: HDRI=0), closure linked.
- a program linked against the static cvc round-trips a 7x5 RGBA image through
  TIFF (Magick + libtiff, which stb cannot do) under node, byte-identical. The
  registry holds 255 formats after init (0 before).
Nothing in CI exercised ImageMagick at run time in a wasm build. The ari-wasm
job only proves the codec libraries resolve at link time. The empty coder
registry that the previous commit fixes in magick_io.cpp failed every Magick
read and write while everything still linked and every native test passed.

image_magick_roundtrip_test is a plain main() like physics_replay_test, since
googletest has no wasm build. It is built by CVC_BUILD_IMAGE_MAGICK_ROUNDTRIP.
It checks that every extension magick_image_io advertises has a coder that
both decodes and encodes, then round-trips an RGBA image through TIFF
(byte-identical) and WEBP (size). Neither format can go through the stb
handler, so both directions run through Magick, libtiff and libwebp. It exits
77 in a build without ImageMagick. Natively, image_test covers the same round
trips.

ci.yml's ari-wasm job now configures with the option, builds the target next
to ari, and runs it under the emsdk's node. Its path filter also covers
src/cvc/image, inc/cvc/image and the test.

Verified locally (emsdk 5.0.7, catalog wasm deps, the same stock-tier
configure as the job): the test passes. With init_magick_once's
GetMagickInfo("*") call removed, it fails with 11 failures (all nine coders
unregistered, both round trips with "no encoder") and exits 1.
@transfix
transfix enabled auto-merge (squash) October 25, 2026 04:59
@transfix
transfix merged commit 5536b65 into master Oct 25, 2026
24 of 25 checks passed
transfix added a commit that referenced this pull request Oct 26, 2026
…lib (#822)

#801 added zlib to the ImageMagick delegate closure in src/cvc/CMakeLists.txt
as "zlib|z". On a native MSVC build that finds a pkg-config (MSYS2's
C:/msys64/mingw64/bin/pkg-config.exe on PATH; the PKG_CONFIG_LIBDIR pin keeps it
on the cvcpkg .pc files), pkg_check_modules(... zlib) succeeds from cvcpkg's
zlib.pc, whose Libs: line is `-lz`. FindPkgConfig then cannot find_library() a
`z` (pkgcfg_lib__im_dep_zlib_z-NOTFOUND), because the MSVC import library is
zlib.lib, and it keeps the unresolved name bare in _im_dep_zlib_LINK_LIBRARIES
and in PkgConfig::_im_dep_zlib. The loop trusted _FOUND and hung that target off
ImageMagick::MagickCore, so every link of cvc.dll asked link.exe for z.lib:

    LINK : fatal error LNK1181: cannot open input file 'z.lib'

CI stays green because the GitHub windows-2022 image has no pkg-config. The loop
takes the find_library fallback there, `NAMES z` finds nothing, and zlib is
silently left out of the closure.

On MSVC, the loop now uses a pkg-config answer only when every library in
<prefix>_LINK_LIBRARIES resolved to an absolute path. Otherwise it takes the
find_library fallback. Other toolchains keep today's behaviour, because their
linkers search for a bare name themselves. The wasm libxml-2.0.pc lists `-lm`,
which no sysroot file backs and emcc handles itself, so a stricter rule there
would move wasm's libxml2 off the pkg-config path #801 just made work.

A closure entry can now list several library names. zlib's are `z zlib`, and the
fallback uses NAMES_PER_DIR so the prefix's zlib.lib is not passed over for a
later directory that matches `z`. With or without pkg-config, cvc.dll now links
deps/lib/zlib.lib. The static-export handling is unchanged: delegates still hang
off the build-local ImageMagick::MagickCore and never reach cvcTargets.cmake.
transfix added a commit that referenced this pull request Oct 29, 2026
…bxml2 out of the host link (#872)

publish-pycvc-gl-wasm failed on the v3.7.1 and v3.7.2 tag runs at configure
("found no ImageMagick in .../wasm-deps"). #801 made imagemagick a wasm build dep
of pycvc-gl-cp312 and made build-wasm.sh fail without it, but the workflow
installed a hand-typed dep list that never gained it.

- The install step runs `cvcpkg install-deps cvcpkg/recipes/pycvc-gl-cp312
  --platform wasm`, plus freetype, assimp and imgui by name, so it cannot drift
  from the recipe again. It sets pipefail: under the default `bash -e`,
  `cvcpkg install | tail -3 || error` passed a failed install.

With ImageMagick in, the host the build linked did not compile under node
("expected 0 elements on the stack for fallthru, found 1"). link-host.sh links
every $DEPS/lib/*.a under --allow-multiple-definition. VTK's bundled libxml2
mangles only the public API, so 65 internals collided with cvcpkg's libxml2
2.12.9, which ImageMagick pulls in; VTK's __xmlRaiseError returns int and
2.12's callers expect void.

- link-host.sh leaves libvtklibxml2-*.a out of the group. Its only user,
  vtkXMLTreeReader, is not in the vtk-python build.
- The verify step runs a bundled host under node and requires
  PYCVC_VTK_BRIDGE_OK and PYCVC_WASM_OK, since link-host.sh's own smoke is
  non-fatal and the broken host went out green.

Dry run 40795092841 on 77772ca passed: ImageMagick found (Q16, HDRI=1), no
libxml2 mismatches, the host prints both markers, and the bundle is
pycvc-gl-cp312 3.7.2+cvc.1 (85.8 MB).
@transfix
transfix deleted the fix/wasm-imagemagick-on branch October 29, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant