Call me a mad scientist for this, if you'd like.
I want to be able to, at runtime, satisfy a component's imports, using the exports of another component I have instantiated, without having to manually define each resource and function.
This doesn't seem possible right now. I want to make it possible. I have never contributed to wasmtime, and this is certainly a huge project to take on as a first contribution. I've been looking under the hood, and have some ideas, but I figure I should probably announce my intentions so people know I'm up to this. That way, I can hopefully ask questions, too.
@Julia DeMille a very interesting goal for sure!
it might help (me, anyway) to define a little more what you mean by dynamically/at runtime: do you mean that you want to start a component C, without any of its imports initially, and as external resources are called/used, dynamically fill them in somehow? or do you mean that you want a reflection-like introspection ability from within one component, to load another component, work out what it needs to instantiate, and invent/plug that in before starting it? or something else?
Chris Fallin said:
or do you mean that you want a reflection-like introspection ability from within one component, to load another component, work out what it needs to instantiate, and invent/plug that in before starting it?
This one—when loading in a component, being able to supply the Linker
with another component and have its exports satisfy whatever imports it can.
can you unpack "whatever imports it can" a bit -- is this a best-effort thing, where we're duck-type-matching things up and there may be some missing pieces? or is there a step in this system where we inspect the component, see it wants a world W with imports A, B, C, and put together exactly those?
Take the regex
and validator
components from the composing components page as an example. They would be matched based on the WIT, I suppose.
If there are imports not defined by a provided component, it would be on the user to define those before instantiating, as normal.
Possibly relevant: https://github.com/rylev/wepl
From the Features
section:
Satisfying imports with other WebAssembly Components
Joel Dice said:
Possibly relevant: https://github.com/rylev/wepl
Will take a look, thanks
That crate uses wasm_compose
, which has been superseded by wac. I guess I could try to work out how wac works.
it's all just code.
It looks like plug
in the wac-graph crate is the most notable function. It's doing... effectively what I planned to do?
It is using a graph instead of wasmtime's linker model, though. Still, shouldn't be terribly hard to adapt.
Yes, wac plug
does what it sounds like you're trying to do except statically, producing a new component. Based on my (limited) understanding of the wac-graph code I'm not sure that it will be directly translatable to the wasmtime Linker, but others might have a better understanding there.
Last updated: Dec 23 2024 at 13:07 UTC