Live data from Hacker News

Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

github.com

31–40 of 41 posts

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#31
post #23

Earlier quoted context omitted.

There exists tooling already to compile for wasm from static languages (rust, C++, and so on) and there exists tooling to run this WASM on a raspberry pi (wasmer, etc). That makes me feel the end goal here is not what's described ("make wasm so it can run on a raspberry"), but rather "make wasm run in micropython". Am I missing something?

Yes, we're talking about Raspberry Pi Pico (RP2040) here. Not the Linux-based SBCs (Single Board Computers)

Curious if you've seen the WAMR runtime which is explicitly designed to be lightweight enough for freestanding embedded systems on some higher end microcontrollers (Cortex-M4F).

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#32
post #31

Earlier quoted context omitted.

Yes, we're talking about Raspberry Pi Pico (RP2040) here. Not the Linux-based SBCs (Single Board Computers)

Curious if you've seen the WAMR runtime which is explicitly designed to be lightweight enough for freestanding embedded systems on some higher end microcontrollers (Cortex-M4F).

Yes, Wasm3 also targets Cortex-M4 and even Cortex-M0 :)

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#33

Author here, ready to answer any questions.

Like several others I'm confused about the tagline for this. If I understand correctly, it's not compiling "WASM to micropython", but to native binary code with generated micropython bindings?

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#34

Author here, ready to answer any questions.

Like several others I'm confused about the tagline for this. If I understand correctly, it's not compiling "WASM to micropython", but to native binary code with generated micropython bindings?

Correct. I didn't create the tagline, sorry

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#35
post #25

Earlier quoted context omitted.

Actually in my case I need a VM, because I want users to be able to upload "extension plugins" in real-time, without reuploading firmware In that case which approach / library would you recommend to embedd a WASM VM?

This is exactly what wasm2mpy does for MicroPython: Dynamically loaded, AOT-compiled WASM modules

Okay great! But I'm not using MicroPython, just compiling directly for the ESP32, would that mean that to use wasm2mpy I would need to add a MicroPython VM in my code?

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#36
post #25

Earlier quoted context omitted.

Actually in my case I need a VM, because I want users to be able to upload "extension plugins" in real-time, without reuploading firmware In that case which approach / library would you recommend to embedd a WASM VM?

This is exactly what wasm2mpy does for MicroPython: Dynamically loaded, AOT-compiled WASM modules

would you say that using wasm2mpy is better suited for my needs than having a wasm runtime like the one of bytecodealliance? What would be the advantage in this case?

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#37
post #23

Earlier quoted context omitted.

There exists tooling already to compile for wasm from static languages (rust, C++, and so on) and there exists tooling to run this WASM on a raspberry pi (wasmer, etc). That makes me feel the end goal here is not what's described ("make wasm so it can run on a raspberry"), but rather "make wasm run in micropython". Am I missing something?

Yes, we're talking about Raspberry Pi Pico (RP2040) here. Not the Linux-based SBCs (Single Board Computers)

I see, thanks for the clarification!

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#38
post #36

Earlier quoted context omitted.

This is exactly what wasm2mpy does for MicroPython: Dynamically loaded, AOT-compiled WASM modules

would you say that using wasm2mpy is better suited for my needs than having a wasm runtime like the one of bytecodealliance? What would be the advantage in this case?

Yes, for these microcontroller-type chips, ahead-of-time compilation would be definitely more suitable. WAMR probably supports it, but you can also to it via WASM2C, easily. I prefer not depending on WAMR, it is very bloated

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#39

Earlier quoted context omitted.

tools/mpy_ld.py: https://github.com/micropython/micropython/blob/master/tools... tools/mpy-tool.py lists opcodes: https://github.com/micropython/micropython/blob/master/tools... Can the same be done with .pyc files; what are the advantages of MicroPython native modules? Why does it need wasm2c?

I don't think .pyc files can contain native code, but .mpy can! And that's exactly what I'm using here: - compile any language to wasm - translate wasm to C99 - use the native target toolchain to compile C99 to .mpy - run that on the device

If they're both Turing-complete opcodes instruction sets, Church-Turing says it is possible with just .pyc, too.

But that doesn't solve for WASM on a MicroPython device.

And that is why smart contracts without costed opcodes could not be built on Python.

Re: Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys

#40
post #36

Earlier quoted context omitted.

would you say that using wasm2mpy is better suited for my needs than having a wasm runtime like the one of bytecodealliance? What would be the advantage in this case?

Yes, for these microcontroller-type chips, ahead-of-time compilation would be definitely more suitable. WAMR probably supports it, but you can also to it via WASM2C, easily. I prefer not depending on WAMR, it is very bloated

thanks for all those answers! Slava Ukraini
Post reply on HN