wabt icon indicating copy to clipboard operation
wabt copied to clipboard

Implement WebAssembly C API for wasm2c output

Open RReverser opened this issue 2 years ago • 2 comments

Not sure how feasible it would be, but it would be great if the generated C file implemented the WebAssembly C API for instantiation, dynamic enumeration of exports, integration with imports etc. for better interop with other engines.

RReverser avatar Jan 07 '23 15:01 RReverser

Sounds interesting for sure!

sbc100 avatar Jan 09 '23 11:01 sbc100

I think it would be quite feasible to do most of the Wasm C API -- basically all the parts that don't require interpreting Wasm at runtime. It would be challenging to support wasm_module_new (turning a Wasm binary into a wasm_module_t) unless we make the user link with libclang (to dynamically compile the wasm2c output at runtime) and then a runtime loader to load the resulting output into the binary. We have this working in research code but it's a big jump from where WABT is now.

But, I think it would be pretty straightforward for the wasm2c-generated code to provide a function that lets the user get a preproduced wasm_module_t from the already-built module, and then support most of the functions downstream from there (e.g. wasm_instance_new to instantiate the module from its imports). It could just be a command-line option to wasm2c to generate wrapper functions that wrap the generated code to expose the Wasm C API (or most of it) for a particular module.

If you think people would benefit from this or if it would expand usage of wasm2c, I think it would be a great addition!

keithw avatar Jan 11 '23 09:01 keithw