brendandburns added the bug label to Issue #9174.
brendandburns opened issue #9174:
Test Case
package main import ( "fmt" "log" "os" ) func main() { stat, err := os.Stat("./") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", stat.Name()) entries, err := os.ReadDir("./") if err != nil { log.Fatal(err) } for _, entry := range entries { fmt.Printf("\t%s\n", entry.Name()) } file, err := os.Open("main.go") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", file.Name()) if err := os.WriteFile("test.txt", []byte("This is test data"), 0x777); err != nil { log.Fatal(err) } }
Steps to Reproduce
GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go
wasmtime --dir .::. main.wasm
Expected Results
Generated code should be able to open files mapped in via
--dir
Actual Results
``
...
2024/08/27 18:27:51 open main.go: Bad file number### Versions and Environment Wasmtime version or commit: 24.0 Operating system: Linux Architecture: x86_64 ### Extra Info I don't know if this is a Golang or a wasmtime issue. ~~~
brendandburns edited issue #9174:
Test Case
package main import ( "fmt" "log" "os" ) func main() { stat, err := os.Stat("./") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", stat.Name()) entries, err := os.ReadDir("./") if err != nil { log.Fatal(err) } for _, entry := range entries { fmt.Printf("\t%s\n", entry.Name()) } file, err := os.Open("main.go") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", file.Name()) if err := os.WriteFile("test.txt", []byte("This is test data"), 0x777); err != nil { log.Fatal(err) } }
Steps to Reproduce
GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go
wasmtime --dir .::. main.wasm
Expected Results
Generated code should be able to open files mapped in via
--dir
Actual Results
... 2024/08/27 18:27:51 open main.go: Bad file number
Versions and Environment
Wasmtime version or commit: 24.0
Operating system: Linux
Architecture: x86_64
Extra Info
I don't know if this is a Golang or a wasmtime issue.
bjorn3 commented on issue #9174:
Can you try running with
WASMTIME_LOG=wasmtime_wasi=trace
? That should show all wasi syscalls executed by the wasm module with all arguments and error results.
primoly commented on issue #9174:
The issue does not occur if you use
wasmtime --dir .::/ main.wasm
(Note the.::/
instead of.::.
)I think Go always adds a
/
at the beginning of the path. Changing toos.Open("./main.go")
does not resolve the issue.Rust’s
std::fs::File::open
works with both absolute and relative paths as it useswasi-libc
which does the mapping automatically so I guess this is an issue with the Go bindings to Wasi.
brendandburns closed issue #9174:
Test Case
package main import ( "fmt" "log" "os" ) func main() { stat, err := os.Stat("./") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", stat.Name()) entries, err := os.ReadDir("./") if err != nil { log.Fatal(err) } for _, entry := range entries { fmt.Printf("\t%s\n", entry.Name()) } file, err := os.Open("main.go") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", file.Name()) if err := os.WriteFile("test.txt", []byte("This is test data"), 0x777); err != nil { log.Fatal(err) } }
Steps to Reproduce
GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go
wasmtime --dir .::. main.wasm
Expected Results
Generated code should be able to open files mapped in via
--dir
Actual Results
... 2024/08/27 18:27:51 open main.go: Bad file number
Versions and Environment
Wasmtime version or commit: 24.0
Operating system: Linux
Architecture: x86_64
Extra Info
I don't know if this is a Golang or a wasmtime issue.
brendandburns commented on issue #9174:
Changing
--dir .::..
to--dir .::/
fixes things.I agree that this feels like a bug in the Go + Wasi bindings, I'll look into that codebase.
Closing this issue here.
brendandburns edited a comment on issue #9174:
Changing
--dir .::.
to--dir .::/
fixes things.I agree that this feels like a bug in the Go + Wasi bindings, I'll look into that codebase.
Closing this issue here.
Last updated: Nov 22 2024 at 16:03 UTC