Skip to content

Commit d251dc0

Browse files
committed
add ability to run multiiple wasi versions
Signed-off-by: karthik2804 <[email protected]>
1 parent c7ad4f1 commit d251dc0

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/lib.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,28 @@ impl CommandTrigger {
9393

9494
let (instance, mut store) = instance_builder.instantiate(()).await?;
9595

96-
let func = {
97-
let instance_export = instance
98-
.get_export(&mut store, None, "wasi:cli/[email protected]")
99-
.context("failed to find the wasi:cli/[email protected] instance in component")?;
100-
101-
let func_export = instance
102-
.get_export(&mut store, Some(&instance_export), "run")
103-
.context("failed to find the \"run\" function in wasi:cli/[email protected] instance")?;
104-
105-
instance
106-
.get_typed_func::<(), (Result<(), ()>,)>(&mut store, func_export)
107-
.context("failed to get typed \"run\" function")?
108-
};
96+
let versions = ["0.2.3", "0.2.2", "0.2.1", "0.2.0"];
97+
let mut func = None;
98+
99+
for version in versions {
100+
if let Some(instance_export) =
101+
instance.get_export(&mut store, None, &format!("wasi:cli/run@{}", version))
102+
{
103+
if let Some(func_export) =
104+
instance.get_export(&mut store, Some(&instance_export), "run")
105+
{
106+
if let Ok(typed_func) =
107+
instance.get_typed_func::<(), (Result<(), ()>,)>(&mut store, func_export)
108+
{
109+
func = Some(typed_func);
110+
break;
111+
}
112+
}
113+
}
114+
}
115+
116+
let func = func
117+
.context("failed to find a compatible wasi:cli/run instance with a \"run\" function")?;
109118
let _ = func.call_async(&mut store, ()).await?;
110119

111120
Ok(())

0 commit comments

Comments
 (0)