Does wasmer-go support importing memory into the wasm module
radkomih opened this issue · comments
Radosvet M commented
Summary
I don't see any examples in the docs if wasmer-go
supports importing memory from the host environment into the Wasm module? Is it possible and how?
Additional details
For example: The Wasm module (the one below) should be able to use the memory provided by the host and use the host provided functions to manage it.
Type: wasm
Size: 2.5 MB
Imports:
Functions:
"env"."ext_allocator_free": [I32] -> []
"env"."ext_allocator_malloc": [I32] -> [I32]
Memories:
"env"."memory": not shared (20 pages..)
Tables:
Globals:
Exports:
Functions:
"intr_cust_function": [I32, I32] -> [I64]
Memories:
Tables:
"__indirect_function_table": FuncRef (352..352)
Globals:
"__data_end": I32 (constant)
"__heap_base": I32 (constant)
Radosvet M commented
Found what I was looking for.
James Lawrence commented
@radkomih it'd be useful if you posted the solution =P
Radosvet M commented
Sure, here is the fragment with the memory import:
...
importObject := wasmer.NewDefaultWasiImportObject()
memory, _ := wasmer.NewMemory(2, 0)
imports := wasmer.NewImports()
imports.Namespace("env").AppendMemory("memory", memory)
importObject.Extend(*imports)
instance, _ := module.InstantiateWithImportObject(importObject)
...