Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang to wasm compilation using tinygo. Execution using wasmtime

I have the following test code

func main() {
    path, err := os.Getwd()
    log.Println(path, err)
    files, err := ioutil.ReadDir("/etc/dse")
    log.Println(files, err)
}

I compile it to wasm using

tinygo build -target wasi -o list.wasm list.go

Then I executeit using

wasmtime list.wasm

The output is

2023/05/05 16:00:50 / <nil>
2023/05/05 16:00:50 [] open /etc/dse: errno 76

At the same time, the directory /etc/dse exists and has permissions 777.

What is the source of this error and how to fix this?

like image 929
0x11111 Avatar asked Oct 24 '25 14:10

0x11111


1 Answers

errno 76 means capabilities insufficient.

You have to give it capabilities to access files in the requisite directories, with the wasmtime option --dir (see wasmtime WASI tutorial):

The --dir= option instructs wasmtime to preopen a directory, and make it available to the program as a capability which can be used to open files inside that directory.

$ wasmtime --dir=/etc/dse list.wasm
2023/05/06 01:36:31 / <nil>
2023/05/06 01:36:31 [] readdir unimplemented : errno 54

Unfortunately, readdir is not implemented in TinyGo yet.

References:

  • TinyGo - Unsupported System Calls
  • Languages - System Calls
  • stub of ReadDirent in TinyGo
  • TinyGo issue - wasi: implement readdir
like image 84
Zeke Lu Avatar answered Oct 27 '25 09:10

Zeke Lu