Stream: general

Topic: Questions regarding `.wit` on web


view this post on Zulip Carson Rajcan (Jan 12 2024 at 19:55):

Hi all, new here, excited to be in the community.

I have a Rust lib crate which is sometimes used as a wasm component (run via wasmtime) and sometimes used as a regular Rust crate dependency when compiling for x86. Some of the exported types in this Rust lib are composed of types imported from bindings generated from a .wit file.

I would like to use this same Rust crate in a third scenario, a web app (leptos). I've tried a couple things to make this happen, and I have a couple more ideas, but I was wondering if anyone had any insight for this setup?

view this post on Zulip fitzgen (he/him) (Jan 12 2024 at 20:07):

I would personally suggest splitting your project into multiple crates:

view this post on Zulip Carson Rajcan (Jan 12 2024 at 20:42):

@fitzgen (he/him) thanks for the reply. This is similar to what I was thinking I would have to do, it will just take a little work.

view this post on Zulip fitzgen (he/him) (Jan 12 2024 at 21:10):

yeah it is usually easier when you design things that way from the start, but that also means that switching now is better than putting it off because it only gets harder as you add API surface and features

view this post on Zulip Karel Hrkal (kajacx) (Jan 14 2024 at 10:01):

If you want to load and run a wit component on the web in Rust, you can use wasm-bridge or wasm_component_layer.

Although since you have your crate as a normal Rust crate as well, you would probably be better off just including that as a normal dependency instead of loading it as a wit component.

Provides a single unified API to run WASM modules on the desktop using wasmtime, or on the web using js-sys. - GitHub - kajacx/wasm-bridge: Provides a single unified API to run WASM modules on the ...

view this post on Zulip Carson Rajcan (Jan 16 2024 at 23:53):

@Karel Hrkal (kajacx) wasm-bridge is really cool. I'll likely need to use it soon. Nice documentation!


Last updated: Dec 23 2024 at 12:05 UTC