summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-23 22:42:38 +0800
committerruki <[email protected]>2025-12-23 22:42:38 +0800
commite0c5f68ea4892333ca4a4b10362f1e9aa8ce9118 (patch)
treed1e0749124dc6d1108e550a36640655ebff58ed0
parentf5adbc00fad0f91ccb820856a859a5223d9080e9 (diff)
improve llvm/clang toolchain
-rw-r--r--xmake/modules/private/utils/toolchain.lua11
-rw-r--r--xmake/toolchains/clang-cl/load.lua10
-rw-r--r--xmake/toolchains/clang/load.lua20
3 files changed, 22 insertions, 19 deletions
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua
index cd2f20736..af165080f 100644
--- a/xmake/modules/private/utils/toolchain.lua
+++ b/xmake/modules/private/utils/toolchain.lua
@@ -467,16 +467,7 @@ function add_llvm_runenvs(toolchain)
for _, dir in ipairs({dirs.libdir or false, dirs.cxxlibdir or false, dirs.rtlibdir or false}) do
if dir then
if toolchain:is_plat("windows") or is_host("windows") then
- -- The dynamic libraries (DLLs) for Clang ASan and MSVC ASan share the same filename, making them incompatible.
- -- Currently, runenvs maybe have Visual Studio environment variables.
- -- If the Clang path is not prioritized (placed first), the system incorrectly loads the MSVC ASan DLL, resulting in a runtime failure.
- local runenvs = toolchain:get("runenvs")
- if runenvs and runenvs["PATH"] then
- runenvs["PATH"] = table.wrap(runenvs["PATH"])
- table.insert(runenvs["PATH"], 1, dir)
- else
- toolchain:add("runenvs", "PATH", dir)
- end
+ toolchain:add("runenvs", "PATH", dir)
elseif toolchain:is_plat("linux", "bsd") then
toolchain:add("runenvs", "LD_LIBRARY_PATH", dir)
elseif toolchain:is_plat("macosx") then
diff --git a/xmake/toolchains/clang-cl/load.lua b/xmake/toolchains/clang-cl/load.lua
index f69b98cb3..e06883012 100644
--- a/xmake/toolchains/clang-cl/load.lua
+++ b/xmake/toolchains/clang-cl/load.lua
@@ -47,11 +47,15 @@ function main(toolchain)
toolchain:set("toolset", "ar", "link.exe")
end
+ -- add llvm runenvs before adding vsenvs
+ --
+ -- The dynamic libraries (DLLs) for Clang ASan and MSVC ASan share the same filename, making them incompatible.
+ -- Currently, runenvs maybe have Visual Studio environment variables.
+ -- If the Clang path is not prioritized (placed first), the system incorrectly loads the MSVC ASan DLL, resulting in a runtime failure.
+ toolchain_utils.add_llvm_runenvs(toolchain)
+
-- add vs environments
toolchain_utils.add_vsenvs(toolchain)
-
- -- add llvm runenvs
- toolchain_utils.add_llvm_runenvs(toolchain)
-- add target flags
local flags = toolchain_utils.get_clang_target_flags(toolchain)
diff --git a/xmake/toolchains/clang/load.lua b/xmake/toolchains/clang/load.lua
index 14bffea51..4a12b31ce 100644
--- a/xmake/toolchains/clang/load.lua
+++ b/xmake/toolchains/clang/load.lua
@@ -52,14 +52,22 @@ function main(toolchain, suffix)
toolchain:add("shflags", flags)
end
- -- init windows
- if toolchain:is_plat("windows") then
- _load_windows(toolchain, suffix)
- end
-
-- set llvm runtimes
toolchain_utils.set_llvm_runtimes(toolchain)
- -- add llvm runenvs
+ -- add llvm runenvs before adding vsenvs
+ --
+ -- The dynamic libraries (DLLs) for Clang ASan and MSVC ASan share the same filename, making them incompatible.
+ -- Currently, runenvs maybe have Visual Studio environment variables.
+ -- If the Clang path is not prioritized (placed first), the system incorrectly loads the MSVC ASan DLL, resulting in a runtime failure.
toolchain_utils.add_llvm_runenvs(toolchain)
+
+ -- add configs for windows
+ if toolchain:is_plat("windows") then
+ toolchain_utils.add_vsenvs(toolchain)
+ if is_host("linux") or project.policy("build.optimization.lto") then
+ toolchain:add("ldflags", "-fuse-ld=lld-link" .. suffix)
+ toolchain:add("shflags", "-fuse-ld=lld-link" .. suffix)
+ end
+ end
end