Replace Abseil extension with bazel_dep and eliminate source patching by mmorel-35 · Pull Request #243 · DataDog/dd-trace-cpp
This PR addresses the request to modernize the Abseil dependency management by replacing the custom Bazel extension with a standard bazel_dep and eliminating the need for source patching.
Problem
The current setup used a custom Bazel extension (extensions.bzl) to download Abseil via http_archive and apply a source patch (abseil.patch) to modify absl/base/options.h. The patch forced Abseil to not use C++ standard library types:
-#define ABSL_OPTION_USE_STD_OPTIONAL 2 +#define ABSL_OPTION_USE_STD_OPTIONAL 0
This approach had several downsides:
- Required maintaining a custom extension
- Needed source patching which is fragile and non-standard
- Used an older Abseil commit instead of tagged releases
Solution
1. Replaced extension with direct bazel_dep
# Before: Custom extension non_module_dependencies = use_extension("//:extensions.bzl", "non_module_dependencies") use_repo(non_module_dependencies, "com_google_absl") # After: Standard bazel_dep bazel_dep( name = "abseil-cpp", version = "20230125.3", repo_name = "com_google_absl", )
2. Replaced patch with compile-time configuration
Instead of patching source files, the same behavior is achieved through C++ preprocessor defines in .bazelrc.absl:
--cxxopt='-DABSL_OPTION_USE_STD_OPTIONAL=0' --cxxopt='-DABSL_OPTION_USE_STD_STRING_VIEW=0' --cxxopt='-DABSL_OPTION_USE_STD_VARIANT=0'
These defines are applied for all platforms (Linux, macOS, Windows) alongside the existing DD_USE_ABSEIL_FOR_ENVOY macro.