WebAssembly / WebAssembly/WASI

Supporting an "initial current directory"

Open
#771 47 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-filesystem
Dominant language
Rust
Stars
5.8k
Forks
333
Avg merge
2d 13h
Merged PRs (30d)
3

Description

Many applications today (or at least many CLI apps) rely on the idea of a "current directory" of the calling process (e.g. getcwd and chdir). Currently, though, WASI doesn't define what it means to have a current directory and implementations like wasi-libc don't have a getcwd symbol. For ease of porting applications, however, I think it might be good to support this concept.

I'm not entirely sure if this actually needs to manifest itself as new WASI APIs, however. They're even more low level than libc typically is and it may be possible to get away with having the concept of a current directory being entirely within wasi-libc. I wanted to open the issue here, though, to see if others felt the same and have some discussion with respect to WASI itself rather than just wasi-libc.

One idea I've got is that wasi-libc could interpret preopened paths as either absolute (starting with /) or relative to the root (those that don't start with /). Next a new syscall would be added:

(module $wasi_ephemeral_proc
  ;;; Returns the initial current directory of the application
  (@interface func (export "current_dir")
    (result $path string)
  )
)

And then wasi-libc would contain emulation of getcwd and chdir as necessary. This would allow applications which want to print paths relative to the current directory to be able to print values appropriately and applications could also be started in arbitrary locations as decided by the embedder.

In any case I'm curious if others have thought about this as well, and if there's other interest in supporting this as well.

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 reviewing the WASI process and filesystem interface discussions referenced in the issue, then compare the proposed current_dir syscall with keeping the concept inside wasi-libc. Check whether the project has since defined a current-directory model or related APIs. Done means reaching a maintainer-backed design decision and identifying the required WASI and wasi-libc changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.