WasmKit icon indicating copy to clipboard operation
WasmKit copied to clipboard

How to add additional imports?

Open Vithanco opened this issue 10 months ago • 2 comments

I think I miss an introduction. I have a non-standard import in an emscripten created WASM

(import "env" "__syscall_faccessat" (func $env.__syscall_faccessat (type $t7))) with t7 being (type $t7 (func (param i32 i32 i32 i32) (result i32)))

How would I add an implementation for this to my setup?

let wasi = try WASIBridgeToHost()
let engine = Engine()
let store = Store(engine: engine)
var imports = Imports()
//add the missing import here
wasi.link(to: &imports, store: store)
let instance = try module.instantiate(store: store, imports: imports) 

Relevant types seem to have only private init functions.

Vithanco avatar Jan 21 '25 14:01 Vithanco

You can use Imports.define

kateinoigakukun avatar Jan 21 '25 14:01 kateinoigakukun

That seem to work. Thank you!!!! is there anywhere an example of how to transfer a string from Swift to WASM (and back)? All examples only use numbers.

Vithanco avatar Jan 22 '25 08:01 Vithanco