From a6e727470437eceb8d27cadd6737c7e50577d410 Mon Sep 17 00:00:00 2001 From: Piotr Wiercinski Date: Fri, 23 Feb 2024 17:14:08 +0100 Subject: wasm: make qtloader.js use FS.createPreloadedFile when preloading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/platforms/wasm/qtloader.js | 42 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src') 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; -- cgit v1.2.3