feat: Build each SDK module as its own CMake target #448
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #448"
general
weight: 0.35
fuzzybinary
refs: RUM-20125
This PR updates our CMake configuration to make the boundaries between the SDK's source modules more explicit. In the process, it moves almost every file within
src/, and it also makes it possible to selectively disable individual modules at configure-time.As a result of this PR:
## The final build artifact is still a single library
As before, whether the SDK is built as a static or shared library, it still produces a single library as an artifact, e.g.
libddsdkcpp.aorlibddsdkcpp.so.As of this PR, it is possible to disable specific modules. For example, if a customer doesn't use the logging feature and wants to customize their build to not include any logging code whatsoever, they could configure their SDK build with
DD_MODULE_LOGGING=OFF. The result would be addsdkcpplibrary that does not declare any logging APIs or include any implementation-layer logging code.To reiterate: a customer that compiles with
DD_MODULE_LOGGING=OFFwould still just getlibddsdkcpp.aor the like; that file would just have less code in it, and they couldn't call logging APIs.This is not the same thing as "modularizing" the build in the sense of producing separate libraries, e.g. having separate files for
ddsdkcpp-core.dllvs.ddsdkcpp-logging.dlletc., such that applications could selectively load only certain features from the same build. At this juncture, we are not attempting to split the SDK's _build artifacts_ along module or feature lines. There is still a single canonical set of modules that we enable when we publish precompiled releases, and no two distinctly-configured SDK builds should ever be deemed binary-compatible.## Making modules an explicitly-defined part of the build
This PR adds a new CMake utility,
modules.cmake, which defines this function:Example usage for the
loggingmodule:As a result of
dd_add_module(logging ...), when we build code that's declared within thisloggingmodule, we can only include headers fromcoreor its dependencies (i.e.types).Additionally, this module declaration will only be active when
DD_MODULE_LOGGING=ON(it's on by default). In that case, and only in that case:OBJECTtarget calledddsdkcpp_loggingwill be created, and our compiled logging code will be linked into the final library- In static builds, these targets also carry their link dependencies to consumers of
Datadog::sdk, e.g.ddsdkcpp_corecarrieslibcurlinclude-c/datadog/logging.handinclude-cpp/datadog/logging.hppwill be included in packaged builds## A note about "umbrella headers"
As always, consumers of the library can pull in specific public API headers directly:
For convenience, we also provide a single-file "umbrella" header that pulls in the entirety of the C or C++ API:
These were previously static files. As of this PR, since modules may be enabled or disabled at build-time, we now use CMake templates to generate these headers, such that they only reference the headers whose modules were part of the build.
These files (
datadog.handdatadog.hpp) are generated at configure-time, so they're always present in CMake builds. There is no change to these files in our published builds: the CMake install process will output equivalent versions to the same paths as always.## How this PR rearranges source files
Previously, we had:
src/: all library source, with loosely-enforced module conventions-
datadog/c/: implementation of all C APIs-
datadog/cpp/: implementation of all C++ APIs-
datadog/impl/: implementation of all internal SDK code, split by module:-
core/-
logging/-
...-
CMakeLists.txt: one big config file for the whole libraryNow, we have:
src/: directories for each module, each with its ownc/cpp/implsplit-
core/-
logging/-
datadog/c/: implementation of the C logging API-
datadog/cpp/: implementation of the C++ logging API-
datadog/impl/logging/: implementation of the Logging feature-
CMakeLists.txt: module-specific config defining how the logging feature is built-
...-
CMakeLists.txt: top-level config file that adds the subdir for each enabled moduleEach module is now self-contained in its own top-level directory, with each public API header being associated with a particular module.
You'll notice that we now have a bunch of nested
datadog/subdirectories, and each module has a subdirectory that repeats the module name (e.g.datadog/impl/logging/->logging/datadog/impl/logging/). While this nesting may feel a bit awkward, it helps to maintain good cpp-library-include-path hygiene, and it ensures that this PR does _not_ change our include paths in any way.These explicit, unambiguous include paths are worthwhile because:
datadog/typesvscorevsloggingetc.)### Practical example
As an example: the declaration of
datadog::impl::RumSessionScopeis now versioned at a different path in the repo:src/datadog/impl/rum/scopes/session.hppsrc/rum/datadog/impl/rum/scopes/session.hpp...but internal code that needs this type still includes it the exact same way:
And if you put that same include directive into a source file in the
loggingmodule, for example: it would fail to compile, sinceloggingdoes not declarerumas a dependency, and thereforesrc/rum/is not in the include path for those files.### network_instrumentation headers
Since every public header is now associated with a module, this PR has to choose where
network_instrumentation.{h,hpp}belong.These headers currently declare
FirstPartyHosts, and they will eventually declare the interface that cross-platform SDKs (as well as library consumers) will use to instrument HTTP requests for distributed tracing.This code is intended to be usable even without
coreSDK functionality, so this PR assignsnetwork_instrumentationheaders to thetypesmodule.## Crashpad handler configuration
The Crashpad handler still lists its dd-sdk-cpp sources by hand in
handler/BUILD.gn, sodatadog.patchis regenerated to point those paths atsrc/types/andsrc/crash_processing/. RUM-20124 will replace the hardcoded list of source files with a list that's automatically generated from the module targets' source lists.[RUM-20124]: https://datadoghq.atlassian.net/browse/RUM-20124?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