From 58a47edda15fe365220f8502ad42a7bd09bf83b7 Mon Sep 17 00:00:00 2001 From: Mikolaj Boc Date: Mon, 26 Jun 2023 12:17:41 +0200 Subject: [PATCH] Use a sanitized JS export name for WASM modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, a target name with a JS special character (like, -, for example), would lead to an invalid export name being generated for WASM modules. Sanitize these by replacing any non-alphanumeric character with underscores, as is done for feature names. Change-Id: I01fbc50bddedd011a9584f673d79d88a3bc09bbb Reviewed-by: Piotr Wierciński Reviewed-by: Morten Johan Sørvig --- src/corelib/Qt6WasmMacros.cmake | 12 ++++++++++-- src/plugins/platforms/wasm/wasm_shell.html | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/corelib/Qt6WasmMacros.cmake b/src/corelib/Qt6WasmMacros.cmake index 188ed28fe4..ffc39d27a8 100644 --- a/src/corelib/Qt6WasmMacros.cmake +++ b/src/corelib/Qt6WasmMacros.cmake @@ -22,6 +22,8 @@ function(_qt_internal_wasm_add_target_helpers target) endif() set(APPNAME ${_target_output_name}) + _qt_internal_wasm_export_name_for_target(_export_name ${target}) + set(APPEXPORTNAME ${_export_name}) get_target_property(target_output_directory ${target} RUNTIME_OUTPUT_DIRECTORY) @@ -106,10 +108,16 @@ function(_qt_internal_add_wasm_extra_exported_methods target) endfunction() function(_qt_internal_set_wasm_export_name target) + _qt_internal_wasm_export_name_for_target(export_name ${target}) + target_link_options("${target}" PRIVATE "SHELL:-s EXPORT_NAME=${export_name}") +endfunction() + +function(_qt_internal_wasm_export_name_for_target out target) get_target_property(export_name "${target}" QT_WASM_EXPORT_NAME) if(export_name) - target_link_options("${target}" PRIVATE "SHELL:-s EXPORT_NAME=${export_name}") + set(${out} "${export_name}" PARENT_SCOPE) else() - target_link_options("${target}" PRIVATE "SHELL:-s EXPORT_NAME=${target}_entry") + string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" target "${target}") + set(${out} "${target}_entry" PARENT_SCOPE) endif() endfunction() diff --git a/src/plugins/platforms/wasm/wasm_shell.html b/src/plugins/platforms/wasm/wasm_shell.html index 2287e3fad2..9e4f0c2df3 100644 --- a/src/plugins/platforms/wasm/wasm_shell.html +++ b/src/plugins/platforms/wasm/wasm_shell.html @@ -57,7 +57,7 @@ exitData.text !== undefined ? ` (${exitData.text})` : ''; showUi(spinner); }, - entryFunction: window.@APPNAME@_entry, + entryFunction: window.@APPEXPORTNAME@, containerElements: [screen], } });