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?
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.
Ah, bummer. I guess I'll have to stay in core-wasm-land this time.
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.
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.
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: Dec 23 2024 at 13:07 UTC