1
0
mirror of https://github.com/containers/youki synced 2024-11-29 21:11:29 +01:00

Lint & format

Signed-off-by: Thomas Schubart <24721048+Furisto@users.noreply.github.com>
This commit is contained in:
Thomas Schubart 2022-12-11 16:12:35 +01:00
parent 264db582dd
commit 84ab1655ae
4 changed files with 44 additions and 9 deletions

@ -1,7 +1,7 @@
use anyhow::{Context, Result};
use oci_spec::runtime::Spec;
use self::{default::DefaultExecutor};
use self::default::DefaultExecutor;
#[cfg(feature = "wasm-wasmedge")]
use self::wasmedge::WasmEdgeExecutor;
#[cfg(feature = "wasm-wasmer")]

@ -42,7 +42,8 @@ impl Executor for WasmerExecutor {
.finalize()?;
let store = Store::default();
let module = Module::from_file(&store, &args[0]).with_context(|| format!("could not load wasm module from {}", &args[0]))?;
let module = Module::from_file(&store, &args[0])
.with_context(|| format!("could not load wasm module from {}", &args[0]))?;
let imports = wasm_env
.import_object(&module)

@ -51,20 +51,29 @@ impl Executor for WasmtimeExecutor {
.with_context(|| format!("could not load wasm module from {}", &cmd))?;
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s).context("cannot add wasi context to linker")?;
wasmtime_wasi::add_to_linker(&mut linker, |s| s)
.context("cannot add wasi context to linker")?;
let wasi = WasiCtxBuilder::new()
.inherit_stdio()
.args(&args).context("cannot add args to wasi context")?
.envs(&envs).context("cannot add environment variables to wasi context")?
.args(args)
.context("cannot add args to wasi context")?
.envs(&envs)
.context("cannot add environment variables to wasi context")?
.build();
let mut store = Store::new(&engine, wasi);
let instance = linker.instantiate(&mut store, &module).context("wasm module could not be instantiated")?;
let start = instance.get_func(&mut store, "_start").ok_or(anyhow!("could not retrieve wasm module main function"))?;
let instance = linker
.instantiate(&mut store, &module)
.context("wasm module could not be instantiated")?;
let start = instance
.get_func(&mut store, "_start")
.ok_or_else(|| anyhow!("could not retrieve wasm module main function"))?;
start.call(&mut store, &mut[], &mut[]).context("wasm module was not executed successfully")
start
.call(&mut store, &[], &mut [])
.context("wasm module was not executed successfully")
}
fn can_handle(spec: &Spec) -> Result<bool> {

@ -0,0 +1,25 @@
This is a simple wasm module for testing purposes. It prints out the arguments given to the program and all environment variables. You can compile the module with
```
cargo build --target wasm32-wasi
```
If you want youki to execute the module you must copy it to the root file system of the container and reference it in the args of the config.json. You must also ensure that the annotations contain `"run.oci.handler": "wasm"` and that youki has been compiled with one of the supported wasm runtimes. For further information please check the [documentation](https://containers.github.io/youki/user/webassembly.html).
```
"ociVersion": "1.0.2-dev",
"annotations": {
"run.oci.handler": "wasm"
},
"process": {
"terminal": true,
"user": {
"uid": 0,
"gid": 0
},
"args": [
"/wasm-sample.wasm",
"hello",
"wasm"
],
```