wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

panic: Missing import: `wasi_snapshot_preview1`.`sock_accept` #410

Closed tim-chow closed 2 months ago

tim-chow commented 2 months ago

test.py:

def multiply(a: int, b: int) -> int:
    return a * b

if __name__ == "__main__":
    print(multiply(3, 3))

compile with py2wasm:

py2wasm -o test.wasm test.py

running with wasmer command is ok:

# wasmer run test.wasm 
9

but with wasmer-go there comes a problem。

main.go:

package main

import (
    "fmt"
    "github.com/wasmerio/wasmer-go/wasmer"
    "io/ioutil"
)

func main() {
    wasmBytes, err := ioutil.ReadFile("test.wasm")
    check(err)
    store := wasmer.NewStore(wasmer.NewEngine())
    module, _ := wasmer.NewModule(store, wasmBytes)

    wasiEnv, _ := wasmer.NewWasiStateBuilder("wasi-program").
        // Choose according to your actual situation
        // Argument("--foo").
        // Environment("ABC", "DEF").
        // MapDirectory("./", ".").
        Finalize()
    importObject, err := wasiEnv.GenerateImportObject(store, module)
    fmt.Printf("%v\n", importObject)
    check(err)

    instance, err := wasmer.NewInstance(module, importObject)
    check(err)

    start, err := instance.Exports.GetWasiStartFunction()
    check(err)
    start()

}

func check(e error) {
    if e != nil {
        panic(e)
    }
}

the output:

panic: Missing import: `wasi_snapshot_preview1`.`sock_accept`

goroutine 1 [running]:
main.check(...)
    /root/wasmer-go-demo/main.go:53
main.main()
    /root/wasmer-go-demo/main.go:43 +0x165
exit status 2

importObject including:

&{map[wasi_snapshot_preview1:map[args_get:0xc000012018 args_sizes_get:0xc000012030 clock_res_get:0xc000012048 clock_time_get:0xc000012060 environ_get:0xc000012078 environ_sizes_get:0xc000012090 fd_advise:0xc0000120a8 fd_allocate:0xc0000120c0 fd_close:0xc0000120d8 fd_datasync:0xc0000120f0 fd_fdstat_get:0xc000012108 fd_fdstat_set_flags:0xc000012120 fd_fdstat_set_rights:0xc000012138 fd_filestat_get:0xc000012150 fd_filestat_set_size:0xc000012168 fd_filestat_set_times:0xc000012180 fd_pread:0xc000012198 fd_prestat_dir_name:0xc0000121c8 fd_prestat_get:0xc0000121b0 fd_pwrite:0xc0000121e0 fd_read:0xc0000121f8 fd_readdir:0xc000012210 fd_renumber:0xc000012228 fd_seek:0xc000012240 fd_sync:0xc000012258 fd_tell:0xc000012270 fd_write:0xc000012288 path_create_directory:0xc0000122a0 path_filestat_get:0xc0000122b8 path_filestat_set_times:0xc0000122d0 path_link:0xc0000122e8 path_open:0xc000012300 path_readlink:0xc000012318 path_remove_directory:0xc000012330 path_rename:0xc000012348 path_symlink:0xc000012360 path_unlink_file:0xc000012378 poll_oneoff:0xc000012390 proc_exit:0xc0000123a8 proc_raise:0xc0000123c0 random_get:0xc0000123d8 sched_yield:0xc0000123f0 sock_recv:0xc000012408 sock_send:0xc000012420 sock_shutdown:0xc000012438]]}
syrusakbary commented 2 months ago

Hey @tim-chow . Wasmer-go is a bit outdated. But we'll update soon in the coming weeks

tim-chow commented 2 months ago

Hey @tim-chow . Wasmer-go is a bit outdated. But we'll update soon in the coming weeks

@syrusakbary Got it~Thank you so much~

Yisaer commented 2 months ago

Hi @syrusakbary @tim-chow

I meet the same issue with wasmer-go v1.0.4, will this be fixed in the next release? If it will, When will the next version be released?

Also, can we reopen this issue as the problem is still existed?

Please tell me if the issue is already fixed in the master branch, thus I can verify it quickly.