Skip to content

Commit 8a5e161

Browse files
committed
xmake: Sanitize options
1 parent 11ca3d1 commit 8a5e161

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,22 @@ target("YourProject", function()
126126
end)
127127
```
128128

129-
### Contribute
129+
### Configure the build via the xmake menu
130+
```console
131+
xmake f [--toolchain=llvm] --runtimes="c++_shared" [--sdk=/opt/llvm-git] --menu
132+
```
133+
134+
### Configure the build manually
135+
```console
136+
xmake f [--toolchain=llvm] --runtimes="c++_shared" [--sdk=/opt/llvm-git] [-y|--yes] [--enable_tests=y] [--sanitize_memory=y] [--sanitize_thread=y]
137+
```
130138

131139
### Build command
132140
```console
133-
xmake f [--toolchain=llvm] --runtimes="c++_shared" [--sdk=/opt/llvm-git] [--enable_tests=y] --yes
134141
xmake [b|build] [-vD]
135142
```
136143

137-
### Run tests
144+
### Build & Run tests
138145
```console
139146
xmake [r|run]
140147
```
@@ -144,6 +151,8 @@ xmake [r|run]
144151
xmake watch -r
145152
```
146153

154+
### Contribute
155+
147156
[![Contribute](https://img.shields.io/badge/-Contribute-blue?style=for-the-badge)](CONTRIBUTING.md)
148157

149158
---

xmake.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ add_rules(
2828
"mode.check",
2929
"mode.profile",
3030
"mode.coverage",
31-
"mode.valgrind",
32-
"mode.asan",
33-
"mode.tsan",
34-
"mode.lsan",
35-
"mode.ubsan")
31+
"mode.valgrind")
3632

37-
option("enable_tests")
38-
option("enable_moduleonly", {default = true})
33+
option("enable_moduleonly", {default = true, category = "Build CppUtils", description = "Module only"})
34+
option("sanitize_memory", {default = false, category = "Build CppUtils/Sanitizer", description = "Enable ASan + LSan + UBSan"})
35+
option("sanitize_thread", {default = false, category = "Build CppUtils/Sanitizer", description = "Enable TSan"})
36+
option("enable_tests", {default = true, description = "Enable Unit Tests"})
3937

4038
target("CppUtils", function()
4139
if get_config("enable_moduleonly") then
@@ -48,6 +46,16 @@ target("CppUtils", function()
4846
add_includedirs("include", { public = true })
4947
add_headerfiles("include/(CppUtils/**.hpp)")
5048
add_headerfiles("include/(Stl/**.hpp)")
49+
50+
if get_config("sanitize_memory") then
51+
set_policy("build.sanitizer.address", true) -- ASAN
52+
set_policy("build.sanitizer.leak", true) -- LSan
53+
set_policy("build.sanitizer.undefined", true) -- UBSan
54+
end
55+
56+
if get_config("sanitize_thread") then
57+
set_policy("build.sanitizer.thread", true) -- TSan
58+
end
5159
end)
5260

5361
if has_config("enable_tests") then

0 commit comments

Comments
 (0)