Skip to content

Wasm implementation - #1040

Merged
highperformancecoder merged 11 commits into
developfrom
cairoShim-refactor
Nov 10, 2026
Merged

highperformancecoder merged 11 commits into
developfrom
cairoShim-refactor

Conversation

@highperformancecoder

@highperformancecoder highperformancecoder commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

This change is Reviewable

highperformancecoder and others added 4 commits November 4, 2026 18:38
New wasm/ directory builds the Minsky object with Emscripten
(jsminsky.js + jsminsky.wasm). Its methods are exposed through the
RESTProcess descriptor via embind, and the model canvas is drawn
through mansoura::MansouraHTMLCanvas. wasm/minsky.js mirrors the C++
method tree as a Javascript object and handles mouse, wheel and key
events; wasm/test.html is a demo page; wasm/test/smoke.js runs the
module under node against a mock canvas (make -C wasm test).

Platform changes, all behind __EMSCRIPTEN__:
- header stubs for cairo and friends in wasm/stubs
- RungeKutta::rkstep and BackgroundSaver run synchronously, as there
  are no threads
- clipboard is a no-op
- drop the pango.h includes, which were not needed outside Mansoura
- RenderNativeWindow: drawToContext() draws into an existing context,
  and records the frame size, as renderFrame() would

Also: mdlReader uses char32_t rather than uint32_t, as libc++ has no
char_traits<uint32_t>; nobble the libc++ vector iterator.

Update mansoura ref.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Minsky reads and writes NaN and Infinity as JSON5 values. Strict
JSON.parse could not read them (they were being replaced by null), and
JSON.stringify turned them into null on the way in. minsky.js now uses
the JSON5 library for both, taken from a JSON5 global, or require().
test.html loads the copy the GUI uses, and smoke.js checks a NaN read
and an Infinity round trip.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 01:40
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ed2ac90d-9eea-4522-a8ee-33f5d2539a69

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical defects skip command-state updates, leak Wasm allocations, and discard clipboard contents, making cut operations destructive.

6 open issues
What changed in this PR

Adds a WebAssembly build of Minsky, exposing the existing C++ model API to JavaScript and rendering models on an HTML canvas.

Changes:

  • Adds Emscripten build rules, JavaScript bindings, and browser interaction support.
  • Adapts native dependencies and threaded operations for Wasm.
  • Adds a browser demo and smoke tests for simulation, rendering, and API access.
File Description
wasm/​test/​smoke.js Tests API access, simulation, rendering, and serialization.
wasm/​test/​mockCanvas.js Provides a recording canvas mock.
wasm/​test.html Adds an interactive browser demo.
wasm/​stubs/​windowInformationStub.cc Stubs native window operations.
wasm/​stubs/​pythonBuffer.h Removes Python binding dependencies from Wasm.
wasm/​stubs/​pango/​pangocairo.h Provides a Pango compatibility header.
wasm/​stubs/​mansouraCairo.h Exposes drawing interfaces without Cairo.
wasm/​stubs/​cairoStub.cc Supplies Cairo stubs and unsupported-operation errors.
wasm/​stubs/​cairo/​cairo.h Declares minimal Cairo compatibility types and functions.
wasm/​stubs/​cairo.h Supports the alternate Cairo include path.
wasm/​minsky.js Wraps the model API and handles canvas interaction.
wasm/​Makefile Builds the Wasm module and runs smoke tests.
wasm/​jsminsky.cc Binds the C++ API and HTML canvas renderer.
wasm/​.gitignore Excludes generated Wasm build artifacts.
RESTService/​nobble.h Supports Emscripten iterator types in descriptors.
model/​renderNativeWindow.h Declares external-context rendering support.
model/​renderNativeWindow.cc Implements drawing into externally managed contexts.
model/​operationRS2.cc Removes an unnecessary Pango include.
model/​operationRS1.cc Removes an unnecessary Pango include.
model/​operation.cc Removes an unnecessary Pango include.
model/​minsky.h Excludes Pango headers from Wasm builds.
model/​minsky.cc Uses backend-independent font settings.
model/​dataOp.cc Removes an unnecessary Pango include.
model/​CSVDialog.cc Removes an unnecessary Pango include.
model/​cairoItems.h Makes rendering context pointers const-correct.
engine/​saver.cc Runs saving synchronously under Emscripten.
engine/​rungeKutta.cc Runs integration synchronously under Emscripten.
engine/​mdlReader.cc Uses standard UTF-32 character and string types.
engine/​godleyExport.cc Removes an unnecessary Pango include.
engine/​clipboard.cc Adds Wasm branches without native clipboard access.

Review effort: Balanced

Comment thread engine/clipboard.cc Resolved
Comment thread wasm/jsminsky.cc Outdated
return jsGuard([&]{
json_pack_t jin;
read(args,jin);
return CppWrapper(wrappedObject->process("."+method, jin));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implemented in commit a6d9fff: Wasm wrappers now call commandHook after successful dispatch using parsed arguments and a fully qualified path preserved by returned wrappers. The Wasm smoke test could not run because em++ is unavailable.

Comment thread wasm/minsky.js Outdated
Comment on lines +43 to +44
const resultObj=impl.call(fullMethod,stringify(args));
const children=resultObj.list();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in 9152728: Embind vectors and scalar results are released, and returned object wrappers now expose an idempotent dispose() method.

Comment thread wasm/minsky.js Resolved
Comment thread wasm/minsky.js Resolved
Comment thread wasm/test.html Resolved
highperformancecoder and others added 3 commits November 10, 2026 10:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Added frame variable to manage animation frame cancellation.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 2 commits November 9, 2026 23:30
Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
@highperformancecoder
highperformancecoder merged commit 4a21381 into develop Nov 10, 2026
5 checks passed
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.

3 participants