If we attempt to access the file system, such as the example provided https://github.com/bsletten/wasm_tdg/tree/main/ch11
We should see wasmtime and wasmer behave nearly the same, however wasmer v4.3.0 gives an error that it was unable to mount the given directory where was wasmtime v21.0.0 executes as expected.
use std::fs;
use std::env;
use std::io::{Read, Write};
/*
Purpose: This crate will showcase read/write file access with WASI
*/
static FILE_PATH: &str = "/tmp/hello.txt";
fn main() {
let args = env::args().collect::<Vec<String>>();
let name = if args.len() >=2 { &args[1] } else { "world" };
let greeting = format!("Hello, {}!", name);
let mut output_file = fs::File::create(FILE_PATH)
.expect(&format!("error creating {}", FILE_PATH));
output_file.write_all(greeting.as_bytes())
.expect(&format!("Error writing: {}", FILE_PATH));
let mut input_file = fs::File::open(FILE_PATH)
.expect(&format!("error opening {}", FILE_PATH));
let mut input = String::new();
input_file.read_to_string(&mut input)
.expect(&format!("Error reading: {} ", FILE_PATH));
println!("Read in from file: {}", input);
}
Executing in wasmtime:
wasmtime --dir=/tmp file_rw.wasm dog
Read in from file: Hello, dog!
Executing in wasmer:
wasmer --dir=/tmp/ file_rw.wasm fish
error: Unable to mount "/tmp"
╰─▶ 1: file exists
I would have expected the same results for both runtimes. Both are being maintained still. This type of file access isnt overly complicated so its disappointing that Wasmer use case examples are not being updated appropriately in their own documentation, let alone outside resources
2