← Back to Pull requests

feat: Build each SDK module as its own CMake target #448

Closed
unknown closed this pull request without merging on Nov 18, 2026 21:02 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 00:09 UTC
Author

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 SDK now enforces module boundaries, such that it's no longer possible to accidentally add cross-module includes that violate the established architecture

  • Feature-specific build configuration details (like which profiler backend or crash handler we use) are now more cleanly encapsulated within the relevant source module

  • There are cases where we need to support compiling a subset of modules with a different toolchain: it's now much easier to do so

  • We can exclude experimental/unstable/preview features from the build by default, if desired

  • Customers who want to explicitly strip unused features out of their build can do so
  • ## 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.a or libddsdkcpp.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 a ddsdkcpp library that does not declare any logging APIs or include any implementation-layer logging code.

    To reiterate: a customer that compiles with DD_MODULE_LOGGING=OFF would still just get libddsdkcpp.a or 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.dll vs. ddsdkcpp-logging.dll etc., 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:

    dd_add_module(<name>
        [DEPENDS <module>...]
        [PUBLIC_HEADERS <header>...]
        SOURCES <file>...
    )
    

    Example usage for the logging module:

    dd_add_module(logging
        DEPENDS core
        PUBLIC_HEADERS logging
        SOURCES
            datadog/c/logging.cpp
            datadog/cpp/logging.cpp
            datadog/impl/logging/event_generation.cpp
            datadog/impl/logging/logger.cpp
            datadog/impl/logging/logging.cpp
            datadog/impl/logging/tags.cpp
    )
    

    As a result of dd_add_module(logging ...), when we build code that's declared within this logging module, we can only include headers from core or 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:

  • The source files declared in the module will be compiled

  • A CMake OBJECT target called ddsdkcpp_logging will 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_core carries libcurl
  • The public headers include-c/datadog/logging.h and include-cpp/datadog/logging.hpp will be included in packaged builds

  • The "umbrella headers" (see note below) will include those public headers
  • ## A note about "umbrella headers"

    As always, consumers of the library can pull in specific public API headers directly:

    #include "datadog/logging.h"   // .h corresponds to C API headers
    #include "datadog/logging.hpp" // .hpp corresponds to C++ API headers
    

    For convenience, we also provide a single-file "umbrella" header that pulls in the entirety of the C or C++ API:

    #include "datadog.h"   // C API
    #include "datadog.hpp" // 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.h and datadog.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 library

    Now, we have:

  • src/: directories for each module, each with its own c/cpp/impl split

  • - 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 module

    Each 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:

  • They "namespace" all SDK includes with datadog/

  • They clearly distinguish API-layer from implementation-layer includes

  • They clearly distinguish includes from different modules (types vs core vs logging etc.)
  • ### Practical example

    As an example: the declaration of datadog::impl::RumSessionScope is now versioned at a different path in the repo:

  • old: src/datadog/impl/rum/scopes/session.hpp

  • new: src/rum/datadog/impl/rum/scopes/session.hpp
  • ...but internal code that needs this type still includes it the exact same way:

    #include "datadog/impl/rum/scopes/session.hpp"
    

    And if you put that same include directive into a source file in the logging module, for example: it would fail to compile, since logging does not declare rum as a dependency, and therefore src/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 core SDK functionality, so this PR assigns network_instrumentation headers to the types module.

    ## Crashpad handler configuration

    The Crashpad handler still lists its dd-sdk-cpp sources by hand in handler/BUILD.gn, so datadog.patch is regenerated to point those paths at src/types/ and src/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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: fuzzybinary Review duration: 1252m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%