Combining wasms

23 views
Skip to first unread message

craste...@gmail.com

unread,
Feb 13, 2023, 11:12:31 PM2/13/23
to emscripten-discuss
Is there a way for emscripten to include or merge with an existing wasm file?

For example, lets say there is a third party wasm named foo.wasm and I want to make a bar.wasm that exposes foo's interface as well as my own bar api.

I know that you can include bytecode files in the compile commandline.
Is there a way to include a wasm file?

Thomas Lively

unread,
Feb 14, 2023, 12:33:10 AM2/14/23
to emscripte...@googlegroups.com
No, unfortunately there's no way to do that today. The closest thing would be linking in a third party Wasm module in the relocatable .o format, but standalone Wasm modules are not typically in that format. We may introduce a wasm-merge tool at some point in the future given that it is a popular feature request and that there are new emerging toolchains for e.g. Kotlin, Dart, and Java that are not based on LLVM and cannot produce .o files. I don't know of anyone currently working on that, though.

You may be interested in wasm-compose from the Bytecode Alliance's wasm-tools project, although that's focused on composing modules using the Wasm Component Model, so I don't know if it can handle regular Wasm modules: https://github.com/bytecodealliance/wasm-tools.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/ff7904e1-c634-4521-8701-2e21c00d69f3n%40googlegroups.com.

craste...@gmail.com

unread,
Feb 14, 2023, 12:53:13 AM2/14/23
to emscripten-discuss
That is unfortunate.  I suppose I could do something like this: (since I build the thirdparty wasm with their included build script)

- setup my bar build script to just output bar.o instead of bar.wasm.
- change/edit their "foo" build script to include my bar.o along with all its other stuff.
- perhaps even change the script to output foobar.wasm instead of foo.wasm.  (just to make it clear that this is a different animal from the original)

Of course, that means I have the headache of re-implementing those edits anytime I update to a newer version of foo.  But I could live with that.

Sam Clegg

unread,
Feb 14, 2023, 2:23:30 AM2/14/23
to emscripte...@googlegroups.com
On Mon, Feb 13, 2023 at 9:53 PM craste...@gmail.com <craste...@gmail.com> wrote:
That is unfortunate.  I suppose I could do something like this: (since I build the thirdparty wasm with their included build script)

- setup my bar build script to just output bar.o instead of bar.wasm.
- change/edit their "foo" build script to include my bar.o along with all its other stuff.

Yes, normally the easiest way is to build a static library and then link against it. 

So in this case you would build `libbar.a` and then add `-lbar` to your build for `foo`.   Most software that is designed to be used as a library is already setup with build rules to produce a library archive (.a. file).

- perhaps even change the script to output foobar.wasm instead of foo.wasm.  (just to make it clear that this is a different animal from the original)

Of course, that means I have the headache of re-implementing those edits anytime I update to a newer version of foo.  But I could live with that.



On Monday, February 13, 2023 at 10:33:10 PM UTC-7 tli...@google.com wrote:
No, unfortunately there's no way to do that today. The closest thing would be linking in a third party Wasm module in the relocatable .o format, but standalone Wasm modules are not typically in that format. We may introduce a wasm-merge tool at some point in the future given that it is a popular feature request and that there are new emerging toolchains for e.g. Kotlin, Dart, and Java that are not based on LLVM and cannot produce .o files. I don't know of anyone currently working on that, though.

You may be interested in wasm-compose from the Bytecode Alliance's wasm-tools project, although that's focused on composing modules using the Wasm Component Model, so I don't know if it can handle regular Wasm modules: https://github.com/bytecodealliance/wasm-tools.

On Mon, Feb 13, 2023 at 10:12 PM craste...@gmail.com <craste...@gmail.com> wrote:
Is there a way for emscripten to include or merge with an existing wasm file?

For example, lets say there is a third party wasm named foo.wasm and I want to make a bar.wasm that exposes foo's interface as well as my own bar api.

I know that you can include bytecode files in the compile commandline.
Is there a way to include a wasm file?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/ff7904e1-c634-4521-8701-2e21c00d69f3n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages