Stream: jco

Topic: 'wrapper' component?


view this post on Zulip Ben Sully (Oct 12 2024 at 09:33):

Hello! I'm experimenting with jco as an alternative to wasm-pack for providing JS bindings to a library I'm writing. The library is written in Rust as a bunch of separate crates, and I was hoping I could:

  1. wrap each of the crates in a component to expose their functionality individually
  2. create a 'wrapper' component which just imports/exports all of their functionality.
    I was thinking I could then use jco transpile on the wrapper component to get nice JS bindings with types and stuff, rather than having to write a bunch of bindings by hand like I do for wasm-pack. Plus the component could be used from other languages, too.

I've been trying to do this for a little while and have got a bit stuck, so figured it's time to ask!

  1. Is this actually possible? and what would be the right incantation of wasm-tools to generate a WASM file from the WIT (which really only contains imports/exports in the world)
  2. Is this a good idea? I'm not actually sure it's easier than just writing the bindings by hand (since I need to write the component impls), but there are several other benefits...
  3. I have no idea if this is possible, but it would be _really_ cool if I could separate out the instantiation of all the separate components, so that e.g. a JS user importing @bsull/library/foo didn't also have to instantiate @bsull/library/bar, etc. That might be a pipe dream and require a manual wrapper library though?

aside, I've been impressed with how much all of the tooling 'just works' so far (when I get things lined up correctly), thanks for that!


Last updated: Nov 22 2024 at 17:03 UTC