diff options
| author | ruki <[email protected]> | 2023-09-21 22:44:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-21 22:44:08 +0800 |
| commit | efee9f525906e48699c4bf0eb10cce74d4e7b468 (patch) | |
| tree | 37892b254262d928d05c6f62a1a22aa3832a04c9 /xmake/rules/c++ | |
| parent | 8afc0e7ed5d14918fa4fafd450b23263f62ea147 (diff) | |
enable asan for objc
Diffstat (limited to 'xmake/rules/c++')
| -rw-r--r-- | xmake/rules/c++/build_sanitizer/config.lua | 28 | ||||
| -rw-r--r-- | xmake/rules/c++/build_sanitizer/xmake.lua | 12 |
2 files changed, 37 insertions, 3 deletions
diff --git a/xmake/rules/c++/build_sanitizer/config.lua b/xmake/rules/c++/build_sanitizer/config.lua index 52732e6a4..38d548004 100644 --- a/xmake/rules/c++/build_sanitizer/config.lua +++ b/xmake/rules/c++/build_sanitizer/config.lua @@ -21,15 +21,23 @@ -- imports import("core.tool.compiler") import("core.project.project") +import("lib.detect.find_tool") +import("core.base.semver") -- add build sanitizer function _add_build_sanitizer(target, sourcekind, checkmode) -- add cflags local _, cc = target:tool(sourcekind) - local cflag = sourcekind == "cxx" and "cxxflags" or "cflags" - if target:has_tool(sourcekind, "cl", "clang", "clangxx", "gcc", "gxx") then - target:add(cflag, "-fsanitize=" .. checkmode) + local flagnames = { + cc = "cflags", + cxx = "cxxflags", + mm = "mflags", + mxx = "mxflags" + } + local flagname = flagnames[sourcekind] + if flagname and target:has_tool(sourcekind, "cl", "clang", "clangxx", "gcc", "gxx") then + target:add(flagname, "-fsanitize=" .. checkmode) end -- add ldflags and shflags @@ -40,8 +48,22 @@ function _add_build_sanitizer(target, sourcekind, checkmode) end function main(target, sourcekind) + local sanitizer = false if target:policy("build.sanitizer.address") or project.policy("build.sanitizer.address") then _add_build_sanitizer(target, sourcekind, "address") + sanitizer = true + end + + if sanitizer and target:is_plat("windows") and target:is_binary() then + local msvc = target:toolchain("msvc") + if msvc then + local envs = msvc:runenvs() + local vscmd_ver = envs and envs.VSCMD_VER + if vscmd_ver and semver.match(vscmd_ver):ge("17.7") then + local cl = assert(find_tool("cl", {envs = envs}), "cl not found!") + target:add("runenvs", "PATH", path.directory(cl.program)) + end + end end end diff --git a/xmake/rules/c++/build_sanitizer/xmake.lua b/xmake/rules/c++/build_sanitizer/xmake.lua index cd96e9150..e7f8dbb62 100644 --- a/xmake/rules/c++/build_sanitizer/xmake.lua +++ b/xmake/rules/c++/build_sanitizer/xmake.lua @@ -30,3 +30,15 @@ rule("c++.build.sanitizer") import("config")(target, "cxx") end) +-- define rule: objc.build.sanitizer +rule("objc.build.sanitizer") + on_config(function (target) + import("config")(target, "mm") + end) + +-- define rule: objc++.build.sanitizer +rule("objc++.build.sanitizer") + on_config(function (target) + import("config")(target, "mxx") + end) + |
