wasmtime-py
wasmtime-py copied to clipboard
Run wasm file like the wasmtime cli would
I'd like to get the same behaviour as the wasmtime foo.wasm cli, or rather i'd like to have the rust program i compiled to wasm behave as similar to native execution as possible. This is the code i currently use:
from wasmtime import Store, Module, Engine, WasiConfig, Linker
engine = Engine()
store = Store(engine)
wasi = WasiConfig()
wasi.inherit_argv()
wasi.inherit_env()
wasi.inherit_stdout()
wasi.inherit_stderr()
wasi.inherit_stdin()
store.set_wasi(wasi)
linker = Linker(engine)
linker.define_wasi()
module = Module.from_file(store.engine, 'foo.wasm')
linking1 = linker.instantiate(store, module)
start = linking1.exports(store).get("") or linking1.exports(store)["_start"]
start(store)
Is there a way with less boilerplate to get wasmtime cli like behaviour or are there any additional options i need to set?
I believe that's roughly in line with what's necessary, but there's specific things with the old-style commands/reactors around getting the "default export" which may need some tweaking over time. Wasmtime's CLI isn't in a final state per-se either though and will probably continue to evolve as well.