A C++ loader for Webpack
- You will need a version of both Clang and the Libclang with a decent C++17 support to install the loader.
- At runtime, the
em++toolchain must be located inside your
PATHfor this loader to work properly.
If you've installed emscripten for the first time, the first compilation will be VERY slow. Subsequent compilations will be much faster.
How does it work?
- First we parse the source file using the LibClang. We extract all the exported symbols from the main file (so no static function, for example).
- In order to add support for the STL data types out-of-the box, we also wrap all the function (and class function) pointers into the emmagic wrappers, which automatically deal with this for us.
The main limitation is the implementation; most of the following issues could be solved by improving the loader:
Not all STL containers are supported.
Possible fix: They just have to be implemented in emmagic.
Currently only works on Windows because I'm lazy.
Possible fix: I need to be less lazy. Also, the build script shouldn't use bashisms.
The compilation output needs to be asm.js rather than WebAssembly.
A separate compilation is done for each file to compile. It's quite inefficient, because it means that if two files depend on the same common code, this code will be duplicated inside each asm.js module, and will be stored twice in the resulting bundle.
Possible fix: Fixing this would require to process all the dependencies from all the files at once, and then to process all the C++ files all at once (effectively linking them together).
The code has to be compiled with the C++17 standard.