-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
stdlib: Add emulated CWD to std.os for WASI targets #11021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3565b6c
to
71ea69d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments to get the ball rolling. I'm still reading over the changes, but I'll try to leave feedback incrementally to make it more manageable.
Thanks for the review! Just pushed a small fix for a Windows-specific test failure and corrected the stylistic problems you pointed out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for this excellent contribution @topolarity !
@topolarity How is |
To clarify my previous comment, let me give an example. Assume the program is given these preopens:
Intuitively, the user would expect the path resolution to work like this:
This is exactly how path resolution used to work in When
When When
|
Thanks for the detailed input @zigazeljko. I'm planning on opening an additional PR this evening to bring us up to parity with the "wasi-libc" behavior. Nested preopens will need to be fixed up in that PR (or we'll need to detect and reject them). The only bit I'm unsure about is whether we can achieve the "intuitive" behavior of distinguishing I'm going to cc you there so that we can discuss in more detail :-) |
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the current working directory. The `*at(...)` functions look for this and resolve relative paths against the stored CWD. Absolute paths are dynamically matched against the stored Preopens. "os.initPreopensWasi()" must be called before std.os functions will resolve relative or absolute paths correctly. This is asserted at runtime. Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`, `fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`, and `faccessat`. This also includes limited support for `getcwd()` and `realpath()`. These return an error if the CWD does not correspond to a Preopen with an absolute path. They also do not currently expand symlinks.
Is this documented anywhere and/or have you tested it? I just tested this in wasmer (versions 1.0.0 and 2.2.0) and while leading
As far as I tested, wasmer only trims all leading Additionally, the first preopen ( |
You're right, I had only tested absolute paths. Thanks for the correction - That's an important detail. Let's continue this discussion in the new PR, once its open? |
This PR provides emulated relative and absolute path support for
std.os
on WASI targets (resolves #10749)."os.initPreopensWasi()" must be called before
std.os
functions can resolve relative or absolute paths, which is asserted at runtime.Support has been added for:
open
,rename
,mkdir
,rmdir
,chdir
,fchdir
,link
,symlink
,unlink
,readlink
,fstatat
,access
, andfaccessat
.This also includes limited support for
getcwd()
andrealpath()
. These return an error if the CWD does not correspond to a Preopen with an absolute path. They also do not currently expand symlinks. Tests have been updated to expect the CWD at "/cwd" rather than ".", so that "realpath" will work for CWD-relative paths.