From 9c2355117c8a9e9881dc5b02f865f4a8cf931233 Mon Sep 17 00:00:00 2001 From: Dominic Elm Date: Wed, 16 Aug 2023 09:27:52 +0200 Subject: [PATCH 1/2] Add ability to initialize cwd from PWD when targeting WASI --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4c83a0cd3..d2d942a70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,6 +63,13 @@ pub use settings::{opts_with_clap, RunMode}; pub fn run(init: impl FnOnce(&mut VirtualMachine) + 'static) -> ExitCode { env_logger::init(); + #[cfg(target_os = "wasi")] + { + if let Ok(pwd) = env::var("PWD") { + let _ = env::set_current_dir(pwd); + }; + } + let (settings, run_mode) = opts_with_clap(); // Be quiet if "quiet" arg is set OR stdin is not connected to a terminal From 3131d56298b056f98aa0c8688e0ccd89a012d3c0 Mon Sep 17 00:00:00 2001 From: Dominic Elm Date: Wed, 23 Aug 2023 11:28:17 +0200 Subject: [PATCH 2/2] fixup: add note --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index d2d942a70..c9ff15354 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,6 +63,7 @@ pub use settings::{opts_with_clap, RunMode}; pub fn run(init: impl FnOnce(&mut VirtualMachine) + 'static) -> ExitCode { env_logger::init(); + // NOTE: This is not a WASI convention. But it will be convenient since POSIX shell always defines it. #[cfg(target_os = "wasi")] { if let Ok(pwd) = env::var("PWD") {