Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions ddtrace/appsec/_iast/_ast/CMakeLists.txt

This file was deleted.

93 changes: 18 additions & 75 deletions ddtrace/appsec/_iast/_taint_tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
cmake_minimum_required(VERSION 3.19)
include(FetchContent)

set(APP_NAME _native)
option(BUILD_MACOS "Build for MacOS" OFF)
if(DEFINED ENV{CIBUILDWHEEL} OR DEFINED ENV{CIBW_BUILD})
option(NATIVE_TESTING "Disable test subdirectories and targets" OFF)
else()
option(NATIVE_TESTING "Load test subdirectories and targets" ON)
endif()
# AIDEV-NOTE: This CMakeLists.txt is used exclusively to build the native C++ unit tests (appsec_iast_native riot venv).
# The _native Python extension itself is now built via AbslExtension in setup.py, so there is no pybind11_add_module /
# install() here.

project(${APP_NAME})
project(_native_tests)

set(CMAKE_CXX_STANDARD 17)

Expand All @@ -24,34 +20,15 @@ add_compile_options(
-Wall
-Wno-unknown-pragmas
-U_FORTIFY_SOURCE
-g) # Add debug symbols always, it will be stripped in release/minsizerel by cmake
-g)

if(BUILD_MACOS)
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
message(STATUS "Compile options for MacOS")
if(APPLE)
add_link_options(-ldl -undefined dynamic_lookup)
else()
message(STATUS "Compile options for Linux/Win")
endif(BUILD_MACOS)
unset(BUILD_MACOS CACHE)
endif()

# Check the DD_COMPILE_ABSEIL environment variable and build type
if(DEFINED ENV{DD_COMPILE_ABSEIL} AND ("$ENV{DD_COMPILE_ABSEIL}" STREQUAL "0" OR "$ENV{DD_COMPILE_ABSEIL}" STREQUAL
"false"))
message("==============================================================")
message("WARNING: DD_COMPILE_ABSEIL set to 0 or false: not using abseil")
message("==============================================================")
add_definitions(-DDONT_COMPILE_ABSEIL) # Define DONT_COMPILE_ABSEIL preprocessor variable
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("=====================================")
message("WARNING: Debug mode: not using abseil")
message("=====================================")
add_definitions(-DDONT_COMPILE_ABSEIL) # Define DONT_COMPILE_ABSEIL preprocessor variable
else()
message("Release, RelWithDebInfo, or MinSizeRel mode: using abseil (DD_COMPILE_ABSEIL unset or not 0/false)")
# Use a git-based fetch rather than a ZIP download: git shallow clones are more resilient to GitHub transient
# failures than release archive downloads. FETCHCONTENT_UPDATES_DISCONNECTED prevents re-fetching on every configure
# once the initial clone is in the cache (set by FETCHCONTENT_BASE_DIR in setup.py).
# In Release/RelWithDebInfo builds NDEBUG is defined and taint_range.h selects absl::node_hash_map, so we need Abseil.
# In Debug builds NDEBUG is not set and std::unordered_map is used, so Abseil is skipped.
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(FETCHCONTENT_UPDATES_DISCONNECTED
ON
CACHE BOOL "" FORCE)
Expand Down Expand Up @@ -89,51 +66,17 @@ file(
"taint_tracking/*.h"
"utils/*.h")

# Find ICU library (not needed for now) find_package(ICU REQUIRED COMPONENTS uc i18n) # 'uc' for the common library,
# 'i18n' for the internationalization library include_directories(${ICU_INCLUDE_DIRS}) list(APPEND ICU_LIBS
# ${ICU_LIBRARIES})

# Debug messages
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
# message(STATUS "ICU_LIBRARIES = ${ICU_LIBRARIES}") message(STATUS "ICU_INCLUDE_DIRS = ${ICU_INCLUDE_DIRS}")

# For pybind11 3.0: Use legacy Python detection (compatible with wheel building)
set(PYBIND11_FINDPYTHON OFF)

add_subdirectory(_vendor/pybind11)
if(NATIVE_TESTING)
find_package(
Python3
COMPONENTS Interpreter Development
REQUIRED)
# Legacy variables expected elsewhere in the project/tests
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})

add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()

# Set verbose mode so compiler and args are shown
set(CMAKE_VERBOSE_MAKEFILE ON)

