-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
I am trying to compile and run the examples depicted here:
https://github.com/bytecodealliance/wasmtime/blob/fbe29da5cc1c0847af176f151f114a6a535534ff/docs/WASI-tutorial.md
The tools I try to use are emscripten and wasmtime.
When compiling the module with wasi-sdk (clang), the example works as expected.
However, when using emscripten to compile the module, when trying to run the example the following error occurs:
emcc test.c -o test.wasm
echo hello world > test.txt
./wasmtime test.wasm test.txt test2.txt
Error: failed to run main module `test.wasm`
Caused by:
0: failed to instantiate "test.wasm"
1: unknown import: `env::__sys_read` has not been definedI wanted to try to debug the issue to try to see if I can avoid the import and started by creating the following minimal program.
#include <stdlib.h>
#include <stdio.h>
int main() {
printf("Hello world!\n");
FILE* f = fopen("test.txt", "r");
printf("Handle %p\n", f);
perror("fopen():");
return 0;
}When compiling the module with emscripten and running it with wasmtime I get the following.
emcc test.c -o test.wasm
echo hello world > test.txt
./wasmtime test.wasm
Hello world!
Handle 0
fopen():: Operation not permittedSetting the file permissions with chmod 777 test.txt does not help.
Using the wasmtime flags for enabling the program to use the folder where the text file is in does not help either: ./wasmtime --dir=. test.wasm.
Wasmtime produces a different error about insufficient capabilities in case the folder permissions are an issue, and the same example works when compiled with clang (wasi-sdk).
Getting the example to work would be great, but getting the file opening to work at all would be great as well.
I am unsure if I have missed some flag or similar, I will keep on looking through emscripten documentation.
If I cant find anything I will just implement a host defined function to read/write files instead of using WASI.
Emscripten version: 2.0.0 (d81f400)