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/rules | |
| parent | 5c619b17b5847b18d284323830dedaeff9d5d6ed (diff) | |
add asan support for package and policy
Diffstat (limited to 'xmake/rules')
| -rw-r--r-- | xmake/rules/c++/build_sanitizer/config.lua | 47 | ||||
| -rw-r--r-- | xmake/rules/c++/build_sanitizer/xmake.lua | 32 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 4 |
3 files changed, 81 insertions, 2 deletions
diff --git a/xmake/rules/c++/build_sanitizer/config.lua b/xmake/rules/c++/build_sanitizer/config.lua new file mode 100644 index 000000000..52732e6a4 --- /dev/null +++ b/xmake/rules/c++/build_sanitizer/config.lua @@ -0,0 +1,47 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file config.lua +-- + +-- imports +import("core.tool.compiler") +import("core.project.project") + +-- 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) + end + + -- add ldflags and shflags + if target:has_tool("ld", "link", "clang", "clangxx", "gcc", "gxx") then + target:add("ldflags", "-fsanitize=" .. checkmode) + target:add("shflags", "-fsanitize=" .. checkmode) + end +end + +function main(target, sourcekind) + if target:policy("build.sanitizer.address") or + project.policy("build.sanitizer.address") then + _add_build_sanitizer(target, sourcekind, "address") + end +end diff --git a/xmake/rules/c++/build_sanitizer/xmake.lua b/xmake/rules/c++/build_sanitizer/xmake.lua new file mode 100644 index 000000000..cd96e9150 --- /dev/null +++ b/xmake/rules/c++/build_sanitizer/xmake.lua @@ -0,0 +1,32 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: c.build.sanitizer +rule("c.build.sanitizer") + on_config(function (target) + import("config")(target, "cc") + end) + +-- define rule: c++.build.sanitizer +rule("c++.build.sanitizer") + on_config(function (target) + import("config")(target, "cxx") + end) + diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 19c943e77..e130df73b 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -20,12 +20,12 @@ rule("c.build") set_sourcekinds("cc") - add_deps("c.build.pcheader", "c.build.optimization") + add_deps("c.build.pcheader", "c.build.optimization", "c.build.sanitizer") on_build_files("private.action.build.object", {batch = true, distcc = true}) rule("c++.build") set_sourcekinds("cxx") - add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization") + add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization", "c++.build.sanitizer") on_build_files("private.action.build.object", {batch = true, distcc = true}) on_config(function (target) -- we enable c++ exceptions by default |
