stage2: Initialize WASI preopens on startup

This commit is contained in:
Cody Tapscott 2022-03-01 10:42:34 -07:00
parent 089651716c
commit 692ccd01b4

View File

@ -162,6 +162,16 @@ pub fn main() anyerror!void {
return mainArgs(gpa_tracy.allocator(), arena, args);
}
// WASI: `--dir` instructs the WASM runtime to "preopen" a directory, making
// it available to the us, the guest program. This is the only way for us to
// access files/dirs on the host filesystem
if (builtin.os.tag == .wasi) {
// This sets our CWD to "/preopens/cwd"
// Dot-prefixed preopens like `--dir=.` are "mounted" at "/preopens/cwd"
// Other preopens like `--dir=lib` are "mounted" at "/"
try std.os.initPreopensWasi(std.heap.page_allocator, "/preopens/cwd");
}
return mainArgs(gpa, arena, args);
}