diff --git a/docs/migration_to_3.0.0.md b/docs/migration_to_3.0.0.md index dc8d2b45e..f4aab9092 100644 --- a/docs/migration_to_3.0.0.md +++ b/docs/migration_to_3.0.0.md @@ -84,7 +84,7 @@ pub struct MyEnv { pub memory: wasmer::LazyInit, #[wasmer(export(name = "__alloc"))] pub alloc_guest_memory: LazyInit>, - + pub multiply_by: u32, } @@ -153,7 +153,7 @@ let str = ptr.read_utf8_string(&memory_view, length as u32).unwrap(); println!("Memory contents: {:?}", str); ``` -The reason for this change is that in the future this will enable +The reason for this change is that in the future this will enable safely sharing memory across threads. The same thing goes for reading slices: ```rust @@ -199,7 +199,7 @@ let instance = Instance::new(&mut store, &module, &import_object).expect("Could For WASI, don't forget to initialize the `WasiEnv` (it will import the memory) ```rust -let mut wasi_env = WasiState::new("hello").finalize()?; +let mut wasi_env = WasiState::builder("hello").finalize()?; let import_object = wasi_env.import_object(&mut store, &module)?; let instance = Instance::new(&mut store, &module, &import_object).expect("Could not instantiate module."); wasi_env.initialize(&mut store, &instance).unwrap(); diff --git a/examples/wasi.rs b/examples/wasi.rs index b8880b5d5..d7c3f31f2 100644 --- a/examples/wasi.rs +++ b/examples/wasi.rs @@ -39,7 +39,7 @@ fn main() -> Result<(), Box> { println!("Creating `WasiEnv`..."); // First, we create the `WasiEnv` - let mut wasi_env = WasiState::new("hello") + let mut wasi_env = WasiState::builder("hello") // .args(&["world"]) // .env("KEY", "Value") .finalize(&mut store)?; diff --git a/examples/wasi_pipes.rs b/examples/wasi_pipes.rs index 8f1c41c26..c39dc8520 100644 --- a/examples/wasi_pipes.rs +++ b/examples/wasi_pipes.rs @@ -38,7 +38,7 @@ fn main() -> Result<(), Box> { // First, we create the `WasiEnv` with the stdio pipes let mut input = Pipe::new(); let mut output = Pipe::new(); - let wasi_env = WasiState::new("hello") + let wasi_env = WasiState::builder("hello") .stdin(Box::new(input.clone())) .stdout(Box::new(output.clone())) .finalize(&mut store)?; diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 62c71e6ae..76943a774 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -43,7 +43,7 @@ pub unsafe extern "C" fn wasi_config_new( inherit_stdout: true, inherit_stderr: true, inherit_stdin: true, - state_builder: WasiState::new(prog_name), + state_builder: WasiState::builder(prog_name), })) } diff --git a/lib/cli/src/commands/run/wasi.rs b/lib/cli/src/commands/run/wasi.rs index c62d68a2a..619394b08 100644 --- a/lib/cli/src/commands/run/wasi.rs +++ b/lib/cli/src/commands/run/wasi.rs @@ -113,7 +113,7 @@ impl Wasi { let runtime = Arc::new(PluggableRuntimeImplementation::default()); - let mut wasi_state_builder = WasiState::new(program_name); + let mut wasi_state_builder = WasiState::builder(program_name); wasi_state_builder .args(args) .envs(self.env_vars.clone()) diff --git a/lib/wasi/README.md b/lib/wasi/README.md index 81a2985e4..e65e2508d 100644 --- a/lib/wasi/README.md +++ b/lib/wasi/README.md @@ -23,10 +23,10 @@ WASI easily from the Wasmer runtime, through our `ImportObject` API. ## Supported WASI versions -| WASI version | Support | -|-|-| -| `wasi_unstable` | ✅ | -| `wasi_snapshot_preview1` | ✅ | +| WASI version | Support | +| ------------------------ | ------- | +| `wasi_unstable` | ✅ | +| `wasi_snapshot_preview1` | ✅ | The special `Latest` version points to `wasi_snapshot_preview1`. @@ -67,7 +67,7 @@ let mut store = Store::default(); let module = Module::from_file(&store, "hello.wasm")?; // Create the `WasiEnv`. -let wasi_env = WasiState::new("command-name") +let wasi_env = WasiState::builder("command-name") .args(&["Gordon"]) .finalize()?; diff --git a/lib/wasi/src/os/console/mod.rs b/lib/wasi/src/os/console/mod.rs index de07cd7ed..10ad7d700 100644 --- a/lib/wasi/src/os/console/mod.rs +++ b/lib/wasi/src/os/console/mod.rs @@ -165,7 +165,7 @@ impl Console { let wasi_thread = wasi_process.new_thread(); // Create the state - let mut state = WasiState::new(prog); + let mut state = WasiState::builder(prog); if let Some(stdin) = self.stdin.take() { state.stdin(Box::new(stdin)); } diff --git a/lib/wasi/src/runners/wasi.rs b/lib/wasi/src/runners/wasi.rs index 46a422941..fdee283d4 100644 --- a/lib/wasi/src/runners/wasi.rs +++ b/lib/wasi/src/runners/wasi.rs @@ -81,7 +81,7 @@ fn prepare_webc_env( .collect::>(); let filesystem = Box::new(WebcFileSystem::init(webc, &package_name)); - let mut wasi_env = WasiState::new(command); + let mut wasi_env = WasiState::builder(command); wasi_env.set_fs(filesystem); wasi_env.args(args); for f_name in top_level_dirs.iter() { diff --git a/lib/wasi/src/state/builder.rs b/lib/wasi/src/state/builder.rs index 768ae139d..e941429ac 100644 --- a/lib/wasi/src/state/builder.rs +++ b/lib/wasi/src/state/builder.rs @@ -24,7 +24,7 @@ use crate::{ /// Creates an empty [`WasiStateBuilder`]. /// -/// Internal method only, users should call [`WasiState::new`]. +/// Internal method only, users should call [`WasiState::builder`]. pub(crate) fn create_wasi_state(program_name: &str) -> WasiStateBuilder { WasiStateBuilder { args: vec![program_name.to_string()], @@ -38,7 +38,7 @@ pub(crate) fn create_wasi_state(program_name: &str) -> WasiStateBuilder { /// ```no_run /// # use wasmer_wasi::{WasiState, WasiStateCreationError}; /// # fn main() -> Result<(), WasiStateCreationError> { -/// let mut state_builder = WasiState::new("wasi-prog-name"); +/// let mut state_builder = WasiState::builder("wasi-prog-name"); /// state_builder /// .env("ENV_VAR", "ENV_VAL") /// .arg("--verbose") @@ -263,7 +263,7 @@ impl WasiStateBuilder { /// ```no_run /// # use wasmer_wasi::{WasiState, WasiStateCreationError}; /// # fn main() -> Result<(), WasiStateCreationError> { - /// WasiState::new("program_name") + /// WasiState::builder("program_name") /// .preopen(|p| p.directory("src").read(true).write(true).create(true))? /// .preopen(|p| p.directory(".").alias("dot").read(true))? /// .build()?; diff --git a/lib/wasi/src/state/mod.rs b/lib/wasi/src/state/mod.rs index dd211228b..16cd52cf9 100644 --- a/lib/wasi/src/state/mod.rs +++ b/lib/wasi/src/state/mod.rs @@ -226,7 +226,7 @@ impl WasiBusState { /// ```no_run /// # use wasmer_wasi::{WasiState, WasiStateCreationError}; /// # fn main() -> Result<(), WasiStateCreationError> { -/// WasiState::new("program_name") +/// WasiState::builder("program_name") /// .env(b"HOME", "/home/home".to_string()) /// .arg("--help") /// .envs({ diff --git a/lib/wasi/tests/catsay.rs b/lib/wasi/tests/catsay.rs index ff49e61cd..2bcc103cd 100644 --- a/lib/wasi/tests/catsay.rs +++ b/lib/wasi/tests/catsay.rs @@ -71,7 +71,7 @@ async fn test_catsay() { async fn run_test(mut store: Store, module: Module) { // Create the `WasiEnv`. let mut stdout = Pipe::default(); - let mut wasi_state_builder = WasiState::new("catsay"); + let mut wasi_state_builder = WasiState::builder("catsay"); let mut stdin_pipe = Pipe::default(); diff --git a/lib/wasi/tests/condvar.rs b/lib/wasi/tests/condvar.rs index 0528dd45c..2a7976df7 100644 --- a/lib/wasi/tests/condvar.rs +++ b/lib/wasi/tests/condvar.rs @@ -59,7 +59,7 @@ async fn test_condvar() { async fn run_test(mut store: Store, module: Module) { // Create the `WasiEnv`. let mut stdout = Pipe::default(); - let mut wasi_state_builder = WasiState::new("multi-threading"); + let mut wasi_state_builder = WasiState::builder("multi-threading"); let mut wasi_env = wasi_state_builder .stdout(Box::new(stdout.clone())) diff --git a/lib/wasi/tests/coreutils.rs b/lib/wasi/tests/coreutils.rs index b8361f8c0..5369b8f49 100644 --- a/lib/wasi/tests/coreutils.rs +++ b/lib/wasi/tests/coreutils.rs @@ -63,7 +63,7 @@ async fn test_coreutils() { async fn run_test(mut store: Store, module: Module) { // Create the `WasiEnv`. let mut stdout = Pipe::default(); - let mut wasi_state_builder = WasiState::new("echo"); + let mut wasi_state_builder = WasiState::builder("echo"); wasi_state_builder.args(&["apple"]); let mut wasi_env = wasi_state_builder diff --git a/lib/wasi/tests/multi-threading.rs b/lib/wasi/tests/multi-threading.rs index e39bd3bd6..cdb470019 100644 --- a/lib/wasi/tests/multi-threading.rs +++ b/lib/wasi/tests/multi-threading.rs @@ -58,7 +58,7 @@ async fn test_multithreading() { async fn run_test(mut store: Store, module: Module) { // Create the `WasiEnv`. let mut stdout = Pipe::default(); - let mut wasi_state_builder = WasiState::new("multi-threading"); + let mut wasi_state_builder = WasiState::builder("multi-threading"); let mut wasi_env = wasi_state_builder .stdout(Box::new(stdout.clone())) diff --git a/lib/wasi/tests/stdio.rs b/lib/wasi/tests/stdio.rs index 7edea779e..e0ab91bb0 100644 --- a/lib/wasi/tests/stdio.rs +++ b/lib/wasi/tests/stdio.rs @@ -75,7 +75,7 @@ async fn test_stdout() { let mut pipe = WasiBidirectionalSharedPipePair::default(); // FIXME: evaluate if needed (method not available on ArcFile) // pipe.set_blocking(false); - let mut wasi_env = WasiState::new("command-name") + let mut wasi_env = WasiState::builder("command-name") .args(&["Gordon"]) .stdout(Box::new(pipe.clone())) .finalize(&mut store) @@ -116,7 +116,7 @@ async fn test_env() { let mut pipe = WasiBidirectionalSharedPipePair::default(); // FIXME: evaluate if needed (method not available) // .with_blocking(false); - let mut wasi_state_builder = WasiState::new("command-name"); + let mut wasi_state_builder = WasiState::builder("command-name"); wasi_state_builder .args(&["Gordon"]) .env("DOG", "X") @@ -164,7 +164,7 @@ async fn test_stdin() { let buf = "Hello, stdin!\n".as_bytes().to_owned(); pipe.write(&buf[..]).await.unwrap(); - let mut wasi_env = WasiState::new("command-name") + let mut wasi_env = WasiState::builder("command-name") .stdin(Box::new(pipe.clone())) .finalize(&mut store) .unwrap(); diff --git a/tests/lib/wast/src/wasi_wast.rs b/tests/lib/wast/src/wasi_wast.rs index 46c14b52f..afef3bbc8 100644 --- a/tests/lib/wast/src/wasi_wast.rs +++ b/tests/lib/wast/src/wasi_wast.rs @@ -160,7 +160,7 @@ impl<'a> WasiTest<'a> { mpsc::Receiver>, mpsc::Receiver>, )> { - let mut builder = WasiState::new(self.wasm_path); + let mut builder = WasiState::builder(self.wasm_path); let stdin_pipe = WasiBidirectionalPipePair::new().with_blocking(false); builder.stdin(Box::new(stdin_pipe));