summaryrefslogtreecommitdiff
path: root/xmake/rules/c++
diff options
context:
space:
mode:
authorstar9029 <[email protected]>2025-12-22 11:42:39 +0800
committerstar9029 <[email protected]>2025-12-22 11:42:39 +0800
commita9e51834621aedeb6e8aa5aec0880af28ac4200d (patch)
tree2d558cc78ce31cc0a6132684010d0b10a8c6b8e3 /xmake/rules/c++
parent3c6c162da56f3fe7b9b99dd3f1194e0a545c68f7 (diff)
clean code to toolchain_utils
Diffstat (limited to 'xmake/rules/c++')
-rw-r--r--xmake/rules/c++/config/sanitizer.lua40
1 files changed, 4 insertions, 36 deletions
diff --git a/xmake/rules/c++/config/sanitizer.lua b/xmake/rules/c++/config/sanitizer.lua
index 1862d3e9b..646197c0c 100644
--- a/xmake/rules/c++/config/sanitizer.lua
+++ b/xmake/rules/c++/config/sanitizer.lua
@@ -24,11 +24,6 @@ import("lib.detect.find_tool")
import("core.base.semver")
import("private.utils.toolchain", {alias = "toolchain_utils"})
-function _get_clang_asan_library_dir(target)
- local toolchain = target:toolchain("clang-cl") or target:toolchain("clang")
- return path.join(toolchain_utils.get_llvm_resourcedir(toolchain), "lib/windows")
-end
-
-- add build sanitizer
function _add_build_sanitizer(target, sourcekind, checkmode)
-- add cflags
@@ -52,36 +47,11 @@ function _add_build_sanitizer(target, sourcekind, checkmode)
end
if target:is_plat("windows") and checkmode == "address" and not target:has_tool("cxx", "cl") then
- assert(target:has_runtime("MD", "MT"), "clang asan only support MD/MT runtime on windows")
-
- local ldflags = {}
- if target:has_tool("ld", "clang", "clangxx") then
- if target:has_runtime("MT") then
- table.insert(ldflags, "-D_MT")
- elseif target:has_runtime("MD") then
- table.join2(ldflags, {"-D_MT", "-D_DLL"})
- end
- else
- -- cmake unsupported use clang++ as linker with clang-cl compiler, so we keep using lld-link/link as linker
- -- @see https://gitlab.kitware.com/cmake/cmake/-/issues/26430
- local kind
- if target:has_runtime("MD") then
- kind = "dynamic"
- elseif target:has_runtime("MT") then
- kind = "static"
- end
-
- local libdir = _get_clang_asan_library_dir(target)
- local driver = target:has_tool("ld", "lld_link", "link") and "" or "-Wl,"
- local thunk = path.join(libdir, string.format("clang_rt.asan_%s_runtime_thunk-x86_64.lib", kind))
- table.join2(ldflags, {
- path.unix(path.join(libdir, "clang_rt.asan_dynamic-x86_64.lib")),
- driver .. "/WHOLEARCHIVE:" .. path.unix(thunk),
- driver .. "/INFERASANLIBS:NO",
- })
+ local ldflags = toolchain_utils.add_llvm_asan_flags(target)
+ if #ldflags ~= 0 then
+ target:add("ldflags", ldflags, {force = true})
+ target:add("shflags", ldflags, {force = true})
end
- target:add("ldflags", ldflags, {force = true})
- target:add("shflags", ldflags, {force = true})
end
end
@@ -117,8 +87,6 @@ function main(target, sourcekind)
target:add("runenvs", "PATH", path.directory(cl.program))
end
end
- else
- target:add("runenvs", "PATH", _get_clang_asan_library_dir(target))
end
end
end