Sitelet https://github.com/micropython/micropython/issues/15270#issuecomment-2280942885
Skip to content

Include a WASM interpreter as part of micropython or its standard library? #15270

Description

@huyng

Description

What are your thoughts on adding a WASM interpreter to Micropython's standard library / standard distribution?

The main benefit would be that I or anyone could for example write a library in C, C++, Zig, Rust, or Nim; compile it to WASM, and then run that same code in MicroPython through the WASM interpreter. Given a sufficiently optimized interpreter, one could get near the same performance as native C code.

A major use case for this workflow is mainly in machine learning, ai models, image processing, signal processing etc ... One could develop their image processing code with their normal toolchain on desktop. Compile to WASM while exporting a few functions, and then running these same functions within the WASM runtime on the embedded device.

Since many languages already target WASM as a compilation target, this would allow library developers to build for a single target while gaining the ability to distribute and run their code on many different microcontrollers. This is in contrast to the current process where one needs to compile for each microcontroller target if you want your library to run across many devices.

pywasm for example, is one such WASM interpreter written in pure Python. You can see an example of how WASM code compiled from a simple C function is loaded and ran here.

Here is a WASM interpreter written in C and one in Zig.

I assume the C implementation would give the most optimal performance. But you could always include the pure-python wasm interpreter first into micropython, and then later on replace it with the C implementation.

Code Size

I am unsure at this point how much a WASM interpreter would add to the Micropython runtime and would need to do further investigation.

Implementation

I hope the MicroPython maintainers or community will implement this feature

Code of Conduct

Yes, I agree

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementationsproposed-closeSuggest this issue should be closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions