Skip to content

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

Open
@Timmmm

Description

@Timmmm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesystemArea: `std::fs`O-wasiOperating system: Wasi, Webassembly System InterfaceT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions