From 3d2235ad4e974377db450a53fa2bf7ce9277b6c3 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Sun, 27 Sep 2026 03:35:06 +0800 Subject: [PATCH] [fix] statically link the Windows CRT in Slint --- apps/desktop/xmake/targets.lua | 9 +++++++++ deps/thirdparty/slint/xmake.lua | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/desktop/xmake/targets.lua b/apps/desktop/xmake/targets.lua index b8ea6f26..a50b48d6 100644 --- a/apps/desktop/xmake/targets.lua +++ b/apps/desktop/xmake/targets.lua @@ -38,6 +38,15 @@ function setup_targets() local runtime_dir = path.join(slint:installdir(), "lib") local runtime_dll = path.join(runtime_dir, "slint_cpp.dll") assert(os.isfile(runtime_dll), "Slint runtime not found: " .. runtime_dll) + import("utils.binary.deplibs") + local dependencies = deplibs(runtime_dll, {plat = "windows", arch = target:arch()}) + assert(dependencies and #dependencies > 0, "Cannot inspect Slint runtime dependencies: " .. runtime_dll) + for _, dependency in ipairs(dependencies) do + local name = path.filename(dependency):lower() + assert(not (name:match("^vcruntime%d.*%.dll$") or name:match("^msvcp%d.*%.dll$") or + name:match("^msvcr%d.*%.dll$") or name:match("^concrt%d.*%.dll$")), + "Slint runtime depends on " .. dependency .. "; rebuild the Slint package with static CRT") + end os.cp(runtime_dll, target:targetdir()) end diff --git a/deps/thirdparty/slint/xmake.lua b/deps/thirdparty/slint/xmake.lua index 7fecc81c..7012932e 100644 --- a/deps/thirdparty/slint/xmake.lua +++ b/deps/thirdparty/slint/xmake.lua @@ -8,6 +8,10 @@ package("slint") add_versions("1.17.1", "68222567f8c70ff677cd4a98cd94fb4765ac0f797eb8f8608a646911c908dc2a") add_configs("shared", {description = "Build the Slint runtime as a shared library", default = true, type = "boolean", readonly = true}) + if is_plat("windows") then + -- Include CRT linkage in the package hash so cached /MD builds are not reused. + add_configs("static_crt", {description = "Statically link the Windows C runtime", default = true, type = "boolean", readonly = true}) + end add_deps("cmake~slint >=3.21 <4.0", {host = true, private = true, system = false}) add_deps("rust 1.92.0", {host = true, private = true, system = false}) @@ -51,13 +55,26 @@ package("slint") "-DSLINT_STYLE=fluent", "-DBUILD_SHARED_LIBS=ON" } + local cmake = import("package.tools.cmake") + local envs if package:is_plat("windows") then local rc = assert(package:build_getenv("mrc"), "failed to find the Windows resource compiler") rc = rc:gsub("\\", "/") table.insert(configs, "-DCMAKE_RC_COMPILER=" .. rc) + table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded") + + -- Slint is a Rust cdylib: CMake's /MT setting alone does not affect it. + -- Encoded flags take precedence over RUSTFLAGS set by Corrosion. + envs = cmake.buildenvs(package) + local rustflags = os.getenv("CARGO_ENCODED_RUSTFLAGS") + if rustflags == nil then + rustflags = table.concat((os.getenv("RUSTFLAGS") or ""):split("%s+"), "\31") + end + envs.CARGO_ENCODED_RUSTFLAGS = (rustflags ~= "" and rustflags .. "\31" or "") .. + "-Ctarget-feature=+crt-static" end - import("package.tools.cmake").install(package, configs) + cmake.install(package, configs, {envs = envs}) end) on_test(function(package)