rust-lang / rust-lang/rust

Implement std::fs::canonicalize for WASI

Open
#141,854 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-filesystem C-enhancement E-needs-design O-wasi T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the WASI implementation of std::fs::canonicalize and read the related pre-open discussion in issue #82339. Compare the simple implementation linked from the Rollup issue, then verify that canonicalize works on WASI and addresses the rustfmt failure described here.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.