diff options
| author | ruki <[email protected]> | 2025-12-20 00:35:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-20 00:35:46 +0800 |
| commit | 3608bf0165ec41d87c93137ae6aaf2eb3c82f86b (patch) | |
| tree | 7b82147030b0fd2ff2a01ce6160609d656330528 | |
| parent | dee8082d12241d69cf370c7f566c48c0ca8827bd (diff) | |
fix runtimes for clang/llvm
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 14 | ||||
| -rw-r--r-- | xmake/toolchains/clang/load.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/clang/toolchain_clang.lua | 9 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/xmake.lua | 7 |
4 files changed, 22 insertions, 10 deletions
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index 49af8193f..2d6e63b15 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -91,6 +91,20 @@ function check_vstudio(toolchain, check) return vs end +-- set llvm runtimes +function set_llvm_runtimes(toolchain) + -- We should set them up uniformly here, because runtimes will be accessed early (in sanitizer), + -- which automatically triggers lazy loading of the toolchain. + -- However, if some runtime configurations are set in advance in the descriptor scope, + -- lazy loading will not be triggered when the runtimes are accessed, and some Windows runtimes may be lost. + -- + -- @see https://github.com/xmake-io/xmake/pull/7146#issuecomment-3674402132 + toolchain:set("runtimes", "c++_static", "c++_shared", "stdc++_static", "stdc++_shared") + if toolchain:is_plat("windows") then + toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") + end +end + -- check vc build tools sdk function check_vc_build_tools(toolchain, sdkdir, check) local opt = {} diff --git a/xmake/toolchains/clang/load.lua b/xmake/toolchains/clang/load.lua index 3c50e3be2..6e6e5ba6d 100644 --- a/xmake/toolchains/clang/load.lua +++ b/xmake/toolchains/clang/load.lua @@ -21,6 +21,7 @@ import("detect.sdks.find_vstudio") import("detect.sdks.find_mingw") import("core.project.config") +import("core.project.project") import("private.utils.toolchain", {alias = "toolchain_utils"}) -- add the given vs environment @@ -52,7 +53,6 @@ function _add_vsenv(toolchain, name, curenvs) end function main(toolchain, suffix) - import("core.project.project") local target if toolchain:is_arch("x86_64", "x64") then diff --git a/xmake/toolchains/clang/toolchain_clang.lua b/xmake/toolchains/clang/toolchain_clang.lua index b1e59356f..b9713c6ae 100644 --- a/xmake/toolchains/clang/toolchain_clang.lua +++ b/xmake/toolchains/clang/toolchain_clang.lua @@ -26,7 +26,6 @@ function toolchain_clang(version) set_kind("standalone") set_homepage("https://clang.llvm.org/") set_description("A C language family frontend for LLVM" .. (version and (" (" .. version .. ")") or "")) - set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") set_toolset("cc", "clang" .. suffix) set_toolset("cxx", "clang++" .. suffix, "clang" .. suffix) @@ -60,6 +59,7 @@ function toolchain_clang(version) on_load(function (toolchain) import("core.project.project") + import("private.utils.toolchain", {alias = "toolchain_utils"}) if project.policy("build.optimization.lto") then toolchain:set("toolset", "ar", "llvm-ar" .. suffix) @@ -79,9 +79,10 @@ function toolchain_clang(version) toolchain:add("ldflags", march) toolchain:add("shflags", march) end - if toolchain:is_plat("windows") then - toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") - end + + toolchain_utils.set_llvm_runtimes(toolchain) + + -- load windows configurations if toolchain:is_plat("windows", "mingw") then local rootdir = path.join(path.directory(os.scriptdir()), "clang") import("load", {rootdir = rootdir})(toolchain, suffix) diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index b8f37bec1..4a89b4f32 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -22,7 +22,6 @@ toolchain("llvm") set_kind("standalone") set_homepage("https://llvm.org/") set_description("A collection of modular and reusable compiler and toolchain technologies") - set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") set_toolset("cc", "clang") set_toolset("cxx", "clang++", "clang") @@ -52,10 +51,8 @@ toolchain("llvm") on_load(function (toolchain) import("private.utils.toolchain", {alias = "toolchain_utils"}) - -- add runtimes - if toolchain:is_plat("windows") then - toolchain:add("runtimes", "MT", "MTd", "MD", "MDd") - end + -- set llvm runtimes + toolchain_utils.set_llvm_runtimes(toolchain) -- add llvm runenvs toolchain_utils.add_llvm_runenvs(toolchain) |
