summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-23 14:09:20 +0800
committerGitHub <[email protected]>2025-12-23 14:09:20 +0800
commit47f9f2604141a5995c88d28d00938020a547b6dc (patch)
treef8f8437ad6c9196fe35f2f3eb33caf137d02b2bc
parentf5adbc00fad0f91ccb820856a859a5223d9080e9 (diff)
parentb08157afffc8514fb7ecae44cb2d9d01c32aea7c (diff)
Merge pull request #7163 from xmake-io/clang
Improve clang envs
-rw-r--r--xmake/modules/private/utils/toolchain.lua15
-rw-r--r--xmake/toolchains/clang-cl/load.lua8
-rw-r--r--xmake/toolchains/clang/load.lua20
3 files changed, 24 insertions, 19 deletions
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua
index cd2f20736..48aabdffa 100644
--- a/xmake/modules/private/utils/toolchain.lua
+++ b/xmake/modules/private/utils/toolchain.lua
@@ -115,7 +115,9 @@ function _add_vsenv(toolchain, name, curenvs)
if (name == "INCLUDE" or name == "LIB") and not is_host("windows") then
toolchain:add("runenvs", name, path.joinenv(path.splitenv(new), ";"))
else
- toolchain:add("runenvs", name, table.unwrap(path.splitenv(new)))
+ for _, item in ipairs(path.splitenv(new)) do
+ toolchain:add("runenvs", name, item)
+ end
end
end
end
@@ -467,16 +469,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..69f9c8297 100644
--- a/xmake/toolchains/clang-cl/load.lua
+++ b/xmake/toolchains/clang-cl/load.lua
@@ -49,8 +49,12 @@ function main(toolchain)
-- add vs environments
toolchain_utils.add_vsenvs(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 target flags
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