stephenmuss opened PR #9831 from stephenmuss:initial-cwd
to bytecodealliance:main
:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
This implements initial-cwd for wasi:cli/environment.My biggest struggle was finding the appropriate places to add tests. Any guidance would be appreciated. Thank you.
Closes #9695
stephenmuss requested fitzgen for a review on PR #9831.
stephenmuss requested wasmtime-core-reviewers for a review on PR #9831.
alexcrichton commented on PR #9831:
Thanks! I'd recommend adding a test to
crates/test-programs/bin/*.rs
and there's a small README about the tests in that directory.
stephenmuss commented on PR #9831:
I assume I should be able to use something like this in
crates/test-programs/bin/*.rs
to testfn main() -> std::io::Result<()> { let cwd = std::env::current_dir()?; assert_eq!(cwd.to_str(), Some("/tmp")); Ok(()) }
and run with
-S cwd=/tmp
.Is that understanding correct?
However, I always get
Some("/")
indicating that I still need to set the path somewhere I've missed, presumably insrc/commands/run.rs
andsrc/commands/serve.rs
etc.
alexcrichton commented on PR #9831:
Ah you'll probably need to use the WASI API directly rather than the standard library because the standard library isn't hooked up to this API yet.
Does the WASI API actually exist yet? Your issue about it is still open. Also as far as I can tell
initial_cwd()
isn't actually called from anywhere (though I may have missed it if there's some proc macro magic or something).
alexcrichton commented on PR #9831:
It exists insofar as the
*.wit
function exists and is stable. The issue you linked is from a long time ago and was intended for*.witx
or effectively WASIp1. WASIp1 isn't going to change any more but this function was added to enhance the functionality and largely solve that issue in WASIp2.To the extent the function exists, however, I'm also not familar with any integration with it. For example
wasi-libc
does not call the function and try to use the return value (nor does Rust's libstd). Hooking it up to Wasmtime, however, is step 1 in filling out ecosystem support for it though as otherwise it can't even be tested.
Last updated: Feb 28 2025 at 02:27 UTC