summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@gmail.com>2022-02-14 09:28:51 +1000
committerLorn Potter <lorn.potter@gmail.com>2022-02-23 12:04:37 +1000
commitaf36dc7d763abcd4a5de28957f55cecd25cf8459 (patch)
tree0046162142d45fb5bc6fc73fe23a3060ef6658be
parent196e10bce4c0a9d7a746f5fdde47168a06823472 (diff)
wasm: move user configurable settings
Both INITIAL_MEMORY and PTHREAD_POOL_SIZE are settings users can change, they are not interface settings. Fixes: QTBUG-100693 Pick-to: 6.3 6.2 Change-Id: Ie1547c7f52c9fe109a313260616705728024b6b8 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: David Skoland <david.skoland@qt.io>
-rw-r--r--cmake/QtWasmHelpers.cmake25
-rw-r--r--doc/global/macros.qdocconf2
-rw-r--r--src/corelib/Qt6WasmMacros.cmake35
-rw-r--r--src/corelib/doc/src/cmake/cmake-properties.qdoc46
4 files changed, 83 insertions, 25 deletions
diff --git a/cmake/QtWasmHelpers.cmake b/cmake/QtWasmHelpers.cmake
index a494725d7d..47af621861 100644
--- a/cmake/QtWasmHelpers.cmake
+++ b/cmake/QtWasmHelpers.cmake
@@ -22,23 +22,6 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
target_compile_options("${wasmTarget}" INTERFACE -O2 -msimd128 -msse -msse2)
endif()
- # Hardcode wasm memory size. Emscripten does not currently support memory growth
- # (ALLOW_MEMORY_GROWTH) in pthreads mode, and requires specifying the memory size
- # at build time. Further, browsers limit the maximum initial memory size to 1GB.
- # QT_WASM_INITIAL_MEMORY must be a multiple of 64KB (i.e. 65536)
- if(NOT DEFINED QT_WASM_INITIAL_MEMORY)
- if(QT_FEATURE_thread)
- set(QT_WASM_INITIAL_MEMORY "1GB")
- else()
- set(QT_WASM_INITIAL_MEMORY "20MB") # emscripten default is 16MB, we need slightly more sometimes
- endif()
- endif()
-
- if(DEFINED QT_WASM_INITIAL_MEMORY)
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
- message("Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY}")
- endif()
-
if (QT_FEATURE_opengles3)
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FULL_ES3=1")
@@ -58,14 +41,6 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
if (QT_FEATURE_thread)
target_compile_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
target_link_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
-
- set(POOL_SIZE 4)
- if(DEFINED QT_WASM_PTHREAD_POOL_SIZE)
- set(POOL_SIZE ${QT_WASM_PTHREAD_POOL_SIZE})
- endif()
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s PTHREAD_POOL_SIZE=${POOL_SIZE}")
- message("Setting PTHREAD_POOL_SIZE to ${POOL_SIZE}")
-
else()
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH=1")
endif()
diff --git a/doc/global/macros.qdocconf b/doc/global/macros.qdocconf
index 37c5a3ea1c..31cecc1b78 100644
--- a/doc/global/macros.qdocconf
+++ b/doc/global/macros.qdocconf
@@ -83,3 +83,5 @@ macro.cmakepropertyandroidonly = "\\note This property is used only if targeting
macro.cmakevariableandroidonly = "\\note This variable is used only if targeting the Android platform."
macro.versionlessCMakeCommandsNote = "If \\l{Versionless commands}{versionless commands} are disabled, use \\c{\1} instead. It supports the same set of arguments as this command."
+
+macro.cmakepropertywebassemblyonly = "\\note This property is used only if targeting the WebAssembly platform."
diff --git a/src/corelib/Qt6WasmMacros.cmake b/src/corelib/Qt6WasmMacros.cmake
index 2c915b3903..86044d7e02 100644
--- a/src/corelib/Qt6WasmMacros.cmake
+++ b/src/corelib/Qt6WasmMacros.cmake
@@ -18,5 +18,40 @@ function(_qt_internal_wasm_add_target_helpers target)
configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg"
qtlogo.svg COPYONLY)
+ if(QT_FEATURE_thread)
+ set(POOL_SIZE 4)
+ get_target_property(_tmp_poolSize "${target}" QT_WASM_PTHREAD_POOL_SIZE)
+ if(_tmp_poolSize)
+ set(POOL_SIZE ${_tmp_poolSize})
+ elseif(DEFINED QT_WASM_PTHREAD_POOL_SIZE)
+ set(POOL_SIZE ${QT_WASM_PTHREAD_POOL_SIZE})
+ endif()
+ target_link_options("${target}" PRIVATE "SHELL:-s PTHREAD_POOL_SIZE=${POOL_SIZE}")
+ message(DEBUG "Setting PTHREAD_POOL_SIZE to ${POOL_SIZE} for ${target}")
+ endif()
+
+ # Hardcode wasm memory size. Emscripten does not currently support memory growth
+ # (ALLOW_MEMORY_GROWTH) in pthreads mode, and requires specifying the memory size
+ # at build time. Further, browsers limit the maximum initial memory size to 1GB.
+ # QT_WASM_INITIAL_MEMORY must be a multiple of 64KB (i.e. 65536)
+ get_target_property(_tmp_initialMemory "${target}" QT_WASM_INITIAL_MEMORY)
+ if(_tmp_initialMemory)
+ set(QT_WASM_INITIAL_MEMORY "${_tmp_initialMemory}")
+ elseif(NOT DEFINED QT_WASM_INITIAL_MEMORY)
+ if(QT_FEATURE_thread)
+ set(QT_WASM_INITIAL_MEMORY "1GB")
+ else()
+ # emscripten default is 16MB, we need slightly more sometimes
+ set(QT_WASM_INITIAL_MEMORY "20MB")
+ endif()
+ endif()
+
+ if(DEFINED QT_WASM_INITIAL_MEMORY)
+ target_link_options("${target}"
+ PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
+ message(DEBUG "-- Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY} for ${target}")
+ endif()
+
endif()
endfunction()
+
diff --git a/src/corelib/doc/src/cmake/cmake-properties.qdoc b/src/corelib/doc/src/cmake/cmake-properties.qdoc
index 859b3e79af..347699736d 100644
--- a/src/corelib/doc/src/cmake/cmake-properties.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-properties.qdoc
@@ -384,3 +384,49 @@ the property value overrides the runtime path where the resource file is found.
\sa{The Qt Resource System}
*/
+
+/*!
+\page cmake-target-property-QT_WASM_PTHREAD_POOL_SIZE.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+
+\title QT_WASM_PTHREAD_POOL_SIZE
+\target cmake-target-property-QT_WASM_PTHREAD_POOL_SIZE
+
+\summary {Internal WebAssembly thread pool size.}
+
+\cmakepropertysince 6.2.4
+\preliminarycmakeproperty
+\cmakepropertywebassemblyonly
+
+Specifies the number of web workers (threads) to create at application startup.
+Qt allocates a pool size of 4 by default. This means the app can use
+4 additional threads besides the main thread, without the additional overhead
+of creating a new web worker, which may deadlock if the main thread created it
+and join()s the thread without returning control to the event loop first.
+Translates into the Emscripten compiler setting of PTHREAD_POOL_SIZE.
+
+For more information, see \l{https://emscripten.org/docs/porting/pthreads.html}{Pthreads support}.
+*/
+
+/*!
+\page cmake-target-property-QT_WASM_INITIAL_MEMORY.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+
+\title QT_WASM_INITIAL_MEMORY
+\target cmake-target-property-QT_WASM_INITIAL_MEMORY
+
+\summary {Internal WebAssembly initial memory.}
+
+\cmakepropertysince 6.2.4
+\preliminarycmakeproperty
+\cmakepropertywebassemblyonly
+
+Specifies the initial amount of memory to use, in bytes. Using more will cause the
+browser to copy the old heap into a new one. Translates into the
+Emscripten compiler setting of INITIAL_MEMORY.
+QT_WASM_INITIAL_MEMORY must be a multiple of 65536 bytes.
+
+For more information, see \l{https://github.com/emscripten-core/emscripten/blob/main/src/settings.js}{Emscripten compiler settings}.
+*/