bjorn3 / browser_wasi_shim

A WASI shim for in the browser
Apache License 2.0
310 stars 41 forks source link

Support Wasm Component Model #33

Open DougAnderson444 opened 1 year ago

DougAnderson444 commented 1 year ago

@bjorn3 as I mentioned here https://github.com/bytecodealliance/jco/issues/42#issuecomment-1597139850 I think the way to go about supporting the component model is:

  1. Generate the files, imports and exports using the wasm-compiled js-component-bindgen-component
import { generate } from './js-component-bindgen-component.js`
let { files, imports, exports } = generate(component, opts);
  1. Write a Rollup plugin that takes the 3 generated bytes above and bundles them into an output.
  2. Consumers can then take the bundled output do things like inject it into <head><script>... so it can be used by the window.
bjorn3 commented 1 year ago

Ideally it would be possible to do everything in the browser such that a separate build step for users is not necessary. If that is not feasible a rollup plugin would be fine with me. I don't have any experience with rollup though so I don't know how easy it would be for me to implement.

bjorn3 commented 1 year ago

By the way do you know if browsers intend to support the component model in the (near) future?

DougAnderson444 commented 1 year ago

Ideally it would be possible to do everything in the browser such that a separate build step for users is not necessary. If that is not feasible a rollup plugin would be fine with me. I don't have any experience with rollup though so I don't know how easy it would be for me to implement.

It can indeed all be done in the browser. Rollup can actually be run in the browser too! (Not many people know this).

So what we would have is: Import the component bytes, get loaded JS in the same page. No (non-browser) build step.

I'll see if I can whip up a Rollup plugin for these files.

DougAnderson444 commented 1 year ago

So I wrote the Rollup Plugin 🚀

https://github.com/DougAnderson444/rollup-plugin-wit-component

Needs a bit of cleanup, polish, and a demo to show how to import a *.component.wasm into the browser and use the functions. But it works =)

DougAnderson444 commented 1 year ago

By the way do you know if browsers intend to support the component model in the (near) future?

I do not know. I suspect the answer is "not anytime soon."