Skip to content

1578 Add WASM support#1579

Draft
reneSchm wants to merge 1 commit into
mainfrom
1578-add-wasm-support
Draft

1578 Add WASM support#1579
reneSchm wants to merge 1 commit into
mainfrom
1578-add-wasm-support

Conversation

@reneSchm

@reneSchm reneSchm commented Jul 11, 2026

Copy link
Copy Markdown
Member

Changes and Information

Please briefly list the changes (main added features, changed items, or corrected bugs) made:

  • Small changes to enable the pyodide/emscripten toolchain

If need be, add additional information and what the reviewer should look out for in particular:

  • See comment below for instructions

Merge Request - Guideline Checklist

Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.

Checks by code author

  • Every addressed issue is linked (use the "Closes #ISSUE" keyword below).
  • New code adheres to coding guidelines.
  • No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • Tests are added for new functionality and a local test run was successful (with and without OpenMP).
  • Appropriate documentation within the code (Doxygen) for new functionality has been added in the code.
  • Appropriate external documentation (ReadTheDocs) for new functionality has been added to the online documentation and checked in the preview.
  • Proper attention to licenses, especially no new third-party software with conflicting license has been added.
  • (For ABM development) Checked benchmark results and ran and posted a local test above from before and after development to ensure performance is monitored.

Checks by code reviewer(s)

  • Corresponding issue(s) is/are linked and addressed.
  • Code is clean of development artifacts (no deactivated or commented code lines, no debugging printouts, etc.).
  • Appropriate unit tests have been added, CI passes, code coverage and performance is acceptable (did not decrease).
  • No large data files added in the whole history of commits(files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • On merge, add 2-5 lines with the changes (main added features, changed items, or corrected bugs) to the merge-commit-message. This can be taken from the briefly-list-the-changes above (best case) or the separate commit messages (worst case).

@reneSchm reneSchm linked an issue Jul 11, 2026 that may be closed by this pull request
2 tasks
@reneSchm

Copy link
Copy Markdown
Member Author

Read all steps first, not everything is stated in order.

Get git, cmake, make, python. Create and load python venv.

Sources:

Direct WASM builds

  1. Set up emscripten SDK:

    # Get the emsdk repo
    git clone https://github.com/emscripten-core/emsdk.git
    
    # Enter that directory
    cd emsdk
    
    # Fetch the latest version of the emsdk (not needed the first time you clone)
    git pull
    
    # Download and install the latest SDK tools.
    ./emsdk install latest
    
    # Make the "latest" SDK "active" for the current user. (writes .emscripten file)
    ./emsdk activate latest
    
    # Activate PATH and other environment variables in the current terminal
    source ./emsdk_env.sh
    
  2. Compile with cmake:

    WASM works better with static libraries, as the binary is supposed to run in a browser.

    EXPECT_DEBUG_DEATH was not found.

    If you want to run the examples, add set(CMAKE_EXECUTABLE_SUFFIX ".html") after the project() directive.

    emcmake cmake -S cpp -B cpp/build -DMEMILIO_BUILD_SHARED_LIBS=OFF -DMEMILIO_BUILD_TESTS=OFF

  3. Build: cmake --build cpp/build -j10

  4. If built with html suffix, you can run emrun cpp/build/bin/<example>

Pyodide packaging

  1. Install pyodide-build from pip. Set up emscripten with the first step above, but replace the version "latest" with 5.0.3 (for pyodide-build 0.36.0)
  2. Create a wheel using pyodide build -Ccmake.define.MEMILIO_BUILD_SHARED_LIBS=OFF pycode/memilio-simulation. The wheel will be stored in dist/.
  3. For testing the wheel, you need a new env from pyodide. This requires a Node.js installation: pyodide venv venv-pyodide && source venv-pyodide/bin/activate
  4. pip install dist/<wheel-name>
  5. Run examples to verify installation.

WASM notebook

This section needs some figuring out... The steps might look like:

  • build and run a Emscripten marimo (or some other notebook/platform)
  • use the same Emscripten/Pyodite toolchain to compile memilio-simulation
  • install wheel in the notebook via import micropip; micropip.install("memilio-simulation"); import memilio.simulation
    • the import can technically take file:/// though hosting the wheel might be easier?
  • ???
  • profit

@reneSchm

Copy link
Copy Markdown
Member Author

@HenrZu If you want to take over, have fun ;)

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.

Add WASM support

1 participant