Skip to content

Add Emscripten/WebAssembly support#175

Open
key2 wants to merge 1 commit into
mvrdevelopment:masterfrom
key2:emscripten-support
Open

Add Emscripten/WebAssembly support#175
key2 wants to merge 1 commit into
mvrdevelopment:masterfrom
key2:emscripten-support

Conversation

@key2

@key2 key2 commented Jul 22, 2026

Copy link
Copy Markdown

Motivation

This makes libMVRgdtf compile and run correctly as WebAssembly with Emscripten, so the reference implementation can be used directly in browsers (and Node.js) with 100% file compatibility — e.g. for web-based GDTF/MVR viewers and visualizers — instead of re-implementing the formats in JS.

The library builds with the GS_LIN/_LINUX platform macros, DONT_USE_XERCES_AS_XMLLIB (bundled tinyxml2/rapidxml) and without BUILD_MVR_XCHANGE (raw TCP/mDNS is not available in a browser sandbox). Only three small platform issues needed changes:

Changes

  • UUID.cpp — Emscripten has no libuuid and no /proc. Under __EMSCRIPTEN__, generate random (version 4) UUIDs using std::random_device, which maps to a secure entropy source in Emscripten.

  • Wrapper/FilingWrapper.cppgetpwuid() returns NULL under Emscripten, so GetFolderAppDataPath dereferenced a null pointer and produced an invalid path (which broke the working-folder extraction of GDTF/MVR archives). Use $HOME with a fallback to /home/web_user, the default MEMFS home directory.

  • XmlFileHelper.{h,cpp} — wasm32 defines size_t as unsigned long, which is a distinct type from Uint32 (unsigned int) even though both are 32-bit — unlike the 32-bit targets the IS64BIT guard was written for. Compile the Uint32 overloads of ConvertInteger under Emscripten as well; otherwise calls with Uint32 arguments (e.g. GdtfMap::OnPrintToFile, GdtfConnector::OnReadFromNode) are ambiguous and fail to compile.

All changes are guarded by __EMSCRIPTEN__ and do not affect any existing platform.

Testing

Built with Emscripten 6.0.3 (-fwasm-exceptions, embind bindings on top) and verified in Node.js and headless Chrome:

  • All gdtf-share sample fixtures (Ayrton, BETOPPER, …) and several MVR show files (grandMA3 demo show, festival rigs, 15 files total) parse with zero GetParsingErrorCount(), identical results to the native Linux build
  • Full round trip of fixture metadata, DMX modes/channels, geometry trees (incl. glTF/3DS model buffer extraction), MVR scene traversal with GDTF resolution and DMX addresses

Note: for a fully working WASM build, the pending fixes #169 (root node name) and #170 (3DS/SVG buffer null check) are also needed, but they are independent of this PR.

Minimal changes to make the library compile and run correctly when
targeting WebAssembly with Emscripten (GS_LIN/_LINUX platform macros,
DONT_USE_XERCES_AS_XMLLIB, mvrxchange excluded):

- UUID.cpp: Emscripten provides no libuuid; generate random (v4) UUIDs
  from std::random_device instead.
- FilingWrapper.cpp: getpwuid() returns NULL under Emscripten; resolve
  the app data path from $HOME with a fallback to /home/web_user
  (the default MEMFS home directory).
- XmlFileHelper: wasm32 defines size_t as unsigned long, which is a
  distinct type from Uint32 (unsigned int) even though both are 32 bit,
  unlike the other 32-bit targets the IS64BIT guard was written for.
  Compile the Uint32 overloads of ConvertInteger under Emscripten as
  well, otherwise calls with Uint32 arguments are ambiguous.
@welcome

welcome Bot commented Jul 22, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines.

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