Compiling Rust, GoLang, Zig, WebAssembly to MicroPython modules #15702
Replies: 9 comments 13 replies
-
Very cool work! I believe that building on, and expanding the usage of, .mpy native modules has a lot of potential for MicroPython. It enables creating modules with near-native performance (the bindings boundary does have a slight overhead), while preserving the "just mip install it" developer experience. Which is what people expect from Python on desktop, but is quite unique on embedded/microcontrollers. Having WASM also as an option here, allows code in more languages to be used. And over time we will likely see more and more libraries built in a WASM-first manner, which can then be utilized on MicroPython. Often this comes from "web land" (with very different constraints) but there are some areas where I think code reuse might be realistic - for example compression algorithms, hashing, file formats, digital signal processing, algorithms, numeric computing, machine learning, et.c. |
Beta Was this translation helpful? Give feedback.
-
It seems that in your approach, WASM is ahead-of-time compiled? That is excellent, because one avoids the FLASH/RAM footprint of an interpreter/runtime, and the difficulty of making two different runtimes interoperate. Also: Congratulations on Independence Day of Ukraine! А завзяття, праця щира свого ще докаже, Ще ся волі в Україні піснь гучна розляже. |
Beta Was this translation helpful? Give feedback.
-
I have also updated https://github.com/wasm3/embedded-wasm-apps Since 2021, many dependencies had breaking changes.. some significant efforts were required to get everything working again. |
Beta Was this translation helpful? Give feedback.
-
small update... 😁
|
Beta Was this translation helpful? Give feedback.
-
I was finally able to run something more complicated... MicroPython v1.24.0-preview.193.gba49efe6b on 2024-08-20; Generic ESP32S3 module with ESP32S3
Type "help()" for more information.
>>> import machine
>>> machine.freq(240000000)
>>> import coremark
>>> coremark.setup()
Running CoreMark 1.0...
Result: 135.796 The declared CoreMark for ESP32-S3 is |
Beta Was this translation helpful? Give feedback.
-
You can now access and modify the wasm module memory: >>> import cpp
>>> cpp.setup()
🤩 C++ is running!
>>> cpp._memory[4096:4096+32]
bytearray(b' Blink\x00\xf0\x9f\xa4\xa9 C++ is running!\x00\n\x00\x00\x00')
>>> new_data = b"Hello C++ world"
>>> cpp._memory[4108:4108+len(new_data)] = new_data
>>> cpp.setup()
🤩 Hello C++ world |
Beta Was this translation helpful? Give feedback.
-
🚀🚀🚀 |
Beta Was this translation helpful? Give feedback.
-
While I think this is a very cool project, I'm wondering what the limitations of the combined toolchains are. More specifically: Python is an object oriented language and has nice predefined types like: list, tuple, dictionary, ... Also the source languages you mention like Rust, Go, Zig are object oriented, aren't they? I don't know webassembly. But I know that C is not an object oriented language. Can you confirm this? |
Beta Was this translation helpful? Give feedback.
-
Support of RISC-V ( |
Beta Was this translation helpful? Give feedback.
-
Back in 2021, I experimented with the concept of
embedded-wasm-apps
.This allowed to run any of the WebAssembly supported languages on microcontrollers:
Recently, I discovered that MicroPython has the ability to compile plain C code into a dynamically loadable
.mpy
file. This revelation immediately sparked an idea:So, here is how to convert a
WASM
file into aMPY
module and run it dynamically on different MCUs:https://github.com/vshymanskyy/wasm2mpy
Compile
Upload to the board
Run
Potential benefits of this approach are already described in embedded-wasm-apps.
Also, it will play nicely with
VfsMap
Further reading:
Beta Was this translation helpful? Give feedback.
All reactions