Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Upgrade to abseil 20240116.1 (CMake only) #2599

Merged
merged 12 commits into from
Mar 28, 2024
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -565,27 +565,6 @@ jobs:
- name: run tests
run: ./ci/do_ci.sh bazel.with_async_export.test

bazel_with_abseil:
name: Bazel with external abseil
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Mount Bazel Cache
uses: actions/cache@v4
env:
cache-name: bazel_cache
with:
path: /home/runner/.cache/bazel
key: bazel_test
- name: setup
run: |
sudo ./ci/setup_ci_environment.sh
sudo ./ci/install_bazelisk.sh
- name: run tests
run: ./ci/do_ci.sh bazel.with_abseil

bazel_valgrind:
name: Bazel valgrind
runs-on: ubuntu-latest
Expand Down
73 changes: 40 additions & 33 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")

package(default_visibility = ["//visibility:public"])

bool_flag(
name = "with_abseil",
build_setting_default = False,
)
#
# Important note
# ==============
#
# The boolean flag "with_abseil" is no longer supported,
# because with_abseil is no longer optional.
#
# Unlike CMake, the bazel build has no option to only select a few exporters,
# so it builds all the exporters available.
#
# The OTLP exporter depends on protobuf,
# and protobuf has a mandatory dependency on abseil starting
# with protobuf 3.22
#
# See in CMake:
# "Protobuf 3.22 or upper require abseil-cpp(Recommended version: 20230125 or upper)"
#
# Since building with abseil is mandatory with bazel,
# the bazel option "with_abseil" is now removed.
#

