Skip to content

Implement std::fs::canonicalize for WASI #141854

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

Open
Timmmm opened this issue Jun 1, 2025 · 0 comments
Open

Implement std::fs::canonicalize for WASI #141854

Timmmm opened this issue Jun 1, 2025 · 0 comments
Labels
A-filesystem Area: `std::fs` O-wasi Operating system: Wasi, Webassembly System Interface T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Timmmm
Copy link
Contributor

Timmmm commented Jun 1, 2025

std::fs::canonicalize() is not implemented for WASI, but I can't see any show-stopping reason why it couldn't be (maybe pre-opens complicate it?). I ran into this when attempting to compile rustfmt for WASI.

I found a couple of related issues:

1

#82339 - suggests using the Prefix part of paths (like C:) for pre-opens.

@RReverser said

Another reason I'm asking is that I want to implement Path::canonicalize on WASI because it frequently comes up during cross-compilation, and then fails at runtime - turns out, a lot of crates use it to translate relative paths to absolute ones.

This is exactly the situation I ran into. I'll also note that this was quite annoying to debug since the error message in its entirety was operation not supported on this platform, you can't use RUST_BACKTRACE, rustfmt doesn't have extensive logging, and I don't fancy setting up WASM debugging. I resorted to tedious printf debugging. (Side rant: for all the emphasis Rust puts on compiler error messages its runtime error messages are usually quite terrible!)

2

This issue in Rollup where they ran into the same problem and have a simple implementation we could maybe use.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 1, 2025
@Noratrieb Noratrieb added T-libs Relevant to the library team, which will review and decide on the PR/issue. O-wasi Operating system: Wasi, Webassembly System Interface A-filesystem Area: `std::fs` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-filesystem Area: `std::fs` O-wasi Operating system: Wasi, Webassembly System Interface T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants