Skip to content

Commit d056201

Browse files
authored
Merge pull request #5040 from d3lm/delm/feat/wasi/set-current-dir
Add ability to initialize cwd from PWD when targeting WASI
2 parents 93d731c + 3131d56 commit d056201

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ pub use settings::{opts_with_clap, RunMode};
6363
pub fn run(init: impl FnOnce(&mut VirtualMachine) + 'static) -> ExitCode {
6464
env_logger::init();
6565

66+
// NOTE: This is not a WASI convention. But it will be convenient since POSIX shell always defines it.
67+
#[cfg(target_os = "wasi")]
68+
{
69+
if let Ok(pwd) = env::var("PWD") {
70+
let _ = env::set_current_dir(pwd);
71+
};
72+
}
73+
6674
let (settings, run_mode) = opts_with_clap();
6775

6876
// Be quiet if "quiet" arg is set OR stdin is not connected to a terminal

0 commit comments

Comments
 (0)