Skip to content

Latest commit

 

History

History
59 lines (52 loc) · 2.07 KB

File metadata and controls

59 lines (52 loc) · 2.07 KB

wasi-component-model

Pre-Req

Install python modules - componentize-py, wasmtime-py and Runtime - wasmtime

Steps

  1. Create the WIT world you'd like. Below is simple 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 and create the GUEST; (Optional)
componentize-py -d hello.wit -w hello bindings hello_guest
  1. Create the module in python and save it with name of the app.py (ACTUAL APP)
import hello
class Hello(hello.Hello):
    def hello(self) -> str:
        return "Hello, World!"
  1. Generate the component app.wasm with below command from hello.wit and the module that was created above app.py
componentize-py -d hello.wit -w hello componentize --stub-wasi app -o app.wasm

or

componentize-py -d hello.wit -w hello componentize app -o app.wasm 
  1. Create the host-side bindings for the component app.wasm
python3 -m wasmtime.bindgen app.wasm --out-dir hello_host
  1. Now, we can write a simple host app using those bindings:
from hello_host import Root
from wasmtime import Config, Engine, Store

config = Config()
config.cache = True
engine = Engine(config)
store = Store(engine)
hello = Root(store)
print(f"component says: {hello.hello(store)}")

Flow chart :

image

Reference :

  1. Above example
  2. Implement host application in other languages - Rust, Golang, Python