summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm
diff options
context:
space:
mode:
authorPiotr Wiercinski <piotr.wiercinski@qt.io>2024-02-23 17:14:08 +0100
committerPiotr Wierciński <piotr.wiercinski@qt.io>2024-03-14 14:54:53 +0000
commita6e727470437eceb8d27cadd6737c7e50577d410 (patch)
treea3878532f343bea0c8a2b293a170ef25197cc061 /src/plugins/platforms/wasm
parent0c85b69b860f4222bf0850f2cf5970312b45bfea (diff)
wasm: make qtloader.js use FS.createPreloadedFile when preloading
Currently qtloader.js fetches and copies the files manually. By doing so we are missing some preproccessing by Emscripten preload plugins. Use Emscripten API to preload files, so preload plugin for .so can download, compile and resolve dependencies of imported shared libraries. This makes looking for dependencies in preload_qml_import.py no longer needed. Remove redundant code. Fixes: QTBUG-121817 Change-Id: Idd35f25d5f54123910f813a636407eea23e157cb Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm')
-rw-r--r--src/plugins/platforms/wasm/qtloader.js42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js
index 89944d6dd9..bbc0ac68ab 100644
--- a/src/plugins/platforms/wasm/qtloader.js
+++ b/src/plugins/platforms/wasm/qtloader.js
@@ -120,14 +120,15 @@ async function qtLoad(config)
}
}
}
-
+ const fetchJsonHelper = async path => (await fetch(path)).json();
+ const filesToPreload = (await Promise.all(config.qt.preload.map(fetchJsonHelper))).flat();
const qtPreRun = (instance) => {
// Copy qt.environment to instance.ENV
throwIfEnvUsedButNotExported(instance, config);
for (const [name, value] of Object.entries(config.qt.environment ?? {}))
instance.ENV[name] = value;
- // Copy self.preloadData to MEMFS
+ // Preload files from qt.preload
const makeDirs = (FS, filePath) => {
const parts = filePath.split("/");
let path = "/";
@@ -146,14 +147,25 @@ async function qtLoad(config)
}
}
+ const extractFilenameAndDir = (path) => {
+ const parts = path.split('/');
+ const filename = parts.pop();
+ const dir = parts.join('/');
+ return {
+ filename: filename,
+ dir: dir
+ };
+ }
+ const preloadFile = (file) => {
+ makeDirs(instance.FS, file.destination);
+ const source = file.source.replace('$QTDIR', config.qt.qtdir);
+ const filenameAndDir = extractFilenameAndDir(file.destination);
+ instance.FS.createPreloadedFile(filenameAndDir.dir, filenameAndDir.filename, source, true, true);
+ }
const isFsExported = typeof instance.FS === 'object';
if (!isFsExported)
throw new Error('FS must be exported if preload is used');
-
- for ({destination, data} of self.preloadData) {
- makeDirs(instance.FS, destination);
- instance.FS.writeFile(destination, new Uint8Array(data));
- }
+ filesToPreload.forEach(preloadFile);
}
if (!config.preRun)
@@ -197,22 +209,6 @@ async function qtLoad(config)
}
};
- const fetchPreloadFiles = async () => {
- const fetchJson = async path => (await fetch(path)).json();
- const fetchArrayBuffer = async path => (await fetch(path)).arrayBuffer();
- const loadFiles = async (paths) => {
- const source = paths['source'].replace('$QTDIR', config.qt.qtdir);
- return {
- destination: paths['destination'],
- data: await fetchArrayBuffer(source)
- };
- }
- const fileList = (await Promise.all(config.qt.preload.map(fetchJson))).flat();
- self.preloadData = (await Promise.all(fileList.map(loadFiles))).flat();
- }
-
- await fetchPreloadFiles();
-
// Call app/emscripten module entry function. It may either come from the emscripten
// runtime script or be customized as needed.
let instance;