Skip to content

Refactor browser demos and Emscripten build output - #2721

Merged
sbc100 merged 3 commits into
WebAssembly:mainfrom
kevmoo:demo_cleanup1
Mar 17, 2026
Merged

sbc100 merged 3 commits into
WebAssembly:mainfrom
kevmoo:demo_cleanup1

Conversation

@kevmoo

@kevmoo kevmoo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

This comprehensive modernization of the WABT web demos and Emscripten
build output includes the following major improvements:

  • Separate WASM payload: Updated CMake and Makefile to output a separate
    libwabt.wasm file instead of inlining it in JS. This drastically
    reduces the libwabt.js size from ~1.24MB to ~26KB.
  • ES6 and async/await Modernization: Refactored wabt.post.js and demo
    scripts to use modern ES6 syntax (classes, const/let, arrow functions)
    and properly load the WebAssembly binary asynchronously.
  • Dynamic feature flags: Demos now dynamically generate feature checkboxes
    by inspecting wabt.FEATURES, rather than hardcoding them in HTML.
  • NPM Dependency Bundling: Migrated third-party demo dependencies
    (CodeMirror, Split.js) into a package.json-based build, generating
    a clean third_party.bundle.js. Consolidated shared demo logic into
    share.js.
  • Emscripten exports: Added missing features (compact_imports,
    custom_page_sizes, and wide_arithmetic) to emscripten-exports.txt
    to prevent instantiation errors.

kevmoo added 2 commits March 17, 2026 10:38
This comprehensive modernization of the WABT web demos and Emscripten
build output includes the following major improvements:

* Separate WASM payload: Updated CMake and Makefile to output a separate
  `libwabt.wasm` file instead of inlining it in JS. This drastically
  reduces the `libwabt.js` size from ~1.24MB to ~26KB.
* ES6 and async/await Modernization: Refactored `wabt.post.js` and demo
  scripts to use modern ES6 syntax (classes, const/let, arrow functions)
  and properly load the WebAssembly binary asynchronously.
* Dynamic feature flags: Demos now dynamically generate feature checkboxes
  by inspecting `wabt.FEATURES`, rather than hardcoding them in HTML.
* NPM Dependency Bundling: Migrated third-party demo dependencies
  (CodeMirror, Split.js) into a `package.json`-based build, generating
  a clean `third_party.bundle.js`. Consolidated shared demo logic into
  `share.js`.
* Emscripten exports: Added missing features (`compact_imports`,
  `custom_page_sizes`, and `wide_arithmetic`) to `emscripten-exports.txt`
  to prevent instantiation errors.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting this out! Much appreciated.

LGTM.

With a couple of questions:

  1. I assume you tested this locally somehow to make sure it works?
  2. What cmake command was used to build the demo binary (i.e. debug vs release,etc)

Comment thread docs/demo/third_party/index.js Resolved
@kevmoo

kevmoo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Let me dig through your questions before you land this!

@kevmoo

kevmoo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for splitting this out! Much appreciated.

LGTM.

With a couple of questions:

  1. I assume you tested this locally somehow to make sure it works?

Yep! Both apps. Make sure all of the boxes work and that I can edit code and it runs!

  1. What cmake command was used to build the demo binary (i.e. debug vs release,etc)

Just make demo. Double checked that it is a release build. I also added that Makefile fix for emscripten. See the convo in the other PR.

I think this is ready to land!

Comment thread Makefile Outdated

USE_NINJA ?= 1
EMSCRIPTEN_DIR ?= $(dir $(shell which emcc))
EMSCRIPTEN_DIR ?= $(shell em-config EMSCRIPTEN_ROOT 2>/dev/null || dirname $(shell which emcc))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this might be needed, but maybe in a different PR?

BTW, did you run into this issue yourself building against homebrew version of emscripten?

I wonder if we should instead switch to emcmake which is a command we takes care of the cmake/Modules/Platform/Emscripten.cmake thing for us.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay...

@sbc100

sbc100 commented Mar 17, 2026

Copy link
Copy Markdown
Member

Let me know when you are ready and I will land this, and we can test the live version.

@kevmoo

kevmoo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Done! Land it!

@kevmoo

kevmoo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

gah! no! Let me fix!

@kevmoo

kevmoo commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

oh. nevermind. all good. 😮‍💨

@sbc100
sbc100 merged commit 3fb9d42 into WebAssembly:main Mar 17, 2026
34 checks passed
@kevmoo
kevmoo deleted the demo_cleanup1 branch March 17, 2026 19:08
@sbc100 sbc100 mentioned this pull request Mar 17, 2026
sbc100 pushed a commit that referenced this pull request Mar 17, 2026
This was broken by #2721
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.

2 participants