Skip to content

wasm-merge - why it has been deleted #2174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
geloizi opened this issue Jun 17, 2019 · 6 comments
Closed

wasm-merge - why it has been deleted #2174

geloizi opened this issue Jun 17, 2019 · 6 comments

Comments

@geloizi
Copy link

geloizi commented Jun 17, 2019

Curios why it was decided to remove wasm-merge from the project? I s there any alternative "recommended way" of merging wasm modules?

@tlively
Copy link
Member

tlively commented Jun 17, 2019

We deleted it because we weren't using it and weren't aware of any other uses of it. We now have support for WebAssembly object files in LLVM's lld linker, which provides a much more sophisticated way to merge wasm modules, albeit only those that are valid object files. The use case that is no longer supported is merging separate fully-linked modules together, but it seems that generally it would be better not to do that.

@Heath123
Copy link

Not all compilers use LLVM or object files though (e.g. AssemblyScript)

@tlively
Copy link
Member

tlively commented Jun 15, 2022

Another issue is that it's not really been possible to merge modules without support for multiple memories. But work is underway now on multi-memory, so it might be more feasible to have a useful wasm-merge in the near future. cc @ashleynh

@Heath123
Copy link

Heath123 commented Sep 15, 2022

This could still be useful for modules that don't use linear memory, or ones that have been specifically compiled to only use a certain segment of memory that won't overlap with anything else

@Heath123
Copy link

If I need to do this, what should I do? Use an older version of Binaryen?

@kripken
Copy link
Member

kripken commented Sep 16, 2022

@Heath123 At the moment yes, an older version is the best option.

I do think we should restore wasm-merge as various use cases have been accumulating, including yours. Hopefully someone will have time for this soon.

kripken added a commit that referenced this issue May 16, 2023
We used to have a wasm-merge tool but removed it for a lack of use cases. Recently
use cases have been showing up in the wasm GC space and elsewhere, as people are
using more diverse toolchains together, for example a project might build some C++
code alongside some wasm GC code. Merging those wasm files together can allow
for nice optimizations like inlining and better DCE etc., so it makes sense to have a
tool for merging.

Background:
* Removal: #1969
* Requests:
  * wasm-merge - why it has been deleted #2174
  * Compiling and linking wat files #2276
  * wasm-link? #2767

This PR is a compete rewrite of wasm-merge, not a restoration of the original
codebase. The original code was quite messy (my fault), and also, since then
we've added multi-memory and multi-table which makes things a lot simpler.

The linking semantics are as described in the "wasm-link" issue #2767 : all we do
is merge normal wasm files together and connect imports and export. That is, we
have a graph of modules and their names, and each import to a module name can
be resolved to that module. Basically, like a JS bundler would do for JS, or, in other
words, we do the same operations as JS code would do to glue wasm modules
together at runtime, but at compile time. See the README update in this PR for a
concrete example.

There are no plans to do more than that simple bundling, so this should not
really overlap with wasm-ld's use cases.

This should be fairly fast as it works in linear time on the total input code. However,
it won't be as fast as wasm-ld, of course, as it does build Binaryen IR for each
module. An advantage to working on Binaryen IR is that we can easily do some
global DCE after merging, and further optimizations are possible later.
radekdoulik pushed a commit to dotnet/binaryen that referenced this issue Jul 12, 2024
We used to have a wasm-merge tool but removed it for a lack of use cases. Recently
use cases have been showing up in the wasm GC space and elsewhere, as people are
using more diverse toolchains together, for example a project might build some C++
code alongside some wasm GC code. Merging those wasm files together can allow
for nice optimizations like inlining and better DCE etc., so it makes sense to have a
tool for merging.

Background:
* Removal: WebAssembly#1969
* Requests:
  * wasm-merge - why it has been deleted WebAssembly#2174
  * Compiling and linking wat files WebAssembly#2276
  * wasm-link? WebAssembly#2767

This PR is a compete rewrite of wasm-merge, not a restoration of the original
codebase. The original code was quite messy (my fault), and also, since then
we've added multi-memory and multi-table which makes things a lot simpler.

The linking semantics are as described in the "wasm-link" issue WebAssembly#2767 : all we do
is merge normal wasm files together and connect imports and export. That is, we
have a graph of modules and their names, and each import to a module name can
be resolved to that module. Basically, like a JS bundler would do for JS, or, in other
words, we do the same operations as JS code would do to glue wasm modules
together at runtime, but at compile time. See the README update in this PR for a
concrete example.

There are no plans to do more than that simple bundling, so this should not
really overlap with wasm-ld's use cases.

This should be fairly fast as it works in linear time on the total input code. However,
it won't be as fast as wasm-ld, of course, as it does build Binaryen IR for each
module. An advantage to working on Binaryen IR is that we can easily do some
global DCE after merging, and further optimizations are possible later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants