aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-03-01 10:42:34 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-04-18 10:20:20 -0700
commit692ccd01b4ebaa78f6702b15459437228e6a790d (patch)
treec7423e8ade27fb1a961b5a4abf8adf4d021ba404 /src
parent089651716c3d326f8540f4e415fc88443e42f5f2 (diff)
downloadzig-692ccd01b4ebaa78f6702b15459437228e6a790d.tar.gz
zig-692ccd01b4ebaa78f6702b15459437228e6a790d.zip
stage2: Initialize WASI preopens on startup
Diffstat (limited to 'src')
-rw-r--r--src/main.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index a647216b05..8696661017 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -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);
}