From 73de56670710fb1a5b79fdc4e471a56e785b9139 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Mon, 21 Oct 2024 11:29:39 +0200 Subject: [PATCH 1/2] fix: Correct the `rust-version` in the workspace `Cargo.toml` --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 845f00f316e..a075100a1a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,7 +88,7 @@ edition = "2021" homepage = "https://wasmer.io/" license = "MIT" repository = "https://github.com/wasmerio/wasmer" -rust-version = "1.74" +rust-version = "1.81" version = "4.4.0" [workspace.dependencies] From 20e3c094df049c95b676846277dff7e814f3718e Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Mon, 21 Oct 2024 11:29:55 +0200 Subject: [PATCH 2/2] fix(wasix): Fix the example in the readme --- lib/wasix/README.md | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/wasix/README.md b/lib/wasix/README.md index 74f875a9683..052190faf08 100644 --- a/lib/wasix/README.md +++ b/lib/wasix/README.md @@ -60,27 +60,37 @@ Hello, Some("Gordon") … and programatically with the `wasmer` and the `wasmer-wasi` libraries: ```rust -use wasmer::{Store, Module, Instance}; -use wasmer_wasix::WasiState; +use std::io::Read; +use wasmer::{Module, Store}; +use wasmer_wasix::{Pipe, WasiEnv}; +let wasm_path = "hello.wasm"; + +// Let's declare the Wasm module with the text representation. +let wasm_bytes = std::fs::read(wasm_path)?; + +// Create a Store. let mut store = Store::default(); -let module = Module::from_file(&store, "hello.wasm")?; -// Create the `WasiEnv`. -let wasi_env = WasiState::builder("command-name") - .args(&["Gordon"]) - .finalize()?; +println!("Compiling module..."); +// Let's compile the Wasm module. +let module = Module::new(&store, wasm_bytes)?; + +let (stdout_tx, mut stdout_rx) = Pipe::channel(); + +// Run the module. +WasiEnv::builder("hello") + .args(&["Gordon"]) + // .env("KEY", "Value") + .stdout(Box::new(stdout_tx)) + .run_with_store(module, &mut store)?; -// Generate an `ImportObject`. -let mut wasi_thread = wasi_env.new_thread(); -let import_object = wasi_thread.import_object(&module)?; +eprintln!("Run complete - reading output"); -// Let's instantiate the module with the imports. -let instance = Instance::new(&module, &import_object)?; +let mut buf = String::new(); +stdout_rx.read_to_string(&mut buf).unwrap(); -// Let's call the `_start` function, which is our `main` function in Rust. -let start = instance.exports.get_function("_start")?; -start.call(&[])?; +eprintln!("Output: {buf}"); ``` Check the [fully working example using