Stream: general

Topic: Using component linking to simplify polyfills?


view this post on Zulip James Mart (Jan 05 2024 at 18:02):

I am starting to write a tool in rust that polyfills the wasi_snapshot_preview1 imports in a core wasm module. At a high level, originally I was thinking I would use something like walrus to parse the core module, delete the import, add the new function, an update the references to old function indices.

But now I am wondering if it would be easier to convert the core wasm to a component, compile a polyfill wasm to a component, compose them together into one single component, and then convert back to a core module. Would that work?

view this post on Zulip Joel Dice (Jan 05 2024 at 18:10):

AFAIK there's no general purpose tool for "flattening" a component into a core module. It's theoretically possible, but I don't think anyone has tried to do it.

view this post on Zulip James Mart (Jan 05 2024 at 18:12):

Ah, bummer. I guess I'll have to stay in core-wasm-land this time.

view this post on Zulip Victor Adossi (Jan 10 2024 at 02:14):

Hey I'm not sure if this would help, but have you taken a look at the WASI-virt codebase? there might be some interesting code there for you to look at when it comes to polyfilling/stubbing.

Virtual implementations of WASI APIs. Contribute to bytecodealliance/WASI-Virt development by creating an account on GitHub.

view this post on Zulip James Mart (Jan 10 2024 at 02:22):

Wow, thanks for the tip!

This code is extremely relevant to what I'm trying to do:
https://github.com/bytecodealliance/WASI-Virt/blob/6801514735cb78b385221e225c554bc043038c2f/src/virt_env.rs#L222

...It even uses Walrus which is the same parser I'm using.

view this post on Zulip Victor Adossi (Jan 10 2024 at 02:42):

Yeah, @Guy Bedford does a lot of work on both of those and created WASI-virt -- it was super helpful to me in trying to figure out how to use walrus properly!


Last updated: Nov 22 2024 at 17:03 UTC