wasm: add "qtdir" qtloader config property

This points to the location where qtloader should find
the Qt installation when loading Qt shared libraries
and plugins.

The path is relative to the path of the html file which
contains the application, and is set to "qt" by default.

Deployment of the Qt installation to the web server is
left to the app developer, since this depends on the
exact use case. One possible way to deploy is to create
a "qt" symlink to the Qt installation, for instance:

  html/myapp/myapp.html
  html/myapp/myapp.wasm
  html/myapp/qt -> /path/to/qt

Task-number: QTBUG-63925
Change-Id: I76b129dffc75c06ff6bc67d8c20ce12557b32f31
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit d659c93068120474fb433ad55c619c5d52ab7d8d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Morten Sørvig 2023-06-08 13:53:48 +02:00 committed by Qt Cherry-pick Bot
parent cb3416696f
commit cd16e289f6

View File

@ -24,6 +24,11 @@
* - module: Promise<WebAssembly.Module>
* The module to create the instance from (optional). Specifying the module allows optimizing
* use cases where several instances are created from a single WebAssembly source.
* - qtdir: string
* Path to Qt installation. This path will be used for loading Qt shared libraries and plugins.
* The path is set to 'qt' by default, and is relative to the path of the web page's html file.
* This property is not in use when static linking is used, since this build mode includes all
* libraries and plugins in the wasm file.
*
* @return Promise<{
* instance: EmscriptenModule,
@ -56,6 +61,8 @@ async function qtLoad(config)
if (typeof config.qt.entryFunction !== 'function')
config.qt.entryFunction = window.createQtAppInstance;
config.qt.qtdir ??= 'qt';
config.qtContainerElements = config.qt.containerElements;
delete config.qt.containerElements;
config.qtFontDpi = config.qt.fontDpi;
@ -93,6 +100,15 @@ async function qtLoad(config)
config.onRuntimeInitialized = () => config.qt.onLoaded?.();
const originalLocateFile = config.locateFile;
config.locateFile = filename =>
{
const originalLocatedFilename = originalLocateFile ? originalLocateFile(filename) : filename;
if (originalLocatedFilename.startsWith('libQt6'))
return `${config.qt.qtdir}/lib/${originalLocatedFilename}`;
return originalLocatedFilename;
}
// This is needed for errors which occur right after resolving the instance promise but
// before exiting the function (i.e. on call to main before stack unwinding).
let loadTimeException = undefined;