assemblyscript
assemblyscript copied to clipboard
support to bind wasm
Feature suggestion
I think it will improve the software community ecology if we can support bind wasm which satisfies the requirement of linking. It means we can call c/c++(maybe other language based on LLVM like rust but I don't try it) function in assemblyscript.
How to implement in assemblyscript:
First step we can add a command line option to preload one wasm file and add it into Program instance and then compile wasm module.
Second step maybe statement like import * as xxx from "xxx.wasm" can be supported, but it needs more effort.
I wonder if this proposal meets the roadmap of the community and if this PR can be merged into main.
How to handle multiple memory manager:
Memory.grow in wasm should be checked and it will trigger a compile-time Error. For c/cpp, most of code will alloc memory by malloc / free / realloc in libc, so it can be resolved by using custom libc. e.g. https://github.com/WebAssembly/wasi-sdk
On a sidenote, specifying MALLOC_IMPL=none when compiling wasi-libc won't compile any malloc implementation, which lets us provide our own. Alternatively, we could fork wasi-libc and add our own implementation there.
On a sidenote, specifying
MALLOC_IMPL=nonewhen compilingwasi-libcwon't compile anymallocimplementation, which lets us provide our own.
I think it is enough, we need to design some way to bind the import and export from wasm to as.
First step we can add a command line option to preload one wasm file and add it into Program instance and then compile wasm module.
There is more to this if we want to link properly. For instance, if the preloaded module has a static memory region and a heap region, besides reusing an existing / providing a shared malloc/free, AS would still need to add to the static memory region, which then conflicts with the preloaded module's heap region that typically starts right after. Can't get around relocatable modules, likely with some metadata, akin to what the dylink section does.
Forget about wasi-libc btw., that's overly specific and won't really help with linking anyway.