Skip to content

Commit

Permalink
Add sanitizer flags to Gradle build
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Dec 22, 2024
1 parent 469bb32 commit 8cea52e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ Run with `--build-cache` on the command-line to use the shared [build cache](htt
./gradlew build --build-cache
```

### C++ sanitizers

The C++ compiler's address, thread, and undefined behavior sanitizers can be enabled with the `-Pasan`, `-Ptsan`, and `-Pubsan` flags respectively.

```bash
./gradlew build -Pasan
./gradlew build -Ptsan
./gradlew build -Pubsan
```

### Using Development Builds

Please read the documentation available [here](DevelopmentBuilds.md)
Expand Down
45 changes: 45 additions & 0 deletions shared/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@ nativeUtils.platformConfigs.each {
}
}

// Add address sanitizer flag
if (project.hasProperty('asan')) {
nativeUtils.platformConfigs.each {
if (it.name.contains('windows') || it.name == nativeUtils.wpi.platforms.roborio) {
return
}
it.cppCompiler.args.add('-g3')
it.cppCompiler.args.add('-fsanitize=address')
it.linker.args.add('-fsanitize=address')
if (it.name == nativeUtils.wpi.platforms.linuxx64) {
it.linker.args.add('-static-libasan')
}
}
}

// Add thread sanitizer flag
if (project.hasProperty('tsan')) {
nativeUtils.platformConfigs.each {
if (it.name.contains('windows') || it.name == nativeUtils.wpi.platforms.roborio) {
return
}
it.cppCompiler.args.add('-g3')
it.cppCompiler.args.add('-fsanitize=thread')
it.linker.args.add('-fsanitize=thread')
if (it.name == nativeUtils.wpi.platforms.linuxx64) {
it.linker.args.add('-static-libtsan')
}
}
}

// Add undefined behavior sanitizer flag
if (project.hasProperty('ubsan')) {
nativeUtils.platformConfigs.each {
if (it.name.contains('windows') || it.name == nativeUtils.wpi.platforms.roborio) {
return
}
it.cppCompiler.args.add('-g3')
it.cppCompiler.args.add('-fsanitize=undefined')
it.linker.args.add('-fsanitize=undefined')
if (it.name == nativeUtils.wpi.platforms.linuxx64) {
it.linker.args.add('-static-libubsan')
}
}
}

nativeUtils.platformConfigs.linuxathena.linker.args.add("-Wl,--fatal-warnings")

if (project.hasProperty('ntcoreffibuild')) {
Expand Down

0 comments on commit 8cea52e

Please sign in to comment.