Stream: cargo-component

Topic: `wasm-bindgen` crates -> `cargo component`s & `wasi`


view this post on Zulip Nuke ๐ŸŒ„ (Mar 17 2024 at 20:55):

I am looking for a tutorial (or even just some basic examples) on componentizing / refactoring existing crates targeting a web browser using wasm-bindgen and web_sys. I would assume this would include creation or generation of a wit interface that likely must include wasi in some way and (for now) #jco to be usable in a browser.

Is there such content yet? If not, I would be interested in helping craft such a demo around wasi 0.2.0 with plans to update for async for this: https://github.com/rustwasm/wasm-bindgen/tree/main/examples/fetch

view this post on Zulip Nuke ๐ŸŒ„ (Mar 17 2024 at 21:04):

Am I right to say that the wasi interface could (and likely should) totally abstract all effects, so your guest would be essentially functional outside the fully composed component, with a message or event driven design that calls in/out of wasi to do this?

view this post on Zulip Nuke ๐ŸŒ„ (Mar 17 2024 at 21:27):

As it stands in the existing example for fetch the whole thing is of course encapsulated in run but I would think a component-minded implementation would brake that logic up a bit more. In the contrast with a cargo component based project, I would want some more clean and granular interfaces defined...

view this post on Zulip Nuke ๐ŸŒ„ (Mar 17 2024 at 21:33):

For a component fetch tutorial I would start with cargo component new --lib and have the user-facing export a fetch: func(...) -> ... and form the request in a distinct component that import wasi:http/... to manage the (async eventually) GET. The intermediate component would have a distinct mod that would have functional core logic that is wrapped minimal in the lib to impl Gest for .... Perhaps a few intermediate components that import wasi:http and are composed into a higher level component that imports them and exports a higher-level method using both. :thinking:

Ideally that paves the way to an example of "write once, run with any wasi runtime... or at least any runtime that can provide import wasi:http". Bonus: this could enable exposing the core intermediate (and optionally pure functional) logic to be depended on in other rust crates that might not target wasm/wasi at all.


Last updated: Nov 25 2024 at 19:03 UTC