-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix is_absolute on WASI #77362
Fix is_absolute on WASI #77362
Conversation
WASI does not match `cfg(unix)`, but its paths are Unix-like (`/some/path`) and don't have Windows-like prefixes. Without this change, `is_absolute` for paths like `/some/path` was returning `false`on a WASI target, which is obviously not true and undesirable.
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Thanks!
This sounds reasonable but I don't know anything about WASI, so I'll poke the last few people who touched WASI filesystem stuff for another set of eyes: @ibmibmibm @sunfishcode. Please shout if you notice anything wrong with adopting a unix-equivalent definition of what constitutes an absolute path for WASI. @bors r+ |
📌 Commit 494d6e5 has been approved by |
I believe to some degree that's intentional. There's various documentation stating there's no absolute paths on WASI. Such as here: https://docs.rs/wasi-common/0.18.0/wasi_common/fs/struct.Dir.html
and here: https://docs.rs/wasi-common/0.18.0/wasi_common/fs/index.html
and here: WebAssembly/wasi-libc#81 (comment)
|
Thank you! What do you make of that, @RReverser? @bors r- |
That's an interesting view. I've rather seen it as "WASI doesn't have relative paths" (because there is no concept of current working directory) not "WASI doesn't have absolute paths" (because those are the only kind of paths that WASI path APIs do accept). In fact, being able to distinguish between those two in a cross-platform manner is exactly the reason I wanted this function to work. As a practical example, Rust port of coreutils has its own userland implementation of Since However, if Personally, I think that even though WASI doesn't have absolute paths in the traditional sense (not every path level exists, you can't go between them etc.), it would be still useful to distinguish "/some/path" mount points as absolute, while any other as relative, so that code that can deal with the former would continue work on WASI just like it does on any other system. |
@RReverser I agree. The docs are admittedly ambiguous on this point, WASI functions interpret a path starting with |
I assume you mean, unless such path can be matched via preopened dirs, correct? |
That's a good point, and another reason this PR makes sense. The WASI "system calls" themselves do require relative paths, however in "userspace", library code maps absolute paths into handle + relative path. Above that library abstraction layer, WASI does support absolute paths in a sense, so it makes sense to have |
@sunfishcode Sounds like we're on the same page, thanks for the confirmation. |
@bors r+ |
📌 Commit 494d6e5 has been approved by |
Rollup of 11 pull requests Successful merges: - rust-lang#76851 (Fix 'FIXME' about using NonZeroU32 instead of u32.) - rust-lang#76979 (Improve std::sys::windows::compat) - rust-lang#77111 (Stabilize slice_ptr_range.) - rust-lang#77147 (Split sys_common::Mutex in StaticMutex and MovableMutex.) - rust-lang#77312 (Remove outdated line from `publish_toolstate` hook) - rust-lang#77362 (Fix is_absolute on WASI) - rust-lang#77375 (rustc_metadata: Do not forget to encode inherent impls for foreign types) - rust-lang#77385 (Improve the example for ptr::copy) - rust-lang#77389 (Fix some clippy lints) - rust-lang#77399 (BTreeMap: use Unique::from to avoid a cast where type information exists) - rust-lang#77429 (Link `new` method in `DefautHasher`s doc) Failed merges: r? `@ghost`
WASI does not match
cfg(unix)
, but its paths are Unix-like (/some/path
) and don't have Windows-like prefixes.Without this change,
is_absolute
for any paths, including/some/path
, was returningfalse
on a WASI target, which is obviously not true and undesirable.