-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasmer and dynamic set of host functions #1251
Comments
The high-level API that allows to statically specify imports is a declarative macro wasmer/lib/runtime-core/src/macros.rs Line 78 in 73370b9
which means that there isn't too much magic in it and it's possible to do the same thing outside The code to dynamically specify imports would be like: let mut import_object = ImportObject::new();
let mut ns = Namespace::new();
ns.insert("func1", func1_impl);
ns.insert("func2", func2_impl);
import_object.register("my_namespace", ns);
// now we can use import_object |
Yep, I checked that in the very beginning of my journey. The part which is unclear is how to actually obtain |
Okay so the problem is with dynamically-typed imports. Yeah the current way to do that in the The new API would be like: let func = ErasedFunc::new_polymorphic(
Arc::new(FuncSig::new(vec![Type::I32], vec![Type::I32])),
|ctx, params| -> Vec<Value> {
match params[0] {
Value::I32(x) => vec![Value::I32(x + 1)],
_ => unreachable!()
}
}
); |
I think this would be exactly what I am looking for! |
We just merged #1217 into master. The final API looks very similar to what @losfair commented: let func = DynamicFunc::new(
Arc::new(FuncSig::new(vec![Type::I32], vec![Type::I32])),
|ctx, params| -> Vec<Value> {
match params[0] {
Value::I32(x) => vec![Value::I32(x + 1)],
_ => unreachable!()
}
}
); We will be releasing a new version of Wasmer soon. Let us know if this fully fits your needs @pepyakin :) |
Hey! Found some time to test that and got the following questions:
And the third, the most important part. I wasn't able to figure out how to actually implement what I aimed to do. As a recap: I have a dynamic set of host functions that are not known in advance (number of them, names, signatures or their bodies). Therefore, I need to somehow create these functions so each individual dynamic function would know where to pass control after it was called. First thing I tried is to pass some sort of context into the closure. However, I learned the hard way ("DynamicFunc with captured environment is not yet supported") that the passed function is not actually a closure but rather a function since it cannot close over any variables. Then, I guessed that maybe the
I read that as if The only way I can see this could possible work atm, is to statically instantiate a lot of Maybe I am missing something? If not, are there are any plans to lift the limitation wrt closures? |
With the default configuration the runtime will enforce the closure passed to |
The lifetime on Panic handling is indeed missing - will fix it. |
Ah, thanks for pointing out! I actually was looking for something like this in the docs source but couldn't find anything but it seems it is in master already. I think that can help me move forward. No need for a release I am able to prototype with master for now. |
Was this supposed to be solved actually? FWIW, I am still seeing |
Can you provide an example to reproduce the error? Panics from a |
Yep, so my code is basically this: DynamicFunc::new(
Arc::new(FuncSig::new(params, returns)),
move |ctx, args| -> Vec<wasmer_runtime_core::types::Value> {
dbg!();
vec![]
},
)
.to_export() The debugger shows me the following backtrace (stripped)
which looks like that the segfault happens before my code is ran. |
I think it is right time to mention that I am running macOS 10.15.3 and building in the debug mode. |
The problem seems to be in |
To clarify will it be fixed upstream or you say that this would be the solution? |
We would like to fix this ASAP since it's a soundness bug, but it might be a breaking change (requires change to the public |
Hi! I'm also trying to dynamically specify imports as it was suggested above but getting error that compiler cannot find Namespace structure.
and it sees pretty good ImportObject structure but not Namespace. |
@HaronK it looks like it's not exposed in the It's also available from |
Ah! Thanks! I'm experimenting right now so I think it's ok to use wasmer_runtime_core. |
We are working on a refactor of Wasmer. Once it lands in |
Thanks for the heads up! |
We just landed the refactor in Let us know if you need any help using them @pepyakin Closing the issue |
I am playing with embedding wasmer as a backend into substrate. While doing this, I discovered that the high-level API assumes that the set of imports is known statically - for my use-case this is not the case. At least I haven't seen any APIs that would (easily) allow to do so. I wasn't able to find any examples that would show how to proper achieve that as well.
I thought I would be able to workaround that basically by getting inspired by this example and calling the same Rust functions.
However, regardless that I am essentially doing the same I am observing some weird behavior.
So the question is, do you have an advice on how to integrate wasmer with a dynamic set of host functions?
The text was updated successfully, but these errors were encountered: