Skip to content

Commit

Permalink
stage2: Initialize WASI preopens on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
topolarity committed Mar 7, 2022
1 parent ee2b9cc commit c45ce30
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit c45ce30

Please sign in to comment.