bytecodealliance / bytecodealliance/wizer
wizer.initialize can't read file even if --allow-wasi --dir . specified?
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
Given the program
```
package main
import "os"
var theText string
//go:export wizer.initialize
func WizerInitialize() {
buf, err := os.ReadFile("test.txt")
if err != nil {
println("error: Cannot read test.txt", err.Error())
}
theText = string(buf)
}
func main() {
if theText == "" {
WizerInitialize()
}
println("theText", theText)
}
```
This succeeds, and outputs foobar as expected:
```
tinygo build -target=wasi -scheduler=none -wasm-abi=generic -o main.wasm main.go
echo "foobar" > test.txt
wasmtime --dir . main.wasm
```
but this
```
wizer --allow-wasi --dir . -o out.wasm < main.wasm
```
fails with
```
error: Cannot read test.txt open test.txt: errno 76
```
Setting RUST_LOG=debug shows that it is at least preopening the directory:
```
[2021-07-20T16:12:44Z DEBUG wizer] Validating input Wasm
[2021-07-20T16:12:44Z DEBUG wizer] Preparing input Wasm
[2021-07-20T16:12:44Z DEBUG wasmtime_cache::worker] Cache worker thread started.
[2021-07-20T16:12:44Z DEBUG wasmtime_cache::worker] New nice value of worker thread: 3
[2021-07-20T16:12:44Z DEBUG wizer] Validating the exported initialization function
[2021-07-20T16:12:44Z DEBUG wizer] Calling the initialization function
[2021-07-20T16:12:44Z DEBUG wizer] Preopening directory: .
[2021-07-20T16:12:44Z DEBUG wizer] Creating dummy imports
error: Cannot read test.txt open test.txt: errno 76
```
Passing a bad directory to --dir does abort, so it is at least opening the directory.
This is on mac, so I have not gone through the agony of using dtruss to see if it is actually trying to open a file.
Contributor guide
Assessment
This issue has not been assessed yet.