DouglasDwyer / wasm_component_layer

WebAssembly component model implementation for any backend.
74 stars 13 forks source link

[Question] Trampolines and WASI support #21

Open TitusVM opened 4 weeks ago

TitusVM commented 4 weeks ago

Hi all!

I'm trying to use the wasm_component_layer (with the wasmtime_runtime_layer) to run a simple composed component I made from the WASM documentation example. However, I ran into this line which made me wonder if I'm trying to do something that the tool isn't meant for. I'm having some trouble understanding what roles trampolines play in this scenario. I have a felling that it may be linked to wasi support missing but again, I'm not entirely sure.

Any help would be greatly appreciated 👍

DouglasDwyer commented 3 weeks ago

Hey there, thanks for trying out wasm_component_layer. Right now, there is not support for composed components. The way composed components are implemented in wasmtime (the reference component model implementation) relies on the WASM multi-memory feature. When instantiating each component, each sub-component gets its own memory, and there are some "trampoline" functions that the host generates so that sub-components can call one another.

Multi-memory is not a core WASM feature, and thus an approach like that hasn't been implemented in this library. I think that the first implementation step would be to look at how jco handles composed components, since jco targets browser (which does not have multi-memory either). Maybe there's a workaround from there that could be applied.

Anyhow, I am not working on WASM-related projects right now - so unfortunately I will not be addressing this issue. Nonetheless, feel free to submit a PR if you end up figuring out the problem.

TitusVM commented 2 weeks ago

Thank you for the additional information! Yes, I thought as much as I couldn't find a lot of information about it anywhere. Basically what I'm trying to do is compose components and then run them programmatically, but I'm having trouble finding a good way to do this either using a runtime (in my case wasmtime) or a tool like wasm_component_layer (my preferred option because it's runtime agnostic). I don't understand how exactly wasmtime executes composed components. I'll try what you suggested, but I'm afraid it might be outside the scope of my project.