Search code examples
webassemblymicropythonraspberry-pi-picothonnywasmtime

Does any wasm runtime has a support for micropython (For RPI_PICO board)


I am trying to import a wasm runtime ( to be specific pywasm3) in my thonny editor that supports micropython , I get an error stating no module named pywasm3 , Is there any runtime which can be imported as a module in thonny?or any other way to get the pywasm3 module working in micrpython?I have attached images of error below for reference.

screenshot of error text

I want the import statement to work for importing wasm runtime.


Solution

  • Looking at the wasm3 project, I see that it claims to support the Pico, but I can't find any further documentation on this - there's nothing in the embedded platforms section, for example. Possibly this support was added recently and is not yet mature.

    The problem is that wasm3 is written in C, so you need to make it into a compiled executable binary on the Pico that you can call from your MicroPython code. I'm not an expert on calling compiled code from Python but I'm sure that the pywasm3 Python binding is designed to be installed in 'desktop' Python using pip, which compiles the C code for the target platform during installation. This is not going to work on a Pico!

    I think you have three options:

    • Use wasm3 on the Pico and write the rest of your code in C, rather than in MicroPython. I guess you don't want to do this or you wouldn't have asked the question :-)
    • Build your own version of MicroPython on the Pico that includes wasm3 as an external module. You'd need to become familiar with the build process first and then look at the documentation on extending MicroPython. If you need help with this I suggest asking on MicroPython's Github Discussions.
    • Try an alternative wasm implementation such as pywasm which is written in pure Python, and which you should be able to install on the Pico by simply downloading and copying the package folder. You will probably need to do some work to adapt this package for MicroPython, but it claims to work on Python 3.6 so there may not be too many differences. The catch here is that pywasm alone will occupy more than half of your Pico's RAM - if that's a problem you might need to look at 'freezing' it so that it's stored in flash instead.