diff options
| author | ruki <[email protected]> | 2023-09-21 22:38:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-21 22:38:18 +0800 |
| commit | 3d9cf6af8a3fae36dbb5e8fe055a54000ddcadfb (patch) | |
| tree | 6ecc187316c099057cdad9cdeeaa8d93ef73913e /xmake/core/package/package.lua | |
| parent | 5c619b17b5847b18d284323830dedaeff9d5d6ed (diff) | |
add asan support for package and policy
Diffstat (limited to 'xmake/core/package/package.lua')
| -rw-r--r-- | xmake/core/package/package.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 074e35b29..10d32a0ca 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2111,6 +2111,24 @@ function _instance:_generate_lto_configs(sourcekind) return configs end +-- generate sanitizer configs +function _instance:_generate_sanitizer_configs(sourcekind, checkmode) + + -- add cflags + local configs = {} + if self:has_tool(sourcekind, "cl", "clang", "clangxx", "gcc", "gxx") then + local cflag = sourcekind == "cxx" and "cxxflags" or "cflags" + configs[cflag] = "-fsanitize=" .. checkmode + end + + -- add ldflags and shflags + if self:has_tool("ld", "link", "clang", "clangxx", "gcc", "gxx") then + configs.ldflags = "-fsanitize=" .. checkmode + configs.shflags = "-fsanitize=" .. checkmode + end + return configs +end + -- generate building configs for has_xxx/check_xxx function _instance:_generate_build_configs(configs, opt) opt = opt or {} @@ -2146,6 +2164,15 @@ function _instance:_generate_build_configs(configs, opt) end end end + if self:config("asan") then + local configs_asan = self:_generate_sanitizer_configs(opt.sourcekind or "cxx", "address") + if configs_asan then + for k, v in pairs(configs_asan) do + configs[k] = table.wrap(configs[k] or {}) + table.join2(configs[k], v) + end + end + end -- enable exceptions for msvc by default if opt.sourcekind == "cxx" and configs.exceptions == nil and self:has_tool("cxx", "cl") then configs.exceptions = "cxx" |
