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.
What Go toolchain are you using?
TinyGo.
EDIT: I'm using TinyGo for compiling the code to WASM intended to be executed with Wasmtime.
OK, it should be generating an export function called "_start" that you can call, which initializes the Go runtime and calls your "main".
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
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, ())?;
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