summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Wierciński <[email protected]>2024-11-27 15:36:19 +0100
committerPiotr Wierciński <[email protected]>2025-01-13 18:23:10 +0000
commit010ed1788402bf98d9b98500fdb1f61c333cebe5 (patch)
tree6a1ee5af6192c677330e00cd993f9621008a0b0a
parent8472004a895fa98e68f6f3ff134720904a00c150 (diff)
wasm: Add helper for pluging preloads
Dynamic linking on WebAssembly involves preloading .so libraries during startup of application. Normally, those plugin preload lists are generating manually by user, which can be tedious. Add a bash script which demonstrates how to call python programs to generate preload lists. Pick-to: 6.9 Change-Id: I0a9869ad0d26606f8b33af2c38248cec3088dd0d Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r--cmake/QtBaseGlobalTargets.cmake16
-rw-r--r--src/corelib/Qt6WasmMacros.cmake9
-rw-r--r--util/wasm/preload/generate_default_preloads.sh.in19
-rwxr-xr-xutil/wasm/preload/preload_qml_imports.py15
-rwxr-xr-xutil/wasm/preload/preload_qt_plugins.py11
5 files changed, 56 insertions, 14 deletions
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index 1e028c4a72c..2f0a30645e5 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -386,9 +386,23 @@ if(APPLE)
elseif(WASM)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/util/wasm/wasmtestrunner/qt-wasmtestrunner.py"
"${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt-wasmtestrunner.py" @ONLY)
-
qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/qt-wasmtestrunner.py"
DESTINATION "${INSTALL_LIBEXECDIR}")
+
+ if(QT_FEATURE_shared)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/util/wasm/preload/preload_qml_imports.py"
+ "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/preload_qml_imports.py" COPYONLY)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/util/wasm/preload/preload_qt_plugins.py"
+ "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/preload_qt_plugins.py" COPYONLY)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/util/wasm/preload/generate_default_preloads.sh.in"
+ "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/generate_default_preloads.sh.in" COPYONLY)
+ qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/preload_qml_imports.py"
+ DESTINATION "${INSTALL_LIBEXECDIR}")
+ qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/preload_qt_plugins.py"
+ DESTINATION "${INSTALL_LIBEXECDIR}")
+ qt_install(PROGRAMS "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/generate_default_preloads.sh.in"
+ DESTINATION "${INSTALL_LIBEXECDIR}")
+ endif()
endif()
# Install CI support files to libexec.
diff --git a/src/corelib/Qt6WasmMacros.cmake b/src/corelib/Qt6WasmMacros.cmake
index eae356679bd..e185ef67490 100644
--- a/src/corelib/Qt6WasmMacros.cmake
+++ b/src/corelib/Qt6WasmMacros.cmake
@@ -91,6 +91,15 @@ function(_qt_internal_wasm_add_target_helpers target)
${_target_directory}/qtloader.js COPYONLY)
configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg"
${_target_directory}/qtlogo.svg COPYONLY)
+ if(QT_FEATURE_shared)
+ set(TARGET_DIR "${_target_directory}")
+ set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+ set(QT_HOST_DIR "${QT_HOST_PATH}")
+ set(QT_WASM_DIR "${WASM_BUILD_DIR}")
+ set(QT_INSTALL_DIR "${QT6_INSTALL_PREFIX}")
+ configure_file("${WASM_BUILD_DIR}/libexec/generate_default_preloads.sh.in"
+ "${_target_directory}/generate_default_preloads_for_${target}.sh" @ONLY)
+ endif()
endif()
endif()
endif()
diff --git a/util/wasm/preload/generate_default_preloads.sh.in b/util/wasm/preload/generate_default_preloads.sh.in
new file mode 100644
index 00000000000..b38d308fa45
--- /dev/null
+++ b/util/wasm/preload/generate_default_preloads.sh.in
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+TARGET_DIR="@TARGET_DIR@"
+SOURCE_DIR="@SOURCE_DIR@"
+QT_HOST_DIR="@QT_HOST_DIR@"
+QT_WASM_DIR="@QT_WASM_DIR@"
+QT_INSTALL_DIR="@QT_INSTALL_DIR@"
+
+python3 \
+ "$QT_WASM_DIR/libexec/preload_qt_plugins.py" \
+ "$QT_INSTALL_DIR" \
+ "$TARGET_DIR"
+
+python3 \
+ "$QT_WASM_DIR/libexec/preload_qml_imports.py" \
+ "$SOURCE_DIR" \
+ "$QT_HOST_DIR" \
+ "$QT_INSTALL_DIR" \
+ "$TARGET_DIR"
diff --git a/util/wasm/preload/preload_qml_imports.py b/util/wasm/preload/preload_qml_imports.py
index 9af4fa2a282..b78ef5ee744 100755
--- a/util/wasm/preload/preload_qml_imports.py
+++ b/util/wasm/preload/preload_qml_imports.py
@@ -19,10 +19,6 @@ qt_qml_path = "$QTDIR/qml"
qt_deploy_qml_path = "/qt/qml"
-def eprint(*args, **kwargs):
- print(*args, file=sys.stderr, **kwargs)
-
-
def preload_file(source, destination):
preload_files.append({"source": source, "destination": destination})
@@ -55,24 +51,23 @@ def extract_preload_files_from_imports(imports):
)
preload_file(qmldir_source_path, qmldir_destination_path)
except Exception as e:
- eprint(e)
continue
return libraries
if __name__ == "__main__":
- if len(sys.argv) != 4:
- print("Usage: python preload_qml_imports.py <qml-source-path> <qt-host-path> <qt-wasm-path>")
+ if len(sys.argv) != 5:
+ print("Usage: python preload_qml_imports.py <qml-source-path> <qt-host-path> <qt-wasm-path> <output-dir>")
sys.exit(1)
qml_source_path = sys.argv[1]
qt_host_path = sys.argv[2]
qt_wasm_path = sys.argv[3]
+ output_dir = sys.argv[4]
qml_import_path = os.path.join(qt_wasm_path, "qml")
qmlimportsscanner_path = os.path.join(qt_host_path, "libexec/qmlimportscanner")
- eprint("runing qmlimportsscanner")
command = [qmlimportsscanner_path, "-rootPath", qml_source_path, "-importPath", qml_import_path]
result = subprocess.run(command, stdout=subprocess.PIPE)
imports = json.loads(result.stdout)
@@ -98,4 +93,6 @@ if __name__ == "__main__":
destination = os.path.join("/", library)
preload_file(source, destination)
- print(json.dumps(preload_files, indent=2))
+ with open(f"{output_dir}/qt_qml_imports.json", "w") as f:
+ f.write(json.dumps(preload_files, indent=2))
+
diff --git a/util/wasm/preload/preload_qt_plugins.py b/util/wasm/preload/preload_qt_plugins.py
index 362d1297320..4b9b3683a70 100755
--- a/util/wasm/preload/preload_qt_plugins.py
+++ b/util/wasm/preload/preload_qt_plugins.py
@@ -27,11 +27,12 @@ def find_so_files(directory):
if __name__ == "__main__":
- if len(sys.argv) != 2:
- print("Usage: python make_qt_symlinks.py <qt-wasm-path>")
+ if len(sys.argv) != 3:
+ print("Usage: python preload_qt_plugins.py <qt-wasm-path> <output-dir>")
sys.exit(1)
qt_wasm_path = sys.argv[1]
+ output_dir = sys.argv[2]
# preload all plugins
plugins = find_so_files(os.path.join(qt_wasm_path, "plugins"))
@@ -47,8 +48,10 @@ if __name__ == "__main__":
# and QML imports in /qt/plugins and /qt/qml. The qt.conf file is
# written to the current directory.
qtconf = "[Paths]\nPrefix = /qt\n"
- with open("qt.conf", "w") as f:
+ with open(f"{output_dir}/qt.conf", "w") as f:
f.write(qtconf)
preload.append({"source": "qt.conf", "destination": "/qt.conf"})
- print(json.dumps(preload, indent=2))
+ with open(f"{output_dir}/qt_plugins.json", "w") as f:
+ f.write(json.dumps(preload, indent=2))
+