Skip to content

error in importing wasi binary into a Go application #1880

@hassan-shahbazi

Description

@hassan-shahbazi

Description

I have a Go application that uses wasmer runtime to work with some wasi binaries. When I use Rust to write and generate wasm binary, I can access and use both imported and exported functions and it works perfectly fine.

import (
    wasm "github.com/wasmerio/go-ext-wasm/wasmer"
)

func main() {
    bytes, error := wasm.ReadBytes("binary.wasm")
    if error != nil {
        panic(err)
    }

    instance, err := wasm.NewInstance(bytes)
    if err != nil {
        panic(err)
    }

    println("instance loaded!", instance)
}

However, when I try to import a binary generated by swiftwasm, it gives the following error:

Failed to instantiate the module:
            28 link errors: (1 of 28) Import not found, namespace: wasi_snapshot_preview1, name: proc_exit (2 of 28) Import not found, namespace: wasi_snapshot_preview1, name: args_sizes_get (3 of 28) Import not found, namespace: wasi_snapshot_preview1, name: args_get (4 of 28) Import not found, namespace: wasi_snapshot_preview1, name: sched_yield (5 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_read (6 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_write (7 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_close (8 of 28) Import not found, namespace: wasi_snapshot_preview1, name: clock_time_get (9 of 28) Import not found, namespace: wasi_snapshot_preview1, name: poll_oneoff (10 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_fdstat_get (11 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_open (12 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_filestat_get (13 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_rename (14 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_filestat_set_times (15 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_link (16 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_create_directory (17 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_readdir (18 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_readlink (19 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_symlink (20 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_prestat_get (21 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_prestat_dir_name (22 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_unlink_file (23 of 28) Import not found, namespace: wasi_snapshot_preview1, name: path_remove_directory (24 of 28) Import not found, namespace: wasi_snapshot_preview1, name: random_get (25 of 28) Import not found, namespace: wasi_snapshot_preview1, name: environ_sizes_get (26 of 28) Import not found, namespace: wasi_snapshot_preview1, name: environ_get (27 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_fdstat_set_flags (28 of 28) Import not found, namespace: wasi_snapshot_preview1, name: fd_seek

This is my swift file:

print("Hello World!")

and I use the following command to generate the wasi binary, according to the guide here

$ TOOLCHAIN_PATH = $HOME/.swiftenv/versions/wasm-DEVELOPMENT-SNAPSHOT-2020-09-29-a/usr/share
$ swiftc -target wasm32-unknown-wasi -sdk $TOOLCHAIN_PATH/wasi-sysroot binary.swift -o binary.wasm

Also, running the binary directly with wasmer does not have any issues:

$ wasmer binary.wasm
Hello World!

Metadata

Metadata

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions