Skip to content

fix(cmake): make the static wasm export relocatable (ImageMagick + zstd) - #453

Merged
transfix merged 1 commit into
masterfrom
fix/wasm-imagemagick-zstd-relocatable-export
Sep 28, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/wasm-imagemagick-zstd-relocatable-export

Conversation

@transfix

@transfix transfix commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

The bug

The published wasm libcvc bundle bakes 15 build-machine absolute paths into cvc::cvc's exported INTERFACE_LINK_LIBRARIES (verified by installing the published bundle and grepping cvcTargets.cmake):

/home/runner/work/libcvc/libcvc/wasm-deps/lib/libMagick++-7.Q16HDRI.a
  ...libMagickCore..., libbz2, libjpeg, libpng16, libwebp{,mux,demux,decoder},
  libsharpyuv, libtiff, libxml2, liblzma, libLerc, libzstd

Every relocated consumer's link then dies with:

ninja: error: '.../wasm-deps/lib/libMagick++-7.Q16HDRI.a', needed by
  'bin/<consumer>.js', missing and no known rule to make it

This is why a downstream wasm demo gallery built against the published bundle could never link/deploy — the deps-resolve error just failed first and masked it. (Boost::* and assimp::assimp export correctly as relocatable targets; the assimp zlib fix works.)

Root cause

For a static cvc (wasm --link static) even PRIVATE link deps propagate to consumers as $<LINK_ONLY:...>. On wasm the stock find_package(ImageMagick) produces no imported targets, so the raw-libs fallback links ${ImageMagick_LIBRARIES} (abs) PUBLIC, the delegate loop links each codec abs path PRIVATE, and zstd links its abs path PRIVATE — all baked into the export. The "PRIVATE keeps it out of the interface" assumption only holds for a shared lib. Native/macOS/Windows are unaffected (config-mode imported targets → export names ImageMagick::Magick++ etc.).

Fix (make wasm behave like native — export relocatable target names)

  • ImageMagick: in the raw-libs path, synthesise ImageMagick::Magick++/::MagickCore UNKNOWN IMPORTED targets and link those; delegates (loop now gated on the new _cvc_im_rawlibs flag) hang off MagickCore's interface. Imported-target locations are build-local and never written to install(EXPORT), so the export names only the two relocatable targets — which cvcConfig.cmake.in already recreates (with the delegate closure) in each consumer's prefix.
  • zstd: synthesise PkgConfig::ZSTD instead of linking the raw path, and add zstd re-resolution to cvcConfig.cmake.in (it had none), mirroring the existing FFTW3 handling.

Mirrors the existing assimp::assimp relocatable-export handling in the same file. No behaviour change on native/macOS/Windows (they take the config-mode path; the new branches run only in the raw-libs fallback).

Verification

  • Native CI matrix (this PR) covers no-regression on linux/macOS/windows.
  • Local wasm build + cvcTargets.cmake export inspection confirms the abs paths are gone (in progress).
  • Final proof: reship publish-cvcgl-wasm and relink a downstream wasm consumer against it.

Coordinated with the wasm-recipe owner (no file overlap; this is a prerequisite for the held wasm-SDL3 work, which will inherit the clean export).

The published wasm libcvc bundle baked 15 BUILD-MACHINE absolute paths into
cvc::cvc's exported INTERFACE_LINK_LIBRARIES — libMagick++, libMagickCore, the
codec delegates (bz2/jpeg/png16/webp{,mux,demux,decoder}/sharpyuv/tiff/xml2/
lzma/Lerc), and libzstd — all under /home/runner/work/libcvc/libcvc/wasm-deps/.
Every relocated consumer's link then died with e.g.
  ninja: error: '.../wasm-deps/lib/libMagick++-7.Q16HDRI.a', needed by
    'bin/dbg_austin_live.js', missing and no known rule to make it
which is why the cvcdbg wasm demo3 gallery could never link/deploy (the deps
resolve error just failed first and masked it). Native/macOS/Windows were fine:
they link config-mode imported targets, so the export names ImageMagick::Magick++
etc. — relocatable — which cvcConfig.cmake.in already re-resolves.

Root cause: for a STATIC cvc (wasm --link static) even PRIVATE link deps
propagate to consumers as $<LINK_ONLY:...>, so the raw-libs ImageMagick fallback
(target_link_libraries cvc PUBLIC ${ImageMagick_LIBRARIES}), the delegate loop's
PRIVATE find_library links, and the zstd PRIVATE find_library link all baked
absolute paths into the export. The 'PRIVATE keeps it out of the interface'
assumption only holds for a SHARED lib.

Fix — make wasm behave like native (export relocatable target names):
- ImageMagick: in the raw-libs path, synthesise the ImageMagick::Magick++ /
  ::MagickCore UNKNOWN IMPORTED targets from the found libs and link those; the
  delegate loop (now gated on the new _cvc_im_rawlibs flag, since the targets now
  exist) hangs each delegate off MagickCore's interface. Imported-target
  IMPORTED_LOCATIONs are build-local and never written to install(EXPORT), so the
  export names only the two relocatable targets. cvcConfig.cmake.in already
  recreates them (with the delegate closure) in each consumer's own prefix.
- zstd: synthesise PkgConfig::ZSTD from the find_library path instead of linking
  it raw, and add zstd re-resolution to cvcConfig.cmake.in (the consumer had
  none), mirroring the existing FFTW3 handling.

Mirrors the existing assimp::assimp relocatable-export handling in this file.
No behaviour change on native/macOS/Windows (they take the config-mode target
path; the new branches only run in the raw-libs fallback).
@transfix
transfix merged commit a0ea644 into master Sep 28, 2026
13 checks passed
@transfix
transfix deleted the fix/wasm-imagemagick-zstd-relocatable-export branch September 28, 2026 08:25
transfix added a commit that referenced this pull request Sep 28, 2026
…t fix (#456)

libcvc #453 makes the STATIC wasm export relocatable, but the already-published
wasm-mt bundles (libcvc +cvc.4, cvcgl +cvc.5) still carry the baked absolute
paths — a recipe/source fix can't rewrite a published archive. Reship both:

- libcvc 4 -> 5: clean cvcTargets.cmake wasm-mt export (no /home/runner abs paths).
- cvcgl  5 -> 6: rebuild against + re-pin libcvc +cvc.5. cvcgl exact-pins the
  libcvc it built against, so the published +cvc.5 pins the broken +cvc.4; without
  this bump, installing cvc/cvcgl drags +cvc.4 back in and demo3 still fails.

Native is unaffected (publish-cvcpkg auto-bumps above the recipe floor). After
merge: run publish-cvcgl-wasm (dry_run=false) to ship the pair.
transfix added a commit that referenced this pull request Sep 28, 2026
…ers + reship (#457)

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