wasm backend as a shared library
Describe the bug
when attempting to compile a v program with both -shared and -b wasm, it doesn't behave like the C backend, giving an error if there is no main module and function.
Additionally, functions annotated with [export: 'name'] don't actually export under the provided name as they do with standard shared libraries for the C backend.
Expected Behavior
a .wasm file is created which exports the functions annotated as such, which can be called by a given wasm runtime.
Current Behavior
when compiling with -shared and structuring your program without a main method, the following error occurs:
[wasm-validator error in function _start] unexpected false: call target must exist, on
(call $main.main)
wasm error: validation failed, this should not happen. report an issue with the above messages
after adding an empty main method, running the generated .wasm file through an inspector doesn't list any of the exported functions under the names provided.
Reproduction Steps
compile the following code using v -b wasm -shared .
module my_wasm_lib
[export: "myFunction"]
fn my_function() {
println('Hello World!')
}
then change to the following
module main
[export: "myMainFunction"]
fn main() {
println('Hello World!')
}
and run the resulting binary through https://webassembly.github.io/wabt/demo/wasm2wat/, then do a search for myMainFunction
Possible Solution
Adding support for building as a shared library to the wasm backend would resolve this issue.
Additional Information/Context
I'm attempting to use V as a language for tic-80 through it's wasm scripting system. Eventually my aim is to port this header file to V and use it to interact with the tic-80 api, however due to this issue I can't get wasm exports (and by extension imports, although I haven't tried those) to work. I'm also aware that the wasm backend is still very new, and I don't expect these things to be all implemented. This issue is just to note that this needs a proper implementation.
V version
V 0.3.3 0bd0942
Environment details (OS name and version, etc.)
OS: linux, "Arch Linux"
CC version: cc (GCC) 12.2.1 20230201
V full version: V 0.3.3 2597efa.0bd0942
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
binaryen version: 1:112-1