CPP_STDLIBS = [
"none",
Expand All @@ -25,40 +41,31 @@ string_flag(
values = CPP_STDLIBS,
)

_DEFINES_CXX_STDLIB = select({
":set_cxx_stdlib_none": [],
### automatic selection
":set_cxx_stdlib_best": ["OPENTELEMETRY_STL_VERSION=(__cplusplus/100)"],
# See https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
":set_cxx_stdlib_best_and_msvc": ["OPENTELEMETRY_STL_VERSION=(_MSVC_LANG/100)"],
### manual selection
":set_cxx_stdlib_2014": ["OPENTELEMETRY_STL_VERSION=2014"],
":set_cxx_stdlib_2017": ["OPENTELEMETRY_STL_VERSION=2017"],
":set_cxx_stdlib_2020": ["OPENTELEMETRY_STL_VERSION=2020"],
":set_cxx_stdlib_2023": ["OPENTELEMETRY_STL_VERSION=2023"],
"//conditions:default": [],
})

cc_library(
name = "api",
hdrs = glob(["include/**/*.h"]),
defines = select({
":with_external_abseil": ["HAVE_ABSEIL"],
"//conditions:default": [],
}) + select({
":set_cxx_stdlib_none": [],
### automatic selection
":set_cxx_stdlib_best": ["OPENTELEMETRY_STL_VERSION=(__cplusplus/100)"],
# See https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
":set_cxx_stdlib_best_and_msvc": ["OPENTELEMETRY_STL_VERSION=(_MSVC_LANG/100)"],
### manual selection
":set_cxx_stdlib_2014": ["OPENTELEMETRY_STL_VERSION=2014"],
":set_cxx_stdlib_2017": ["OPENTELEMETRY_STL_VERSION=2017"],
":set_cxx_stdlib_2020": ["OPENTELEMETRY_STL_VERSION=2020"],
":set_cxx_stdlib_2023": ["OPENTELEMETRY_STL_VERSION=2023"],
"//conditions:default": [],
}),
defines = ["OPENTELEMETRY_HAVE_ABSEIL"] + _DEFINES_CXX_STDLIB,
strip_include_prefix = "include",
tags = ["api"],
deps = select({
":with_external_abseil": [
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:variant",
],
"//conditions:default": [],
}),
)

config_setting(
name = "with_external_abseil",
flag_values = {":with_abseil": "true"},
deps = [
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:variant",
],
)

[config_setting(
Expand Down
13 changes: 10 additions & 3 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ if(WITH_NO_DEPRECATED_CODE)
endif()

if(WITH_ABSEIL)
target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL)
target_compile_definitions(opentelemetry_api
INTERFACE OPENTELEMETRY_HAVE_ABSEIL)
target_link_libraries(
opentelemetry_api INTERFACE absl::bad_variant_access absl::any absl::base
absl::bits absl::city)
list(APPEND TARGET_DEPS "absl_bad_variant_access" "absl_any absl_base"
"absl_bits" "absl_city")
list(
APPEND
TARGET_DEPS
"absl_bad_variant_access"
"absl_any"
"absl_base"
"absl_bits"
"absl_city")
endif()

if(WITH_STL STREQUAL "OFF")
Expand Down
6 changes: 3 additions & 3 deletions api/include/opentelemetry/nostd/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#if !defined(OPENTELEMETRY_HAVE_STD_VARIANT)

# ifndef HAVE_ABSEIL
# ifndef OPENTELEMETRY_HAVE_ABSEIL
// We use a LOCAL snapshot of Abseil that is known to compile with Visual Studio 2015.
// Header-only. Without compiling the actual Abseil binary. As Abseil moves on to new
// toolchains, it may drop support for Visual Studio 2015 in future versions.
Expand Down Expand Up @@ -51,7 +51,7 @@ OPENTELEMETRY_END_NAMESPACE
# pragma warning(disable : 4127) // conditional expression is constant
# endif

# ifdef HAVE_ABSEIL
# ifdef OPENTELEMETRY_HAVE_ABSEIL
# include "absl/types/variant.h"
# else
# include "./internal/absl/types/variant.h"
Expand All @@ -64,7 +64,7 @@ OPENTELEMETRY_END_NAMESPACE
OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
{
# ifdef HAVE_ABSEIL
# ifdef OPENTELEMETRY_HAVE_ABSEIL
using absl::bad_variant_access;
# endif
using absl::get;
Expand Down
6 changes: 3 additions & 3 deletions bazel/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def opentelemetry_cpp_deps():
maybe(
http_archive,
name = "com_google_absl",
sha256 = "91ac87d30cc6d79f9ab974c51874a704de9c2647c40f6932597329a282217ba8",
strip_prefix = "abseil-cpp-20220623.1",
sha256 = "3c743204df78366ad2eaf236d6631d83f6bc928d1705dd0000b872e53b73dc6a",
strip_prefix = "abseil-cpp-20240116.1",
urls = [
"https://github.com/abseil/abseil-cpp/archive/refs/tags/20220623.1.tar.gz",
"https://github.com/abseil/abseil-cpp/archive/refs/tags/20240116.1.tar.gz",
],
)

Expand Down
6 changes: 1 addition & 5 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,6 @@ elif [[ "$1" == "cmake.install.test" ]]; then
make -j $(nproc)
sudo make install
exit 0
elif [[ "$1" == "bazel.with_abseil" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC --//api:with_abseil=true //...
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS_ASYNC --//api:with_abseil=true //...
exit 0
elif [[ "$1" == "cmake.test_example_plugin" ]]; then
# Build the plugin
cd "${BUILD_DIR}"
Expand Down Expand Up @@ -529,7 +525,7 @@ elif [[ "$1" == "code.coverage" ]]; then
exit 0
elif [[ "$1" == "third_party.tags" ]]; then
echo "gRPC=v1.49.2" > third_party_release
echo "abseil=20220623.1" >> third_party_release
echo "abseil=20240116.1" >> third_party_release
git submodule foreach --quiet 'echo "$name=$(git describe --tags HEAD)"' | sed 's:.*/::' >> third_party_release
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion ci/install_abseil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

set -ex
export DEBIAN_FRONTEND=noninteractive
[ -z "${ABSEIL_CPP_VERSION}" ] && export ABSEIL_CPP_VERSION="20220623.1"
[ -z "${ABSEIL_CPP_VERSION}" ] && export ABSEIL_CPP_VERSION="20240116.1"

BUILD_DIR=/tmp/
INSTALL_DIR=/usr/local/
Expand Down
6 changes: 2 additions & 4 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ Both these dependencies are listed here:
`OPENTELEMETRY_OPTION_USE_STD_SPAN=0` to indicate nostd:span will always
not be a alias for std::span.
- Uses Abseil C++ Library for `absl::variant` as default `nostd::variant` if
`WITH_ABSEIL` cmake option or
`--@io_opentelemetry_cpp//api:with_abseil=true` (aka
`--//api:with_abseil=true`) bazel option is enabled. License: `Apache
License 2.0`
using cmake option `WITH_ABSEIL`, or if using bazel.
License: `Apache License 2.0`

- [OTLP/HTTP+JSON](/exporters/otlp)
exporter:
Expand Down
3 changes: 1 addition & 2 deletions examples/otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ gRPC internally uses a different version of Abseil than OpenTelemetry C++ SDK.
One option to optimize your code is to build the SDK with system-provided
Abseil library. If you are using CMake, then `-DWITH_ABSEIL=ON` may be passed
during the build of SDK to reuse the same Abseil library as gRPC. If you are
using Bazel, then `--@io_opentelemetry_cpp/api:with_abseil=true` may be passed
to reuse your Abseil library in your project.
using Bazel, the build already depends on an Abseil library in your project.

If you do not want to pursue the above option, and in case if you run into
conflict between Abseil library and OpenTelemetry C++ `absl::variant`
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/common/base64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <iostream>
#include <limits>

#if defined(HAVE_ABSEIL)
#if defined(OPENTELEMETRY_HAVE_ABSEIL)
# include "absl/strings/escaping.h"
#endif

Expand All @@ -21,7 +21,7 @@ namespace sdk
{
namespace common
{
#if !defined(HAVE_ABSEIL)
#if !defined(OPENTELEMETRY_HAVE_ABSEIL)
namespace
{
using Base64EscapeChars = const unsigned char[64];
Expand Down Expand Up @@ -298,7 +298,7 @@ OPENTELEMETRY_EXPORT void Base64Escape(opentelemetry::nostd::string_view src, st
return;
}

#if defined(HAVE_ABSEIL)
#if defined(OPENTELEMETRY_HAVE_ABSEIL)
absl::Base64Escape(absl::string_view{src.data(), src.size()}, dest);
#else
Base64EscapeInternal(*dest, reinterpret_cast<const unsigned char *>(src.data()), src.size(),
Expand All @@ -321,7 +321,7 @@ OPENTELEMETRY_EXPORT bool Base64Unescape(opentelemetry::nostd::string_view src,
return false;
}

#if defined(HAVE_ABSEIL)
#if defined(OPENTELEMETRY_HAVE_ABSEIL)
return absl::Base64Unescape(absl::string_view{src.data(), src.size()}, dest);
#else
if (src.empty())
Expand Down
2 changes: 1 addition & 1 deletion third_party_release
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#

gRPC=v1.49.2
abseil=20220623.1
abseil=20240116.1
benchmark=v1.8.3
googletest=1.14.0
ms-gsl=v3.1.0-67-g6f45293
Expand Down
Loading