Skip to content

Conversation

@Stebalien
Copy link
Contributor

(draft because this is a bit of a hack and needs some discussion first)

At the moment, it's not possible to use &Path, &OsStr, etc. with rustix on WASIp2 without the nightly compiler (requires the wasip2 feature) as OsStrExt and OsStringExt require the wasip2 feature on WASIp2 so we can't use as_bytes() on OsStr and friends.

However, the recommendation on the upstream issue is to just use to_str as WASI paths are Unicode. This PR does exactly that.

@alexcrichton am I interpreting your comment correctly?

Alternatives:

  • Wait. I'd prefer not to do this as I don't see a quick path to stabilization here.
  • Work around this downstream. I'm submitting this to try to get tempfile working on the wasip2 platform on rust stable. I'm also happy to work around this downstream (in tempfile itself).
  • Use OsStr::as_encoded_bytes on wasi instead of OsStrExt::as_bytes. It will technically work but it also technically relies on an unstable representation (one that will likely never change on WASI, but still...).

This PR has two parts:

  1. The first commit DRYs up the code a bit to avoid having to implement too many platform-specific conditionals. I tried to keep this change minimal but I'm also happy to go ahead and DRY up the rest of the code (there's a fair amount of duplicate code in this file).
  2. The second commit special-cases conversions for OsString and OsStr, converting to utf8 strings where necessary.

@alexcrichton
Copy link
Member

I would agree that my thoughts there are being interpreted correctly. I can't comment much as to this PR specifically, however, as I am not familiar with this part of rustix (so would leave that part of review to someone else)

Unfortunately, `OsStrExt` and `OsStringExt` require the wasip2 feature
on wasip2 so we can't use `as_bytes()` on `OsStr` and friends. However,
the recommendation on the upstream issue [1] is to just use `to_str` as
WASI paths are unicode.

[1]: rust-lang/rust#130323 (comment)
@Stebalien Stebalien force-pushed the steb/feat-wasip2-path branch from f88b181 to 5d66a62 Compare November 9, 2025 17:49
@sunfishcode
Copy link
Member

For WASI for all time, the question of whether there will ever be a WASI API that we'd want to be reachable through Rust's std::fs that would accept filesystem paths that aren't USV strings does not yet have a final answer.

But I think we can answer this question with sufficient confidence for WASIp2, specifically. WASIp2 filesystem paths are always USV strings. So for WASIp2, I think it's fine for Rustix to do the to_str() thing, as this PR does.

@Stebalien Stebalien marked this pull request as ready for review November 10, 2025 05:38
@Stebalien
Copy link
Contributor Author

In that case, I think this PR is ready for a review.

@sunfishcode sunfishcode merged commit ee4a7fd into bytecodealliance:main Nov 10, 2025
50 checks passed
@sunfishcode
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants