Stream: general

Topic: execute wasmtime instance


view this post on Zulip Karlo Vizec (Aug 09 2023 at 12:43):

Is there a way to execute an entire Wasmtime Instance (in Wasmtime that's embedded in Go) like the Wasmtime CLI does to .wasm file? As far as I know right now, the only way to execute a piece of code is to call a function.

EDIT: If not, is it possible to export the main Go function? When I attempt to do so, an error is thrown.

view this post on Zulip Lann Martin (Aug 09 2023 at 12:57):

What Go toolchain are you using?

view this post on Zulip Karlo Vizec (Aug 09 2023 at 13:10):

TinyGo.

EDIT: I'm using TinyGo for compiling the code to WASM intended to be executed with Wasmtime.

view this post on Zulip Lann Martin (Aug 09 2023 at 13:27):

OK, it should be generating an export function called "_start" that you can call, which initializes the Go runtime and calls your "main".

view this post on Zulip Lann Martin (Aug 09 2023 at 13:29):

I believe wasmtime run does something like the second example here ("For a Command..."): https://docs.rs/wasmtime/11.0.1/wasmtime/struct.Linker.html#method.module

view this post on Zulip Lann Martin (Aug 09 2023 at 13:34):

The important bit is something like this:

linker.module(&mut store, "", &module)?;
let func = linker.get_default(&mut store, "")?
    .typed::<(), ()>(&store)?;
func.call(&mut store, ())?;

view this post on Zulip Karlo Vizec (Aug 09 2023 at 14:01):

Ah, I see. I've seen tutorials invoke _start function, but didn't know its purpose. I'll try with that later. Thank you!


Last updated: Dec 23 2024 at 12:05 UTC