himakshi25 added the bug label to Issue #9127.
himakshi25 opened issue #9127:
Created a wasm of a simple c program with command:
emcc main.c -o file.wasm.
Program is trying to open a file present in test directory.// main.c #include <stdio.h> int main() { printf("Hello world!\n"); FILE *file = fopen("test/hello_world_file.txt", "rb"); if (!file) { printf("cannot open file\n"); return 1; } while (!feof(file)) { char c = fgetc(file); if (c != EOF) { putchar(c); } } fclose (file); return 0; }On running file.wasm with wasmtime with command
wasmtime file.wasmgot the below errorHello world! cannot open fileAlso, tried giving directory as well in wasmtime but didn't work and got same error.
commandwasmtime --dir=test file.wasmIs there any way to allow wasmtimes to access or mount local directory for file read and write?
himakshi25 edited issue #9127:
Created a wasm of a simple c program with command:
emcc main.c -o file.wasm.
Program is trying to open a file present in test directory.// main.c #include <stdio.h> int main() { printf("Hello world!\n"); FILE *file = fopen("test/hello_world_file.txt", "rb"); if (!file) { printf("cannot open file\n"); return 1; } while (!feof(file)) { char c = fgetc(file); if (c != EOF) { putchar(c); } } fclose (file); return 0; }On running file.wasm with wasmtime with command
wasmtime file.wasmgot the below errorHello world! cannot open fileAlso, tried giving directory as well in wasmtime but didn't work and got same error.
commandwasmtime --dir=test file.wasmIs there any way to allow wasmtime to access or mount local directory for file read and write?
bjorn3 commented on issue #9127:
Unless you enabled the
PURE_WASImode, Emscripten compiled modules are not guaranteed to be WASI compatible. I don't know if that is the reason it failed here, but it is something to keep in mind.
alexcrichton commented on issue #9127:
Have you tried
--dir .perhaps? By default guests have no access to the filesystem sowasmtime file.wasmwon't work. The--dir testargument I don't think will work because that makestestthe root of the filesystem where the program wants to open a directory calledtestso the root needs to be one level higher. If that doesn't work casn you upload the wasm binary here?
himakshi25 commented on issue #9127:
Yeah, I tried without
PURE_WASImode and this might be the possible reason, Sharing file below to confirm.
wasm.zipAs suggested, tried with
PURE_WASImode.
command:emcc main.cpp -o file.wasm -s PURE_WASI
Getting same error, sharing the wasm binary as well.Hello world! cannot open fileCould you please help to know if I am missing any other argument here?
himakshi25 edited a comment on issue #9127:
@bjorn3 Yeah, I tried without
PURE_WASImode and this might be the possible reason, Sharing file below to confirm.
wasm.zipAs suggested, tried with
PURE_WASImode.
command:emcc main.cpp -o file.wasm -s PURE_WASI
Getting same error, sharing the wasm binary as well.Hello world! cannot open fileCould you please help to know if I am missing any other argument here?
alexcrichton commented on issue #9127:
I think this is an issue with a flag needing to be passed to emscripten or similar. The wasm binaries here have these imports:
(import "wasi_snapshot_preview1" "proc_exit" (func (;0;) (type 3))) (import "wasi_snapshot_preview1" "fd_write" (func (;1;) (type 7))) (import "wasi_snapshot_preview1" "fd_read" (func (;2;) (type 7))) (import "wasi_snapshot_preview1" "fd_close" (func (;3;) (type 0))) (import "wasi_snapshot_preview1" "fd_seek" (func (;4;) (type 12)))but none of those are the import to open a host file. This means that the wasm binary is not even trying to open a host file. This makes me think the issue is with the binary itself (e.g. configuration of emscripten) rather than Wasmtime.
rggaur789 commented on issue #9127:
Hi @alexcrichton ,
I have tried the below simple c++ code#include <iostream>
int main() { std::cout << "Hello World!\n"; return 0; }with command
emcc main.cpp -o file.wasm -s PURE_WASIand
wasmtime file.wasmbut I am getting
Error: failed to run main module `file.wasm` Caused by: 0: failed to instantiate "file.wasm" 1: unknown import: `env::_tzset_js` has not been definedI am using emscripten and wasmtime latest versions. Can you please help what I am doing wrong here?
rggaur789 edited a comment on issue #9127:
Hi @alexcrichton ,
I have tried the below simple c++ code#include <iostream> int main() { std::cout << "Hello World!\n"; return 0; }with command
emcc main.cpp -o file.wasm -s PURE_WASIand
wasmtime file.wasmbut I am getting
Error: failed to run main module `file.wasm` Caused by: 0: failed to instantiate "file.wasm" 1: unknown import: `env::_tzset_js` has not been definedI am using emscripten and wasmtime latest versions. Can you please help what I am doing wrong here?
rggaur789 edited a comment on issue #9127:
Hi @alexcrichton / @bjorn3 ,
I have tried the below simple c++ code#include <iostream> int main() { std::cout << "Hello World!\n"; return 0; }with command
emcc main.cpp -o file.wasm -s PURE_WASIand
wasmtime file.wasmbut I am getting
Error: failed to run main module `file.wasm` Caused by: 0: failed to instantiate "file.wasm" 1: unknown import: `env::_tzset_js` has not been definedI am using emscripten and wasmtime latest versions. Can you please help what I am doing wrong here?
bjorn3 commented on issue #9127:
It may be the case that the PURE_WASI mode of Emscripten is broken. It is marked as experimental anyway.
You may have more luck using wasi-sdk instead of Emscripten: https://github.com/webassembly/wasi-sdk
rggaur789 commented on issue #9127:
@bjorn3 I have tried with -s STANDALONE_WASM also but the result is same.
rggaur789 edited a comment on issue #9127:
@bjorn3 I have tried with -s STANDALONE_WASM also but the result is same,
also in wasi-sdk c++ exception is not supported so it will not be compatible with our uses cases
alexcrichton commented on issue #9127:
@rggaur789 you're asking questions here that require a deeper knowledge of Emscripten than I think many of us have. I'd recommend raising questions with the Emscripten side of things for answers
himakshi25 commented on issue #9127:
Thanks @bjorn3 @alexcrichton for inputs.
One related query,
I also tried by using--embed-fileof emscripten https://emscripten.org/docs/porting/files/packaging_files.html
command :emcc file.cpp -o file.wasm --embed-file test/hello_world_file.txt -s STANDALONE_WASM
and while executing with wasmtime getting errorError: failed to run main module `file.wasm` Caused by: 0: failed to instantiate "file.wasm" 1: unknown import: `env::_emscripten_fs_load_embedded_files` has not been definedIs the wasmtime not supporting this emscripten file packaging feature or is there any plan to support this.
bjorn3 commented on issue #9127:
Wasmtime doesn't support Emscripten's ABI. Said ABI is not even stable anyway AFAIK. It seems
--embed-filedepends on Emscripten's ABI and as such is incompatible with STANDALONE_WASM.
himakshi25 closed issue #9127:
Created a wasm of a simple c program with command:
emcc main.c -o file.wasm.
Program is trying to open a file present in test directory.// main.c #include <stdio.h> int main() { printf("Hello world!\n"); FILE *file = fopen("test/hello_world_file.txt", "rb"); if (!file) { printf("cannot open file\n"); return 1; } while (!feof(file)) { char c = fgetc(file); if (c != EOF) { putchar(c); } } fclose (file); return 0; }On running file.wasm with wasmtime with command
wasmtime file.wasmgot the below errorHello world! cannot open fileAlso, tried giving directory as well in wasmtime but didn't work and got same error.
commandwasmtime --dir=test file.wasmIs there any way to allow wasmtime to access or mount local directory for file read and write?
Last updated: Dec 13 2025 at 19:03 UTC