Skip to content

fix(cmake): append ImageMagick delegate closure for stock-tier consumers (+ reship) - #457

Merged
transfix merged 1 commit into
masterfrom
fix/wasm-consumer-imagemagick-delegates
Sep 28, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/wasm-consumer-imagemagick-delegates

Conversation

@transfix

@transfix transfix commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #453 (relocatable export). With the export fixed, a downstream wasm consumer build got past the abs-path error but failed to link:

wasm-ld: error: libMagickCore-7.Q16HDRI.a(...): undefined symbol: BZ2_bzCompress / lzma_code / xmlReadMemory ...

Cause: cvcConfig.cmake.in appends the ImageMagick static codec-delegate closure (bz2/lzma/xml2/…) to MagickCore only when _cvc_im_synth is set — i.e. only when the pkg-config or last-resort tier synthesised the target. On a wasm consumer the stock FindImageMagick tier wins (it finds the static -7.Q16HDRI libs in the prefix) and creates a delegate-less MagickCore without the flag, so the append was skipped.

Fix: gate the append on TARGET ImageMagick::MagickCore existing, not on _cvc_im_synth. The append is self-guarding (find_library per delegate; missing skipped) and a harmless dedup for a shared ImageMagick. Verified locally against the reshipped wasm prefix — MagickCore's interface now carries libbz2/liblzma/libxml2 (the exact 3 undefined-symbol delegates) + jpeg/png/webp/tiff/sharpyuv/Lerc/z.

Reship (embeds the corrected consumer config):

  • libcvc 5 → 6
  • cvcgl 6 → 7 (rebuild + re-pin against libcvc +cvc.6; exact-pin)

After merge → publish-cvcgl-wasm → downstream wasm nightly.

…ers + reship

After the relocatable-export fix (#453) the wasm demo consumer got PAST the abs-path
error but failed to LINK with undefined BZ2_*/lzma_*/xmlReadMemory/xmlFreeDoc symbols:
libMagickCore needs the bz2/lzma/xml2 codec delegates, and they were absent from the
consumer's link line.

Cause: cvcConfig.cmake.in appends the ImageMagick static delegate closure to MagickCore
only when _cvc_im_synth is set — i.e. only when the pkg-config or last-resort tier
synthesised the target. But on a wasm consumer the STOCK FindImageMagick tier wins (it
finds the static -7.Q16HDRI libs in the prefix via find_library) and creates a
delegate-LESS MagickCore without setting the flag, so the append was skipped and the
delegates never made the link line.

Fix: gate the delegate append on the MagickCore target existing, not on _cvc_im_synth.
The append is self-guarding (find_library per delegate, missing ones skipped) and a
harmless dedup for a shared ImageMagick, so it is safe to run for any MagickCore that
reaches it. Verified locally against the reshipped wasm prefix: MagickCore's interface
now carries libbz2/liblzma/libxml2 (+ jpeg/png/webp/tiff/sharpyuv/Lerc/z).

Reship to embed the corrected consumer config:
- libcvc 5 -> 6 (ships fixed cvcConfig.cmake.in)
- cvcgl  6 -> 7 (rebuild + re-pin against libcvc +cvc.6; exact-pin means the old +cvc.6
  cvcgl still pins the +cvc.5 libcvc with the broken consumer config)

After merge: publish-cvcgl-wasm (dry_run=false) -> re-run cvcdbg demo3 nightly.
@transfix
transfix merged commit 93b6541 into master Sep 28, 2026
13 checks passed
@transfix
transfix deleted the fix/wasm-consumer-imagemagick-delegates branch September 28, 2026 10:48
transfix added a commit that referenced this pull request Oct 25, 2026
… work (#801)

* wasm: build the gallery and pycvc-gl with ImageMagick ON, and make it 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).

* ci(wasm): run ImageMagick at run time under node, not just link it

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.
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