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

mv dir/foo dir/bar: applet not found #388

Open orangeC23 opened 1 year ago

orangeC23 commented 1 year ago

Summary

The wasm file is : uutils-wasm.txt The go file is :

package main

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

func main() {

    // os.Chdir(filepath.Dir(os.Args[0]))

    wasmBytes, _ := ioutil.ReadFile("./uutils.wasm")

    store := wasmer.NewStore(wasmer.NewEngine())

    module, _ := wasmer.NewModule(store, wasmBytes)

    wasiEnv, _ := wasmer.NewWasiStateBuilder("uutils").
        // Choose according to your actual situation
        Argument("mv dir/foo dir/bar").
        // Environment("ABC", "DEF").
        MapDirectory("./dir", "./dir").
        Finalize()
    if store == nil {
        fmt.Println("store is null")
    }
    if module == nil {
        fmt.Println("module is null")
    }
    importObject, err := wasiEnv.GenerateImportObject(store, module)
    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)
    }
}

Additional details

go run tmp.go

Expected behavior

mv dir/foo to dir/bar

Actual behavior

It prints mv dir/foo dir/bar: applet not found and do not move. Did I write wrong code?