diff options
| author | Cody Tapscott <topolarity@tapscott.me> | 2022-03-01 10:42:34 -0700 |
|---|---|---|
| committer | Cody Tapscott <topolarity@tapscott.me> | 2022-04-18 10:20:20 -0700 |
| commit | 692ccd01b4ebaa78f6702b15459437228e6a790d (patch) | |
| tree | c7423e8ade27fb1a961b5a4abf8adf4d021ba404 /src/main.zig | |
| parent | 089651716c3d326f8540f4e415fc88443e42f5f2 (diff) | |
| download | zig-692ccd01b4ebaa78f6702b15459437228e6a790d.tar.gz zig-692ccd01b4ebaa78f6702b15459437228e6a790d.zip | |
stage2: Initialize WASI preopens on startup
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 10 |
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); } |