pybind11_add_module(_native SHARED ${SOURCE_FILES} ${HEADER_FILES})
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
set_target_properties(_native PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")

# target_link_libraries(_native PRIVATE ${ICU_LIBS})

if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")
AND NOT (DEFINED ENV{DD_COMPILE_ABSEIL} AND ("$ENV{DD_COMPILE_ABSEIL}" STREQUAL "0" OR "$ENV{DD_COMPILE_ABSEIL}"
STREQUAL "false")))
target_link_libraries(${APP_NAME} PRIVATE absl::node_hash_map)
endif()
find_package(
Python3
COMPONENTS Interpreter Development
REQUIRED)
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})

install(
TARGETS _native
DESTINATION LIBRARY
DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${LIB_INSTALL_DIR})
add_subdirectory(tests EXCLUDE_FROM_ALL)
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class TaintedObject;
// Alias
using TaintedObjectPtr = shared_ptr<TaintedObject>;

// Use Abseil only if NDEBUG is set and DONT_COMPILE_ABSEIL is not set
#if defined(NDEBUG) && !defined(DONT_COMPILE_ABSEIL)
// Use Abseil in Release builds; fall back to std::unordered_map in Debug (NDEBUG not set).
#if defined(NDEBUG)
#include "absl/container/node_hash_map.h"
using TaintedObjectMapType = absl::node_hash_map<uintptr_t, std::pair<Py_hash_t, TaintedObjectPtr>>;
#else
Expand Down
13 changes: 2 additions & 11 deletions ddtrace/appsec/_iast/_taint_tracking/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ add_executable(native_tests ${TEST_SOURCES} ${SOURCE_FILES} ${HEADER_FILES})

set(NATIVE_TEST_LIBRARIES gtest gtest_main ${PYTHON_LIBRARIES} pybind11::module)

if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")
AND NOT (DEFINED ENV{DD_COMPILE_ABSEIL} AND ("$ENV{DD_COMPILE_ABSEIL}" STREQUAL "0" OR "$ENV{DD_COMPILE_ABSEIL}"
STREQUAL "false")))
# Mirror taint_range.h: Abseil is only used in Release builds (NDEBUG defined).
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND NATIVE_TEST_LIBRARIES absl::node_hash_map)
endif()

Expand All @@ -35,18 +34,10 @@ endif()

target_link_libraries(native_tests ${NATIVE_TEST_LIBRARIES})

# Enable ASan for native tests to detect memory errors at runtime. option(NATIVE_TEST_ASAN "Enable AddressSanitizer for
# native tests" ON) if(NATIVE_TEST_ASAN AND NOT MSVC) target_compile_options(native_tests PRIVATE -fsanitize=address
# -fno-omit-frame-pointer) target_link_options(native_tests PRIVATE -fsanitize=address) endif()

# Discover tests
include(GoogleTest)
gtest_discover_tests(native_tests)

# replace gtest_discover_tests to use ASan for native tests to detect memory errors at runtime. gtest_discover_tests(
# native_tests DISCOVERY_MODE PRE_TEST PROPERTIES ENVIRONMENT
# "ASAN_OPTIONS=detect_leaks=0:halt_on_error=1:abort_on_error=1;LSAN_OPTIONS=verbosity=1:log_threads=1")

add_custom_target(
test_valgrind
COMMAND
Expand Down
158 changes: 0 additions & 158 deletions ddtrace/profiling/collector/CMakeLists.txt

This file was deleted.

7 changes: 3 additions & 4 deletions ddtrace/profiling/collector/_memalloc_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
* flat_hash_map provides excellent performance with low memory overhead,
* using the Swiss Tables algorithm from Abseil.
*
* We use a conditional compilation to fall back to std::unordered_map
* when Abseil is not available (e.g., in Debug builds).
* Fall back to std::unordered_map in Debug builds (NDEBUG not set).
*/
#if defined(NDEBUG) && !defined(DONT_COMPILE_ABSEIL)
#if defined(NDEBUG)
#include "absl/container/flat_hash_map.h"
template<typename K, typename V>
using HeapMapType = absl::flat_hash_map<K, V>;
#else
#include <unordered_map>
template<typename K, typename V>
using HeapMapType = std::unordered_map<K, V>;
#endif // defined(NDEBUG) && !defined(DONT_COMPILE_ABSEIL)
#endif // defined(NDEBUG)

/*
How heap profiler sampling works:
Expand Down
Loading
Loading