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.
Many applications today (or at least many CLI apps) rely on the idea of a "current directory" of the calling process (e.g.
getcwdandchdir). Currently, though, WASI doesn't define what it means to have a current directory and implementations like wasi-libc don't have agetcwdsymbol. 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:And then
wasi-libcwould contain emulation ofgetcwdandchdiras 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.