wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

add linker to wasi preview2 that accepts custom closure

Open sehz opened this issue 1 year ago • 5 comments

Allow passing of closure to wasi command linking. Current add_to_linker is re-implemented more general API. Without this, it's hard to create reusable wasi context store

sehz avatar Jan 15 '24 23:01 sehz

Thanks for the PR, but this is something we were ideally hoping to avoid with the WasiView trait design. Would it be possible to implement WasiView for your type T within the Store<T>?

alexcrichton avatar Jan 16 '24 18:01 alexcrichton

Issue is that T is becoming very complex. Ideally Store should be composable. Key problem is that store is tied to linker which makes difficult separate host implementation

sehz avatar Jan 18 '24 00:01 sehz

I understand that T can be complex, and I also understand that writing a closure is shorter than writing a trait impl, but I'm not sure why the complexity would make trait impls more difficult (as opposed to a simple T). The fact that the store and linker are tied together is indeed a bit limiting, but with trait bounds it should be possible to design roughly the sme APIs.

Is there anything preventing the trait impls on T in your case?

alexcrichton avatar Jan 18 '24 16:01 alexcrichton

We chattec a bit more tonight about this and I think it's a reasonable enough feature to add given it's pretty small and solves a concrete use case. If you're ok fixing the failing test on CI (I think there's a new trait bound needed) I can r+

alexcrichton avatar Feb 01 '24 04:02 alexcrichton

Thanks. Will fix CI

sehz avatar Feb 01 '24 14:02 sehz