summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-02-16 03:13:05 +0300
committerSaikari <[email protected]>2026-02-23 01:53:25 +0300
commite619f1ec47159ba18f8cb728706be4c562808888 (patch)
tree5c2a5197adb97ba4ed842e4e2aa7006e9c95a811
parent821545f6a78188e733b0abe84cdfcb6d07c9e082 (diff)
Try repair QT behavior
-rw-r--r--xmake/rules/qt/load.lua12
-rw-r--r--xmake/rules/qt/xmake.lua57
2 files changed, 63 insertions, 6 deletions
diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua
index 1ce0f4fb1..f24e319b3 100644
--- a/xmake/rules/qt/load.lua
+++ b/xmake/rules/qt/load.lua
@@ -500,13 +500,17 @@ function main(target, opt)
target:add("shflags", "-s FETCH=1", "-s ERROR_ON_UNDEFINED_SYMBOLS=1", "-s ALLOW_MEMORY_GROWTH=1", "--bind")
if qt_sdkver:ge("6.0") then
-- @see https://github.com/xmake-io/xmake/issues/4137
- target:add("ldflags", "-s MAX_WEBGL_VERSION=2", "-s WASM_BIGINT=1", "-s DISABLE_EXCEPTION_CATCHING=1")
+ target:add("ldflags", "-s MAX_WEBGL_VERSION=2", "-s WASM_BIGINT=1", "-s ASSERTIONS=0")
target:add("ldflags", "-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js")
- target:add("ldflags", "-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets")
+ -- FS is required for qtloader.js even if we don't use preload files
+ target:add("ldflags", "-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets,FS,callMain,cwrap,ccall,setValue,getValue,UTF8ToString,stringToUTF8")
+ -- @see https://github.com/emscripten-core/emscripten/issues/21844 Export main and emscripten_thread_crashed for qtloader.js
+ target:add("ldflags", "-s EXPORTED_FUNCTIONS=_main", {force = true})
target:add("ldflags", "-s MODULARIZE=1", "-s EXPORT_NAME=createQtAppInstance")
- target:add("shflags", "-s MAX_WEBGL_VERSION=2", "-s WASM_BIGINT=1", "-s DISABLE_EXCEPTION_CATCHING=1")
+ target:add("shflags", "-s MAX_WEBGL_VERSION=2", "-s WASM_BIGINT=1", "-s ASSERTIONS=0")
target:add("shflags", "-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js")
- target:add("shflags", "-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets")
+ target:add("shflags", "-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets,FS,callMain,cwrap,ccall,setValue,getValue,UTF8ToString,stringToUTF8")
+ target:add("shflags", "-s EXPORTED_FUNCTIONS=_main", {force = true})
target:add("shflags", "-s MODULARIZE=1", "-s EXPORT_NAME=createQtAppInstance")
target:set("extension", ".js")
else
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index db13aa913..6aff00ff1 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -30,6 +30,44 @@ rule("qt._wasm_app")
if os.isfile(path.join(pluginsdir, "platforms/wasm_shell.html")) then
os.vcp(path.join(pluginsdir, "platforms/wasm_shell.html"), htmlfile)
io.gsub(htmlfile, "@APPNAME@", target:name())
+ import("core.base.semver")
+ cprint("qt.sdkver: %s", qt.sdkver)
+ if qt.sdkver and semver.new(qt.sdkver):ge("6.0") then
+ local data1, count1 = io.gsub(htmlfile, "@APPEXPORTNAME@", "createQtAppInstance")
+ cprint("replaced APPEXPORTNAME: %s", count1)
+ local data2, count2 = io.gsub(htmlfile, "@PRELOAD@", "")
+ cprint("replaced PRELOAD: %s", count2)
+ local preload = ""
+ -- @see https://github.com/xmake-io/xmake/issues/6182
+ local preloadfiles = target:values("wasm.preloadfiles")
+ if preloadfiles then
+ local filelist = {}
+ for _, preloadfile in ipairs(preloadfiles) do
+ table.insert(filelist, string.format("'%s'", path.filename(preloadfile)))
+ end
+ if #filelist > 0 then
+ preload = string.format("preload: [%s],", table.concat(filelist, ", "))
+ end
+ end
+ -- Patch old containerElements (pre-Qt 6.5)
+ io.gsub(htmlfile, "containerElements: %[screen%],", function (w)
+ return w .. " " .. preload
+ end)
+ -- Patch new qtContainerElements (Qt 6.5+)
+ io.gsub(htmlfile, "qtContainerElements: %[screen%],", function (w)
+ return w .. " " .. preload
+ end)
+ io.gsub(htmlfile, "@PRELOAD@", "")
+ -- Fix qt-app.js errors
+ local jsfile = path.join(targetdir, target:basename() .. ".js")
+ if os.isfile(jsfile) then
+ -- Remove "use strict"; to avoid issues with `this` being undefined in strict mode
+ io.gsub(jsfile, "\"use strict\";", "")
+ io.gsub(jsfile, "'use strict';", "")
+ -- Patch visualViewport access issue if present (undefined this context)
+ io.gsub(jsfile, "this%.visualViewport", "(typeof window !== 'undefined' ? window.visualViewport : null)")
+ end
+ end
os.vcp(path.join(pluginsdir, "platforms/qtloader.js"), targetdir)
os.vcp(path.join(pluginsdir, "platforms/qtlogo.svg"), targetdir)
end
@@ -104,7 +142,14 @@ rule("qt.widgetapp")
if qt_sdkver and qt_sdkver:lt("5.0") then
frameworks = {"QtGui", "QtCore"} -- qt4.x has not QtWidgets, it is in QtGui
end
- import("load")(target, {gui = true, frameworks = frameworks})
+
+ local plugins = {}
+ if target:is_plat("wasm") then
+ local static_frameworks, static_plugins = import("config_static")(target)
+ table.join2(frameworks, static_frameworks)
+ plugins = static_plugins
+ end
+ import("load")(target, {gui = true, frameworks = frameworks, plugins = plugins})
end)
-- deploy application
@@ -162,7 +207,14 @@ rule("qt.quickapp")
end)
on_config(function (target)
- import("load")(target, {gui = true, frameworks = {"QtGui", "QtQuick", "QtQml", "QtCore", "QtNetwork"}})
+ local frameworks = {"QtGui", "QtQuick", "QtQml", "QtCore", "QtNetwork"}
+ local plugins = {}
+ if target:is_plat("wasm") then
+ local static_frameworks, static_plugins = import("config_static")(target)
+ table.join2(frameworks, static_frameworks)
+ plugins = static_plugins
+ end
+ import("load")(target, {gui = true, frameworks = frameworks, plugins = plugins})
end)
-- deploy application
@@ -184,6 +236,7 @@ rule("qt.quickapp_static")
-- we must set kind before target.on_load(), may we will use target in on_load()
on_load(function (target)
+ print("qt.quickapp_static on_load")
target:set("kind", target:is_plat("android") and "shared" or "binary")
end)