Is there a reasonable way to create a webassembly "static library" in a multi-module build for emscripten

Viewed 1999

I am converting a large C++ application for run in a webassembly environment. The build is organized into modules and each module sub-project creates a static or a dynamic library.

From what I have read there is no "ABI" yet standardized for "wasm" modules for dynamic-linking into the browser runtime engine, so at present dynamic linking of pre-compiled and linked libraries is not yet supported.

But in the case of static libraries they are just collections of pre-compiled "intermediate" "object" code which are converted to distribution code in the final "link" phase. I have the compiler set to create ".bc" "object code" from the authored languange.

I have not found any reference to creating a simple archive of the compiler output that can be fed to the final "link" that is supported by the emcc compiler/linker.

So a strategy is I can create zip files (kinda like jar files) with a simple manifest and the build system can unpack them all into a temporary area, and merge the exports files. then "link" the whole mass together into the browser "distributable" Module.

Is there a nascent standard definition for this sort of thing? If so I should support it.

1 Answers

You should be able to use emar just like a the standard ar tool in order to create libraries from the .bc object files.

You can then feed these into em++ (or emcc) at link time and they will work much like native libraries do with native compilers. You can with reference them directly on the command line or with -L/-l arguments.

Related