MODULARIZE & EXPORT_NAME build options oddities · Issue #7950 · emscripten-core/emscripten (original) (raw)

Consider

$ emcc tests\hello_world.c -s MODULARIZE=1 -o a.html

This produces a web page that does not run, but gives no build errors either.

There are two things that are odd about the generated build.

First, I think the history of -s MODULARIZE=1 was intended to be primarily used when building to JavaScript with -o a.js, so the intent is that one would manually invoke the generate Module() function (defined with -s EXPORT_NAME= option) to start the app. But when one is targeting HTML with any of the default html shell files that Emscripten provides (no --shell-file directive passed, or --shell-file src/shell_minimal.html) it seems that we should be automatically be generating a Module(); invocation there to start the page.

Second, why is the default value of the -s EXPORT_NAME= option called Module? That seems wrong. Module is supposed to be an object that contains import/export interactions with the generated page. In MODULARIZE mode EXPORT_NAME specifies the name of the function that one should call to launch the page. Calling this function also Module seems like we are calling two different things by the same name, and by default, one would need to call Module(Module); to run the page. Hence when building

$ emcc tests\hello_world.c -s MODULARIZE=1 -o a.html

it is not possible to launch the generated build even from web console.

Perhaps default value of EXPORT_NAME should be changed to something like 'EmscriptenCode', so that the default launch sequence would look like EmscriptenCode(Module);, and our default shells would add a {{{ EXPORT_NAME }}}(Module); directive to them?