From c45ce30e538dda2d5c71ada3ed86eb201c5e2812 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Tue, 1 Mar 2022 10:42:34 -0700 Subject: [PATCH] stage2: Initialize WASI preopens on startup --- src/main.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.zig b/src/main.zig index ebbbe6da2553..f442270ca0b2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -162,6 +162,17 @@ 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); }