From 6e6451ce96f47e0ef5e8ecf1750f394ff3fb48e4 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 12 Aug 2024 13:04:48 +0200 Subject: [PATCH] Emscripten: Move the Qt event loop off the JS main thread ...so that spawning and joining new threads works now and we no longer need a hardcoded -sPTHREAD_POOL_SIZE of pre-spawned threads (see b84ef4d67eaf9f9fd7fd700ca05339cb0cdff742 "Adapt comphelper::ThreadPool to Emscripten's threading needs"; lets keep MAX_CONCURRENCY capped at 4, at least for now, though). This requires "Minimal support for Emscripten -sPROXY_TO_PTHREAD=1" and "Implement QWasmCursor::changeCursor for Emscripten PROXY_TO_PTHREAD case" (see TODOs there). Change-Id: I8cea827bd7786e3c9fd9401b4b2bef9d3ec00d5a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171758 Reviewed-by: Stephan Bergmann Tested-by: Jenkins --- desktop/Executable_soffice_bin.mk | 1 + solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk | 2 +- static/README.wasm.md | 5 ++++- static/emscripten/environment.js | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/desktop/Executable_soffice_bin.mk b/desktop/Executable_soffice_bin.mk index 350e4a84a0b8..be3b303190c2 100644 --- a/desktop/Executable_soffice_bin.mk +++ b/desktop/Executable_soffice_bin.mk @@ -63,6 +63,7 @@ $(call gb_Executable_get_linktarget_target,soffice_bin): \ $(eval $(call gb_Executable_add_ldflags,soffice_bin,\ -s EXPORTED_FUNCTIONS=@$(gb_CustomTarget_workdir)/desktop/soffice_bin-emscripten-exports/exports -Wl$(COMMA)--whole-archive $(call gb_StaticLibrary_get_target,unoembind) -Wl$(COMMA)--no-whole-archive \ + -sPROXY_TO_PTHREAD=1 -sOFFSCREENCANVAS_SUPPORT=1 -sOFFSCREENCANVASES_TO_PTHREAD=\#qtcanvas \ )) ifeq ($(ENABLE_QT6),TRUE) $(eval $(call gb_Executable_add_ldflags,soffice_bin, \ diff --git a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk index 3898ead4448d..6ba9efe66a5c 100644 --- a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk +++ b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk @@ -15,7 +15,7 @@ gb_EMSCRIPTEN_CPPFLAGS := -pthread -s USE_PTHREADS=1 -D_LARGEFILE64_SOURCE -D_LA gb_EMSCRIPTEN_LDFLAGS := $(gb_EMSCRIPTEN_CPPFLAGS) # Initial memory size and worker thread pool -gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=6 +gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB # To keep the link time (and memory) down, prevent all rewriting options from wasm-emscripten-finalize # See emscripten.py, finalize_wasm, modify_wasm = True diff --git a/static/README.wasm.md b/static/README.wasm.md index de595b19b459..84635d09390d 100644 --- a/static/README.wasm.md +++ b/static/README.wasm.md @@ -64,11 +64,14 @@ With "-opensource -confirm-license" you agree to the open source license. git clone https://github.com/allotropia/qt5.git cd qt5 - git checkout v5.15.2+wasm + git checkout 5.15.2+wasm ./init-repository --module-subset=qtbase ./configure -opensource -confirm-license -xplatform wasm-emscripten -feature-thread -prefix QMAKE_CFLAGS+=-sSUPPORT_LONGJMP=wasm QMAKE_CXXFLAGS+=-sSUPPORT_LONGJMP=wasm make -j module-qtbase +Note that `5.15.2+wasm` is a branch that is expected to contain further fixes as they become +necessary. + Do not include `-fwasm-exceptions` in the above `QMAKE_CXXFLAGS`, see "Note: Currently, using the new Wasm exception handling and simulate_infinite_loop == true at the same time diff --git a/static/emscripten/environment.js b/static/emscripten/environment.js index 4e5d1f98c596..74536a665ccc 100644 --- a/static/emscripten/environment.js +++ b/static/emscripten/environment.js @@ -5,3 +5,4 @@ Module.preRun.push(function() { ENV.MAX_CONCURRENCY = '4'; ENV.SAL_LOG = "+WARN" }); +Module.ignoreApplicationExit = true;