Try to compile this sample code to WASI:
fn main() -> std::io::Result<()> {
for entry in std::fs::read_dir("/")? {
println!("{}", entry?.path().display());
}
Ok(())
}
Then, choose a large-ish folder - e.g. I created a temporary directory with 50 files named 0...49.
Run the produced Wasm with Wasmtime with that directory mapped to /:
$ wasmtime temp.wasm --mapdir /::$PWD/temp-dir
/1
/2
/49
thread 'main' panicked at 'range end index 1214 out of range for slice of length 128', library/std/src/sys/wasi/fs.rs:164:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: failed to run main module `temp.wasm`
Caused by:
0: failed to invoke command default
1: wasm trap: unreachable
wasm backtrace:
0: 0xd581 - <unknown>!__rust_start_panic
1: 0xd223 - <unknown>!rust_panic
2: 0xcdfb - <unknown>!std::panicking::rust_panic_with_hook::h7412819944345424
3: 0xc36e - <unknown>!std::panicking::begin_panic_handler::{{closure}}::h4738c0049ce98322
4: 0xc2af - <unknown>!std::sys_common::backtrace::__rust_end_short_backtrace::h8bb6e3f06234953f
5: 0xcc9f - <unknown>!rust_begin_unwind
6: 0x12d4e - <unknown>!core::panicking::panic_fmt::h904ce09f3cb14707
7: 0x12432 - <unknown>!core::slice::index::slice_end_index_len_fail::hcdd59b2bc02fd78c
8: 0x9bd9 - <unknown>!<std::sys::wasi::fs::ReadDir as core::iter::traits::iterator::Iterator>::next::h53073ad4dd8c7879
9: 0x96ff - <unknown>!<std::fs::ReadDir as core::iter::traits::iterator::Iterator>::next::h35e43cb49f6132cb
10: 0x9de - <unknown>!temp::main::h0ae35bb072c9f0ef
11: 0x1c90 - <unknown>!core::ops::function::FnOnce::call_once::hf1fda840e003cdf0
12: 0x2820 - <unknown>!std::sys_common::backtrace::__rust_begin_short_backtrace::hf0b5aa48499a3256
13: 0x3e5b - <unknown>!std::rt::lang_start::{{closure}}::h6eaa3cdacd789dba
14: 0xd334 - <unknown>!std::rt::lang_start_internal::h0e1571f3e9f07dad
15: 0x3dfc - <unknown>!std::rt::lang_start::h382cc3264c9b1456
16: 0x1483 - <unknown>!__original_main
17: 0x527 - <unknown>!_start
note: run with `WASMTIME_BACKTRACE_DETAILS=1` environment variable to display more information
Same code against the same folder works fine with Wasmer, suggesting it's an environment issue not Rust stdlib issue:
/0
/1
/10
/11
/12
/13
/14
/15
/16
/17
/18
/19
/2
/20
/21
/22
/23
/24
/25
/26
/27
/28
/29
/3
/30
/31
/32
/33
/34
/35
/36
/37
/38
/39
/4
/40
/41
/42
/43
/44
/45
/46
/47
/48
/49
/5
/6
/7
/8
/9
The relevant code on the Rust side also hasn't been updated in 2 years, also confirming it's likely a runtime environment issue: https://github.com/rust-lang/rust/blob/643a79af3d5a31fa87c8a4c9d7f8bc4ebe2add4b/library/std/src/sys/wasi/fs.rs#L164
Try to compile this sample code to WASI:
Then, choose a large-ish folder - e.g. I created a temporary directory with 50 files named 0...49.
Run the produced Wasm with Wasmtime with that directory mapped to
/:Same code against the same folder works fine with Wasmer, suggesting it's an environment issue not Rust stdlib issue:
The relevant code on the Rust side also hasn't been updated in 2 years, also confirming it's likely a runtime environment issue: https://github.com/rust-lang/rust/blob/643a79af3d5a31fa87c8a4c9d7f8bc4ebe2add4b/library/std/src/sys/wasi/fs.rs#L164