WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.5k stars 744 forks source link

Compiling and linking wat files #2276

Open ljulliar opened 5 years ago

ljulliar commented 5 years ago

If I understand correctly wasm-as turns a wat source file into wasm file. But is it a wasm object file that can be linked with other wasm object files (with wasm-ld for instance) ?

I saw that wasm-merge disappeared from binaryen some time ago. THat was the tool to "link" several wasm files together wasn't it ? Any alternative tools to link wasm files together ?

Thank you!

tlively commented 5 years ago

Binaryen currently doesn't know how to reason fully about wasm object files. Can I ask where your wasm modules are coming from and why you want to merge them? That will help us figure out what the best tool for your job is.

ljulliar commented 5 years ago

I am actually developing quite a sizeable application directly using the WASM text format (WAT). I handle everything in a single file right now but it's already quite bulky and I feel a need to split this into several modules and use the proper import / export in each of them and link them together at the end.

So to summarize the outcome of my investigations so far: 1) wat2wasm (from wabt) generate incomplete wasm object files right now (symbil table is missing) and wasm-ld isn't happy about it 2) llvm-as doesn't seem to accept the WAT format as an input 3) and binary ditched wasm-merge

So right now I haven't yet found a working compilation chain that take WAT source files and turn then into a single WASM binary file.

Hope this helps

kripken commented 5 years ago

Have you considered using something like AssemblyScript? It lets you write code that translates 1 to 1 to wasm, like wast, and I believe it supports separate files etc.

We could restore/rewrite wasm-merge in Binaryen, though, that's come up more than once - there are various use cases it turns out.