diff options
author | Morten Sørvig <morten.sorvig@qt.io> | 2021-05-21 11:14:34 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-06-22 11:11:20 +0000 |
commit | 7ee4468a18f18dd2269fc422220fea4dc77017c7 (patch) | |
tree | 776251da15851e28841a3c53262e974c898d84cf /cmake/QtWasmHelpers.cmake | |
parent | a97445274ab94e38f457a0d874ec64aa0da60846 (diff) |
wasm: enable MODULARIZE option and set EXPORT_NAME
Make Emscripten generate a global constructor function
("createQtAppInstance()") instead of a global javascript
module object.
This enables more fine-grained control over module
instantiation; previously the module object would be
created when the runtime javascript was evaluated, and
the number of emscripten module/instances was limited
to one per page.
Set EXPORT_NAME to “createQtAppInstance” which avoids
collisions with other non-Qt Emscripten modules on
the same page. A further improvement would be to include
the app name in EXPORT_NAME, but this is not done at
this time.
Update the code in qtloader.js to call the constructor
function instead of working on a global module object.
The qtloader.js API is functional before the wasm and
Emscripten modules have been instantiated; store properties
and forward to the Emscripten module when it's created.
Change-Id: I12c49a5b9a4a932bbc46fcc5e5ecc453fd0fe7f0
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'cmake/QtWasmHelpers.cmake')
-rw-r--r-- | cmake/QtWasmHelpers.cmake | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cmake/QtWasmHelpers.cmake b/cmake/QtWasmHelpers.cmake index bc5e455fcd..ecea701042 100644 --- a/cmake/QtWasmHelpers.cmake +++ b/cmake/QtWasmHelpers.cmake @@ -7,6 +7,16 @@ function (qt_internal_setup_wasm_target_properties wasmTarget) "SHELL:-s USE_WEBGL2=1" "--bind" "SHELL:-s FETCH=1") + + # Enable MODULARIZE and set EXPORT_NAME, which makes it possible to + # create application instances using a global constructor function, + # e.g. let app_instance = await createQtAppInstance(). + # (as opposed to MODULARIZE=0, where Emscripten creates a global app + # instance object at Javascript eval time) + target_link_options("${wasmTarget}" INTERFACE + "SHELL:-s MODULARIZE=1" + "SHELL:-s EXPORT_NAME=createQtAppInstance") + target_compile_options("${wasmTarget}" INTERFACE --bind) # Hardcode wasm memory size. Emscripten does not currently support memory growth |