Stream: wasmtime

Topic: ✔ WasiCtx and component::Linker


view this post on Zulip Jesse Wellenberg (Yeseh) (Feb 14 2023 at 15:28):

Is there a path to get WasiCtx working with Wasmtime component hosts generated with bindgen!()? Currently wasmtime_wasi::add_to_linker requires a 'normal' module linker so there doesn't seem to be an obvious way to have a host supply WASI imports to a component. I created my component with the snapshot1 adapter.

Just curious if this is possible right now, I realize this is at the edge of a lot of ongoing work :)

view this post on Zulip Ramon Klass (Feb 14 2023 at 15:59):

this is very much the bleeding edge ;) I got this far:
https://github.com/bytecodealliance/preview2-prototyping/blob/main/host/src/main.rs this is how it's supposed to work once everything is finished
but wasi_cap_std_sync::WasiCtxBuilder can't be imported right now, so using this host crate as a lib seems to be currently just not intended

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - preview2-prototyping/main.rs at main · bytecodealliance/preview2-prototyping

view this post on Zulip Alex Crichton (Feb 14 2023 at 15:59):

If you've got a component then the existing wasmtime-wasi crate won't work for you since it's working at the core wasm abstraction layer which isn't compatible. This means that the quick answer to your question is "no, wasmtime_wasi::add_to_linker will not get component support".

The full answer is a bit more nuanced. Your component imports WASI-related functionality, it's just at the component model layer of abstraction. Currently there is not a built-in crate in Wasmtime itself to implement this functionality. The preview2-prototyping repository, however, has a work-in-progress implementation that we'll eventually e upstraming into Wasmtime.

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - GitHub - bytecodealliance/preview2-prototyping: Polyfill adapter for preview1-using wasm modules to call preview2 func...

view this post on Zulip Ramon Klass (Feb 14 2023 at 16:00):

@Alex Crichton would it be possible to reexport that bulder in host/src/lib.rs so we can try out wasi reactors?

view this post on Zulip Alex Crichton (Feb 14 2023 at 16:01):

by "that" what do you mean?

view this post on Zulip Ramon Klass (Feb 14 2023 at 16:03):

https://github.com/bytecodealliance/preview2-prototyping/blob/main/host/src/main.rs#L4

wasi_cap_std_sync is not in the workspace of the repo, so only crates inside the repo can import from it. main.rs imports the WasiCtxBuilder so it can use it, but lib.rs neither imports nor reexports it so if you try to use host as a lib you won't get a WasiCtxBuilder

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - preview2-prototyping/main.rs at main · bytecodealliance/preview2-prototyping

view this post on Zulip Alex Crichton (Feb 14 2023 at 16:05):

oh the preview2-protoyping repo is very much still in the "prototyping" state meaning it hasn't finished design for "how will this be used externally", so questions about how to use I think will get answered in time but for now you'll need to get your hands dirty I think to work with it

view this post on Zulip Alex Crichton (Feb 14 2023 at 16:05):

I should clarify that I am not myself working very closely on the implementation at this time, for specific questions I'd reach out to Pat/Dan

view this post on Zulip Jesse Wellenberg (Yeseh) (Feb 14 2023 at 16:08):

Thanks for the answer! The preview2 prototyping might do it for my current playing around :)

view this post on Zulip Notification Bot (Feb 17 2023 at 11:49):

Jesse Wellenberg (Yeseh) has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC