Skip to content

Commit e31cc94

Browse files
authored
Merge pull request #342 from Distributive-Network/caleb/build/sanitize
feat(build): implement Sanitize build using AddressSanitizer
2 parents ee72ee4 + 7808d4f commit e31cc94

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

.github/workflows/test-and-publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ on:
3939
options:
4040
- 'Debug'
4141
- 'Profile'
42+
- 'Sanitize'
4243
- 'DRelease'
4344
- 'Release'
4445
- 'None'

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
3737
SET(KEEP_SYMBOLS "/DEBUG:FULL")
3838
SET(STRIP_SYMBOLS "/DEBUG:NONE")
3939
SET(PROFILE "/PROFILE")
40+
SET(ADDRESS_SANITIZE "/fsanitize=address /Oy-")
4041
else()
4142
SET(COMPILE_FLAGS "-fno-rtti -Wno-invalid-offsetof")
4243

@@ -45,20 +46,24 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
4546
SET(KEEP_SYMBOLS "-ggdb")
4647
SET(STRIP_SYMBOLS "-s")
4748
SET(PROFILE "-pg")
49+
SET(ADDRESS_SANITIZE "-fsanitize=address -fno-omit-frame-pointer")
4850
endif()
4951
SET(PROFILE_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS} ${PROFILE}")
52+
SET(SANITIZE_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS} ${ADDRESS_SANITIZE}")
5053
SET(DEBUG_FLAGS "${UNOPTIMIZED} ${KEEP_SYMBOLS}")
5154
SET(DRELEASE_FLAGS "${OPTIMIZED} ${KEEP_SYMBOLS}")
5255
SET(RELEASE_FLAGS "${OPTIMIZED} ${STRIP_SYMBOLS}")
5356

5457
if(GENERATOR_IS_MULTI_CONFIG)
55-
set(CMAKE_CONFIGURATION_TYPES "Profile;Debug;DRelease;Release;None" CACHE STRING "" FORCE)
56-
string(APPEND COMPILE_FLAGS "$<$<CONFIG:Profile>:${PROFILE_FLAGS}> $<$<CONFIG:Debug>:${DEBUG_FLAGS}> $<$<CONFIG:DRelease>:${DRELEASE_FLAGS}> $<$<CONFIG:Release>:${RELEASE_FLAGS}>")
58+
set(CMAKE_CONFIGURATION_TYPES "Profile;Sanitize;Debug;DRelease;Release;None" CACHE STRING "" FORCE)
59+
string(APPEND COMPILE_FLAGS "$<$<CONFIG:Profile>:${PROFILE_FLAGS}> $<$<CONFIG:Sanitize>:${SANITIZE_FLAGS}> $<$<CONFIG:Debug>:${DEBUG_FLAGS}> $<$<CONFIG:DRelease>:${DRELEASE_FLAGS}> $<$<CONFIG:Release>:${RELEASE_FLAGS}>")
5760
else()
5861
set_property(CACHE PM_BUILD_TYPE PROPERTY HELPSTRING "Choose the type of build")
59-
set_property(CACHE PM_BUILD_TYPE PROPERTY STRINGS "Profile;Debug;DRelease;Release;None")
62+
set_property(CACHE PM_BUILD_TYPE PROPERTY STRINGS "Profile;Sanitize;Debug;DRelease;Release;None")
6063
if(PM_BUILD_TYPE STREQUAL "Profile")
6164
list(APPEND COMPILE_FLAGS "${PROFILE_FLAGS}")
65+
elseif(PM_BUILD_TYPE STREQUAL "Sanitize")
66+
list(APPEND COMPILE_FLAGS "${SANITIZE_FLAGS}")
6267
elseif(PM_BUILD_TYPE STREQUAL "Debug")
6368
list(APPEND COMPILE_FLAGS "${DEBUG_FLAGS}")
6469
elseif(PM_BUILD_TYPE STREQUAL "DRelease")

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# @date March 2024
55
#
66

7-
BUILD = Debug # (case-insensitive) Release, DRelease, Debug, Profile, or None
7+
BUILD = Debug # (case-insensitive) Release, DRelease, Debug, Sanitize, Profile, or None
88
DOCS = false
99
VERBOSE = true
1010
PYTHON = python3
@@ -21,6 +21,8 @@ endif
2121

2222
ifeq ($(BUILD),Profile)
2323
PYTHON_BUILD_ENV += BUILD_TYPE=Profile
24+
else ifeq ($(BUILD),Sanitize)
25+
PYTHON_BUILD_ENV += BUILD_TYPE=Sanitize
2426
else ifeq ($(BUILD),Debug)
2527
PYTHON_BUILD_ENV += BUILD_TYPE=Debug
2628
else ifeq ($(BUILD),DRelease)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ PythonMonkey supports multiple build types, which you can build by setting the `
8383
- `Release`: stripped symbols, maximum optimizations (default)
8484
- `DRelease`: same as `Release`, except symbols are not stripped
8585
- `Debug`: minimal optimizations
86+
- `Sanitize`: same as `Debug`, except with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) enabled
8687
- `Profile`: same as `Debug`, except profiling is enabled
8788
- `None`: don't compile (useful if you only want to build the docs)
8889

0 commit comments

Comments
 (0)