Building a WASM client
For our client, we must serialize and deserialize data, and load the WASM file. Because of this, we have the following dependencies:
// File: wasm-client/Cargo.toml
[dependencies]
serde = { version = "1.0.197", features = ["derive"] }
tokio = { version = "1.37.0", features = ["full"] }
bincode = "1.3.3"
kernel = { path = "../kernel" }
wasmtime-wasi = { version = "20.0.0", features = ["preview1"]}
wasmtime = "20.0.0"
Now in our dependencies are defined, we can start building the client with the outline below:
// File: wasm-client/src/main.rs
use wasmtime::{Result, Engine, Linker, Module, Store, Config};
use wasmtime_wasi::preview1::{self, WasiP1Ctx};
use wasmtime_wasi::WasiCtxBuilder;
use std::mem::size_of;
use std::slice::from_raw_parts;
use kernel::{
SomeDataStruct,
ResultPointer
};
#[tokio::main]
async fn main() -> Result<()> {
. . .
}
Inside our...