Skip to content

Instantly share code, notes, and snippets.

@iamshreeram
Last active April 28, 2024 03:33
Show Gist options
  • Save iamshreeram/954bec300caeff9d63f839a7295b502d to your computer and use it in GitHub Desktop.
Save iamshreeram/954bec300caeff9d63f839a7295b502d to your computer and use it in GitHub Desktop.
setting wasm/wasi in mac and running it on wasm runtime

Install necessary runtime

  1. Major runtimes - wasmtime / wasmcloud / wasmer - Runtime Comparison
  2. Others to check - fermyon spin / wamr / wasmedge / wazero

Build a sample application using a programming language of your choice

Python example

print("Hello, world!")
  • Other languages : Golang / rust (pending)

Try to componentize the app (modularization)

For python, pip install componentize-py

Steps :

  1. Below is simple WIT / Interface (hello.wit) that would print some string when hello function is called
package example:hello;
world hello {
  export hello: func() -> string;
}
  1. To understand the internal bindings, you can always run below; (Optional)
componentize-py -d hello.wit -w hello bindings .
  1. Write the app that would print Hello, World!
import hello
class Hello(hello.Hello):
    def hello(self) -> str:
        return "Hello, World!"
  1. Generate the component
componentize-py -d hello.wit -w hello componentize app -o app.wasm

Run it in wasi runtime

wasmtime run only knows how to run components targeting the wasi-cli world. It does not (as of this writing) know how to run components targeting arbitrary worlds like the hello world

Follow this

**Right now, You can create component in python and import it in another host application written in python. **

Implement the host-app in another language

Make the application as polygot by implementing a component model

Implement host application in other languages - Rust, Golang, Python

Run it again in wasi runtime [ or in the case of a browser-based application]

Integrate the wasm module into a web browser to test its functionality

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