Skip to content
Merged
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
1 change: 1 addition & 0 deletions ddtrace/internal/datadog/profiling/build_standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ cmake_args=(
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_VERBOSE_MAKEFILE=ON
-DLIB_INSTALL_DIR=$(realpath $MY_DIR)/lib
-DDD_WRAPPER_DIR=$(realpath $MY_DIR)/lib
-DPython3_ROOT_DIR=$(python3 -c "import sys; print(sys.prefix)")
-DNATIVE_EXTENSION_LOCATION=$(realpath $MY_DIR)/../../native
-DEXTENSION_SUFFIX=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
Expand Down
11 changes: 8 additions & 3 deletions ddtrace/internal/datadog/profiling/ddup/CMakeLists.txt
Comment thread
taegyunkim marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake")
include(AnalysisFunc)

# Link against the pre-built libdd_wrapper shared library The library is built by setup.py and its location is passed
# via NATIVE_EXTENSION_LOCATION
set(DD_WRAPPER_LIB "${NATIVE_EXTENSION_LOCATION}/../datadog/profiling/libdd_wrapper${EXTENSION_SUFFIX}")
# Link against the pre-built libdd_wrapper shared library.
if(DEFINED DD_WRAPPER_DIR)
set(DD_WRAPPER_LIB "${DD_WRAPPER_DIR}/libdd_wrapper${EXTENSION_SUFFIX}")
else()
message(FATAL_ERROR "DD_WRAPPER_DIR is not set")
endif()

# Import the pre-built library as an imported target
add_library(dd_wrapper SHARED IMPORTED)
Expand Down Expand Up @@ -55,6 +58,7 @@ add_custom_command(
add_library(${EXTENSION_NAME} SHARED ${DDUP_CPP_SRC})

add_ddup_config(${EXTENSION_NAME})

# Cython generates code that produces errors for the following, so relax compile options
target_compile_options(${EXTENSION_NAME} PRIVATE -Wno-old-style-cast -Wno-shadow -Wno-address)

Expand Down Expand Up @@ -82,6 +86,7 @@ elseif(UNIX)
set_target_properties(${EXTENSION_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/.." BUILD_WITH_INSTALL_RPATH TRUE)
endif()
endif()

target_include_directories(
${EXTENSION_NAME}
PRIVATE ../dd_wrapper/include
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/datadog/profiling/run_clang_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cmake \
-DPython3_ROOT_DIR=$(python3 -c "import sys; print(sys.prefix)") \
-DEXTENSION_SUFFIX=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") \
-DNATIVE_EXTENSION_LOCATION="${REPO_ROOT}/ddtrace/internal/native" \
-DLIB_INSTALL_DIR="${BUILD_DIR}/dd_wrapper" \
-DDD_WRAPPER_DIR="${BUILD_DIR}/dd_wrapper" \
"${SCRIPT_DIR}/stack"
popd

Expand Down
9 changes: 4 additions & 5 deletions ddtrace/internal/datadog/profiling/stack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
# Custom cmake modules are in the parent directory
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

# Link against the pre-built libdd_wrapper shared library The library is built by setup.py and its location is passed
# via NATIVE_EXTENSION_LOCATION. For standalone builds, check LIB_INSTALL_DIR first.
if(LIB_INSTALL_DIR AND EXISTS "${LIB_INSTALL_DIR}/libdd_wrapper${EXTENSION_SUFFIX}")
set(DD_WRAPPER_LIB "${LIB_INSTALL_DIR}/libdd_wrapper${EXTENSION_SUFFIX}")
# Link against the pre-built libdd_wrapper shared library.
if(DEFINED DD_WRAPPER_DIR)
set(DD_WRAPPER_LIB "${DD_WRAPPER_DIR}/libdd_wrapper${EXTENSION_SUFFIX}")
else()
set(DD_WRAPPER_LIB "${NATIVE_EXTENSION_LOCATION}/../datadog/profiling/libdd_wrapper${EXTENSION_SUFFIX}")
message(FATAL_ERROR "DD_WRAPPER_DIR is not set")
Comment thread
taegyunkim marked this conversation as resolved.
endif()

# Import the pre-built library as an imported target
Expand Down
1 change: 1 addition & 0 deletions ddtrace/internal/datadog/profiling/stack/fuzz/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ cmake --build "${DD_WRAPPER_BUILD}" --target install
echo "=== Building fuzz target ==="
cmake -S "${SOURCE_DIR}" -B "${BUILD_DIR}" \
-DBUILD_FUZZING=ON -DBUILD_TESTING=OFF -DSTACK_USE_LIBFUZZER=ON \
-DDD_WRAPPER_DIR="${LIB_INSTALL_DIR}" \
-DLIB_INSTALL_DIR="${LIB_INSTALL_DIR}" \
-DEXTENSION_SUFFIX="${EXTENSION_SUFFIX}" \
-DNATIVE_EXTENSION_LOCATION="${NATIVE_EXTENSION_LOCATION}" \
Expand Down
15 changes: 8 additions & 7 deletions ddtrace/profiling/collector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDONT_COMPILE_ABSEIL)
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).
Expand Down Expand Up @@ -121,23 +122,23 @@ elseif(UNIX)
INSTALL_RPATH "$ORIGIN/../../internal/datadog/profiling")
endif()

# Link with libdd_wrapper if NATIVE_EXTENSION_LOCATION is defined
if(DEFINED NATIVE_EXTENSION_LOCATION)
# Find the libdd_wrapper shared library NATIVE_EXTENSION_LOCATION is ddtrace/internal/native, so
# ../datadog/profiling gets us to ddtrace/internal/datadog/profiling where libdd_wrapper is located
# Link with libdd_wrapper
if(DEFINED DD_WRAPPER_DIR)
set(_dd_wrapper_search_paths ${DD_WRAPPER_DIR})
find_library(
DD_WRAPPER_LIB
NAMES libdd_wrapper${EXTENSION_SUFFIX}
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../../internal/datadog/profiling
${NATIVE_EXTENSION_LOCATION}/../datadog/profiling
PATHS ${_dd_wrapper_search_paths}
NO_DEFAULT_PATH)

if(DD_WRAPPER_LIB)
message(STATUS "Found libdd_wrapper: ${DD_WRAPPER_LIB}")
target_link_libraries(${FULL_EXTENSION_NAME} PRIVATE ${DD_WRAPPER_LIB})
else()
message(WARNING "libdd_wrapper not found, extension may not link correctly")
message(FATAL_ERROR "libdd_wrapper not found in ${_dd_wrapper_search_paths}")
endif()
else()
message(FATAL_ERROR "DD_WRAPPER_DIR is not set")
endif()

# Enable allocator-hook reentry assertions in test builds. setup.py turns this on when
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,16 @@ def build_libdd_wrapper(self):
"""Build libdd_wrapper shared library as a dependency for profiling extensions."""
dd_wrapper_dir = DDUP_DIR.parent / "dd_wrapper"

# Determine output directory (profiling directory)
# Determine output directory (profiling directory).
# Store as self.wrapper_output_dir so _get_common_cmake_args can pass
# DD_WRAPPER_DIR to downstream extensions (ddup, stack, memalloc).
if IS_EDITABLE or getattr(self, "inplace", False):
wrapper_output_dir = Path(__file__).parent / "ddtrace" / "internal" / "datadog" / "profiling"
else:
wrapper_output_dir = (
Path(__file__).parent / Path(self.build_lib) / "ddtrace" / "internal" / "datadog" / "profiling"
)
self.wrapper_output_dir = wrapper_output_dir

wrapper_name = f"libdd_wrapper{self.suffix}"
wrapper_library = wrapper_output_dir / wrapper_name
Expand Down Expand Up @@ -876,6 +879,11 @@ def _get_common_cmake_args(self, source_dir, build_dir, output_dir, extension_na
f"-DNATIVE_EXTENSION_LOCATION={self.output_dir}",
f"-DRUST_GENERATED_HEADERS_DIR={CARGO_TARGET_DIR / 'include'}",
]
# Pass DD_WRAPPER_DIR for ddup/stack/memalloc cmake builds to find libdd_wrapper
if hasattr(self, "wrapper_output_dir"):
cmake_args += [
f"-DDD_WRAPPER_DIR={self.wrapper_output_dir}",
]

# Point FetchContent downloads at the persistent download cache so CMake
# doesn't re-fetch from GitHub (e.g. abseil) on every build invocation.
Expand Down
Loading