From 7ee4468a18f18dd2269fc422220fea4dc77017c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Fri, 21 May 2021 11:14:34 +0200 Subject: wasm: enable MODULARIZE option and set EXPORT_NAME MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmake/QtWasmHelpers.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cmake/QtWasmHelpers.cmake') 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 -- cgit v1.2.3