ije / md4w

A Markdown renderer written in Zig & C, compiled to WebAssymbly.
MIT License
58 stars 0 forks source link

Support WebAssembly ESM Integration / unwasm #1

Closed pi0 closed 6 months ago

pi0 commented 7 months ago

Hi! Kinda excited to see this project since I was planning to work on some markdown utils pkg and was looking for a fast native parser, this is an amazing effort 🔥

Some context:

There is an outstanding proposal from WebAssmbly working group to support .wasm imports as ESM imports, resolving the ever-lasting issues of inconsistent WASM support across platforms and tools.

Besides this, we have Cloudflare Workers that have their specific requirement that requires a wasm import to be predictable (and not compiled on demand) (and other worker runtimes that don't like top-level await for init)

To allow widely adopting wasm libraries within Nuxt and UnJS ecosystems, I have recently started working on unwasm which is an effort to allow adopting ESM WASM modules ahead of time in toolings and allow a universal way of wasm module consumption. unwasm is under development but also constantly tested to make sure has maximum compatibility at the same time.

What is required for it to work?

A small refactor to split the init functionality from the rest of logic (mem alloc, and util exports).

If you are interested, I can happily make a minimal environment for you to easily try this.

pi0 commented 7 months ago

Update: Made this https://github.com/pi0/nitro-md4w.git

See https://github.com/pi0/nitro-md4w/blob/main/utils/md4w.ts for expected entrypoint (we might use unwasm export condition too btw)

ije commented 7 months ago

Thank you @pi0 🧡 unjs/unwasm is amazing!

i just added the unwasmexport condition(workerd for CF as well), does this work with nitropack? wrangler should work now. check https://github.com/ije/md4w/pull/2/files#diff-e51a40ac250c9696142466f114f754161e7e5102c0cdb5354548b757deb272f6R11

pi0 commented 7 months ago

Thanks! I will double check but i guess reordering conditions to unwasm > workerd would be nice to make sure unwasm will be used. Even if it works, in the future it allows more advanced possibilities such as tree-shaking with more wasm exports.

ije commented 7 months ago

Thank you! (just moved unwasm to top)