wasm: allow apps to override EXPORT_RUNTIME_METHODS

Developers can add to Emscripten's EXPORT_RUNTIME_METHODS
by defining their own using:
QT_WASM_EXTRA_EXPORTED_METHODS

Which will add on to Qt's default exported runtime methods
of UTF16ToString,stringToUTF16

for cmake:
set_target_properties(<target> PROPERTIES QT_WASM_EXTRA_EXPORTED_METHODS "ccall,cwrap")
or
set(QT_WASM_EXTRA_EXPORTED_METHODS "ccall,cwrap")

for qmake:
QT_WASM_EXTRA_EXPORTED_METHODS = ccall,cwrap

Done-with: Mikolaj Boc
Fixes: QTBUG-104882
Pick-to: 6.4
Change-Id: I9678bdb7b077aaa8527057212ea4e161c0be0b60
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Lorn Potter 2022-07-14 10:07:00 +10:00
parent 97f6878afd
commit 1f9c1f032c
6 changed files with 35 additions and 2 deletions

View File

@ -40,8 +40,10 @@ function(qt_internal_add_executable name)
endif()
if(WASM)
qt_internal_wasm_add_finalizers("${name}")
_qt_internal_wasm_add_target_helpers("${name}")
endif()
if (arg_VERSION)
if(arg_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")
# nothing to do

View File

@ -7,7 +7,6 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
target_link_options("${wasmTarget}" INTERFACE
"SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1"
"SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16"
"SHELL:-s MAX_WEBGL_VERSION=2"
"SHELL:-s FETCH=1"
"SHELL:-s WASM_BIGINT=1")
@ -80,3 +79,9 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
target_compile_definitions("${wasmTarget}" INTERFACE QT_HAVE_EMSCRIPTEN_ASYNCIFY)
endif()
endfunction()
function(qt_internal_wasm_add_finalizers target)
qt_add_list_file_finalizer(_qt_internal_add_wasm_extra_exported_methods ${target})
endfunction()

View File

@ -7,6 +7,14 @@ isEmpty(DESTDIR): DESTDIR = $$OUT_PWD
exists($$QMAKE_QT_CONFIG) {
## this may be subject to change
## qmake puts a space if done otherwise
!isEmpty(QT_WASM_EXTRA_EXPORTED_METHODS): {
EXPORTED_METHODS = UTF16ToString,stringToUTF16,$$QT_WASM_EXTRA_EXPORTED_METHODS
} else {
EXPORTED_METHODS = UTF16ToString,stringToUTF16
}
EMCC_LFLAGS += -s EXPORTED_RUNTIME_METHODS=$$EXPORTED_METHODS
qtConfig(thread) {
EMCC_LFLAGS += -pthread

View File

@ -32,7 +32,6 @@ EMCC_COMMON_LFLAGS += \
-s WASM=1 \
-s MAX_WEBGL_VERSION=2 \
-s ERROR_ON_UNDEFINED_SYMBOLS=1 \
-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16 \
--bind \
-s FETCH=1 \
-s MODULARIZE=1 \

View File

@ -650,6 +650,7 @@ function(_qt_internal_finalize_executable target)
if(EMSCRIPTEN)
_qt_internal_wasm_add_target_helpers("${target}")
_qt_internal_add_wasm_extra_exported_methods("${target}")
endif()
if(IOS)
_qt_internal_finalize_ios_app("${target}")

View File

@ -60,3 +60,21 @@ function(_qt_internal_wasm_add_target_helpers target)
endif()
endfunction()
function(_qt_internal_add_wasm_extra_exported_methods target)
get_target_property(wasm_extra_exported_methods "${target}" QT_WASM_EXTRA_EXPORTED_METHODS)
if(NOT wasm_extra_exported_methods)
set(wasm_extra_exported_methods ${QT_WASM_EXTRA_EXPORTED_METHODS})
endif()
if(wasm_extra_exported_methods)
target_link_options("${target}" PRIVATE
"SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,${wasm_extra_exported_methods}"
)
else()
# an errant dangling comma will break this
target_link_options("${target}" PRIVATE
"SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16"
)
endif()
endfunction()