mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-30 22:41:03 +00:00
Add experimental invoke support to WASI in wasmer cli
This commit is contained in:
parent
183beb769e
commit
356720efd2
@ -230,6 +230,23 @@ struct Run {
|
|||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Run {
|
||||||
|
/// Used with the `invoke` argument
|
||||||
|
fn parse_args(&self) -> Result<Vec<Value>, String> {
|
||||||
|
let mut args: Vec<Value> = Vec::new();
|
||||||
|
for arg in self.args.iter() {
|
||||||
|
let x = arg.as_str().parse().map_err(|_| {
|
||||||
|
format!(
|
||||||
|
"Can't parse the provided argument {:?} as a integer",
|
||||||
|
arg.as_str()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
args.push(Value::I32(x));
|
||||||
|
}
|
||||||
|
Ok(args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
enum LoaderName {
|
enum LoaderName {
|
||||||
@ -448,9 +465,7 @@ fn execute_wasi(
|
|||||||
let result;
|
let result;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
let cv_pushed = if let Some(msm) = instance.module.runnable_module.get_module_state_map() {
|
||||||
let cv_pushed =
|
|
||||||
if let Some(msm) = instance.module.runnable_module.get_module_state_map() {
|
|
||||||
push_code_version(CodeVersion {
|
push_code_version(CodeVersion {
|
||||||
baseline: true,
|
baseline: true,
|
||||||
msm: msm,
|
msm: msm,
|
||||||
@ -461,15 +476,27 @@ fn execute_wasi(
|
|||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(invoke_fn) = options.invoke.as_ref() {
|
||||||
|
eprintln!("WARNING: Invoking a function with WASI is not officially supported in the WASI standard yet. Use this feature at your own risk, things may not work!");
|
||||||
|
let args = options.parse_args()?;
|
||||||
|
let invoke_result = instance
|
||||||
|
.dyn_func(invoke_fn)
|
||||||
|
.map_err(|e| format!("Invoke failed: {:?}", e))?
|
||||||
|
.call(&args)
|
||||||
|
.map_err(|e| format!("Calling invoke fn failed: {:?}", e))?;
|
||||||
|
println!("{} returned {:?}", invoke_fn, invoke_result);
|
||||||
|
return Ok(());
|
||||||
|
} else {
|
||||||
result = start.call();
|
result = start.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
if cv_pushed {
|
if cv_pushed {
|
||||||
pop_code_version().unwrap();
|
pop_code_version().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(unix))]
|
|
||||||
{
|
|
||||||
result = start.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(ref err) = result {
|
if let Err(ref err) = result {
|
||||||
match err {
|
match err {
|
||||||
@ -755,16 +782,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
.instantiate(&import_object)
|
.instantiate(&import_object)
|
||||||
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
|
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;
|
||||||
|
|
||||||
let mut args: Vec<Value> = Vec::new();
|
let args = options.parse_args()?;
|
||||||
for arg in options.args.iter() {
|
|
||||||
let x = arg.as_str().parse().map_err(|_| {
|
|
||||||
format!(
|
|
||||||
"Can't parse the provided argument {:?} as a integer",
|
|
||||||
arg.as_str()
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
args.push(Value::I32(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
let invoke_fn = match options.invoke.as_ref() {
|
let invoke_fn = match options.invoke.as_ref() {
|
||||||
Some(fun) => fun,
|
Some(fun) => fun,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user