From 47b7cd388ebeb0e17f3d8ea1ffa7351e56c22887 Mon Sep 17 00:00:00 2001 From: owentou Date: Thu, 13 Jan 2022 12:56:54 +0800 Subject: [PATCH 1/5] Add `with_abseil` for bazel config Signed-off-by: owentou --- api/BUILD | 27 +++++++++++++++++++++++++++ bazel/repository.bzl | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/api/BUILD b/api/BUILD index 58610c654e..ca36943a3f 100644 --- a/api/BUILD +++ b/api/BUILD @@ -12,11 +12,38 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + package(default_visibility = ["//visibility:public"]) +bool_flag( + name = "with_abseil", + build_setting_default = False, +) + cc_library( name = "api", hdrs = glob(["include/**/*.h"]), + defines = select({ + ":with_external_abseil": ["HAVE_ABSEIL"], + "//conditions:default": [], + }), strip_include_prefix = "include", tags = ["api"], + deps = select({ + ":with_external_abseil": [ + "@com_google_absl//absl/base", + "@com_google_absl//absl/types:any", + "@com_google_absl//absl/types:variant", + "@com_google_absl//absl/types:span", + "@com_google_absl//absl/numeric:bits", + "@com_google_absl//absl/hash:city", + ], + "//conditions:default": [], + }), +) + +config_setting( + name = "with_external_abseil", + flag_values = {":with_abseil": "true"}, ) diff --git a/bazel/repository.bzl b/bazel/repository.bzl index eed7ebe157..815051c54f 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -28,6 +28,17 @@ def opentelemetry_cpp_deps(): ], ) + # Load abseil dependency(optional) + maybe( + http_archive, + name = "com_google_absl", + sha256 = "59b862f50e710277f8ede96f083a5bb8d7c9595376146838b9580be90374ee1f", + strip_prefix = "abseil-cpp-20210324.2", + urls = [ + "https://github.com/abseil/abseil-cpp/archive/20210324.2.tar.gz", + ], + ) + # Load gRPC dependency maybe( http_archive, From d66a29bfaff30c44224366a011cc18cd9341d94e Mon Sep 17 00:00:00 2001 From: owentou Date: Thu, 13 Jan 2022 14:20:56 +0800 Subject: [PATCH 2/5] Rename internal absl directory and add document of `with_abseil` Signed-off-by: owentou --- .github/workflows/ci.yml | 22 +++++++++++++++++++ .../nostd/{ => internal}/absl/.clang-format | 0 .../nostd/{ => internal}/absl/README.md | 0 .../{ => internal}/absl/base/attributes.h | 0 .../nostd/{ => internal}/absl/base/config.h | 0 .../absl/base/internal/identity.h | 0 .../absl/base/internal/inline_variable.h | 0 .../absl/base/internal/invoke.h | 0 .../nostd/{ => internal}/absl/base/macros.h | 0 .../{ => internal}/absl/base/optimization.h | 0 .../nostd/{ => internal}/absl/base/options.h | 0 .../{ => internal}/absl/base/policy_checks.h | 0 .../nostd/{ => internal}/absl/base/port.h | 0 .../{ => internal}/absl/meta/type_traits.h | 0 .../absl/types/bad_variant_access.h | 0 .../absl/types/internal/variant.h | 0 .../nostd/{ => internal}/absl/types/variant.h | 0 .../{ => internal}/absl/utility/utility.h | 0 api/include/opentelemetry/nostd/variant.h | 4 ++-- ci/do_ci.sh | 4 ++++ docs/dependencies.md | 2 +- examples/otlp/README.md | 4 +++- 22 files changed, 32 insertions(+), 4 deletions(-) rename api/include/opentelemetry/nostd/{ => internal}/absl/.clang-format (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/README.md (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/attributes.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/config.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/internal/identity.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/internal/inline_variable.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/internal/invoke.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/macros.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/optimization.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/options.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/policy_checks.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/base/port.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/meta/type_traits.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/types/bad_variant_access.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/types/internal/variant.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/types/variant.h (100%) rename api/include/opentelemetry/nostd/{ => internal}/absl/utility/utility.h (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6db5f15af..998fcb15ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -150,6 +150,28 @@ jobs: - name: run tests run: ./ci/do_ci.sh bazel.test + bazel_with_abseil: + name: Bazel with external abseil + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: Mount Bazel Cache + uses: actions/cache@v2 + env: + cache-name: bazel_cache + with: + path: /home/runner/.cache/bazel + key: bazel_test + - name: setup + run: | + sudo ./ci/setup_thrift.sh dependencies_only + 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 diff --git a/api/include/opentelemetry/nostd/absl/.clang-format b/api/include/opentelemetry/nostd/internal/absl/.clang-format similarity index 100% rename from api/include/opentelemetry/nostd/absl/.clang-format rename to api/include/opentelemetry/nostd/internal/absl/.clang-format diff --git a/api/include/opentelemetry/nostd/absl/README.md b/api/include/opentelemetry/nostd/internal/absl/README.md similarity index 100% rename from api/include/opentelemetry/nostd/absl/README.md rename to api/include/opentelemetry/nostd/internal/absl/README.md diff --git a/api/include/opentelemetry/nostd/absl/base/attributes.h b/api/include/opentelemetry/nostd/internal/absl/base/attributes.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/attributes.h rename to api/include/opentelemetry/nostd/internal/absl/base/attributes.h diff --git a/api/include/opentelemetry/nostd/absl/base/config.h b/api/include/opentelemetry/nostd/internal/absl/base/config.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/config.h rename to api/include/opentelemetry/nostd/internal/absl/base/config.h diff --git a/api/include/opentelemetry/nostd/absl/base/internal/identity.h b/api/include/opentelemetry/nostd/internal/absl/base/internal/identity.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/internal/identity.h rename to api/include/opentelemetry/nostd/internal/absl/base/internal/identity.h diff --git a/api/include/opentelemetry/nostd/absl/base/internal/inline_variable.h b/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/internal/inline_variable.h rename to api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h diff --git a/api/include/opentelemetry/nostd/absl/base/internal/invoke.h b/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/internal/invoke.h rename to api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h diff --git a/api/include/opentelemetry/nostd/absl/base/macros.h b/api/include/opentelemetry/nostd/internal/absl/base/macros.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/macros.h rename to api/include/opentelemetry/nostd/internal/absl/base/macros.h diff --git a/api/include/opentelemetry/nostd/absl/base/optimization.h b/api/include/opentelemetry/nostd/internal/absl/base/optimization.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/optimization.h rename to api/include/opentelemetry/nostd/internal/absl/base/optimization.h diff --git a/api/include/opentelemetry/nostd/absl/base/options.h b/api/include/opentelemetry/nostd/internal/absl/base/options.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/options.h rename to api/include/opentelemetry/nostd/internal/absl/base/options.h diff --git a/api/include/opentelemetry/nostd/absl/base/policy_checks.h b/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/policy_checks.h rename to api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h diff --git a/api/include/opentelemetry/nostd/absl/base/port.h b/api/include/opentelemetry/nostd/internal/absl/base/port.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/base/port.h rename to api/include/opentelemetry/nostd/internal/absl/base/port.h diff --git a/api/include/opentelemetry/nostd/absl/meta/type_traits.h b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/meta/type_traits.h rename to api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h diff --git a/api/include/opentelemetry/nostd/absl/types/bad_variant_access.h b/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/types/bad_variant_access.h rename to api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h diff --git a/api/include/opentelemetry/nostd/absl/types/internal/variant.h b/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/types/internal/variant.h rename to api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h diff --git a/api/include/opentelemetry/nostd/absl/types/variant.h b/api/include/opentelemetry/nostd/internal/absl/types/variant.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/types/variant.h rename to api/include/opentelemetry/nostd/internal/absl/types/variant.h diff --git a/api/include/opentelemetry/nostd/absl/utility/utility.h b/api/include/opentelemetry/nostd/internal/absl/utility/utility.h similarity index 100% rename from api/include/opentelemetry/nostd/absl/utility/utility.h rename to api/include/opentelemetry/nostd/internal/absl/utility/utility.h diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index e9ef66630e..b6b2326998 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -47,9 +47,9 @@ OPENTELEMETRY_END_NAMESPACE # endif # ifdef HAVE_ABSEIL -# include +# include "absl/types/variant.h" # else -# include "./absl/types/variant.h" +# include "./internal/absl/types/variant.h" # endif # ifdef _MSC_VER diff --git a/ci/do_ci.sh b/ci/do_ci.sh index cb2547d9a1..e005549bda 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -162,6 +162,10 @@ elif [[ "$1" == "bazel.test" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //... bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //... exit 0 +elif [[ "$1" == "bazel.with_abseil" ]]; then + bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS --//api:with_abseil=true //... + bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS --//api:with_abseil=true //... + exit 0 elif [[ "$1" == "bazel.macos.test" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_MACOS_OPTIONS //... bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_MACOS_TEST_OPTIONS //... diff --git a/docs/dependencies.md b/docs/dependencies.md index 49f6320180..1028bd56d4 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -18,7 +18,7 @@ Both these dependencies are listed here: - [API](https://github.com/open-telemetry/opentelemetry-cpp/tree/v1.0.0-rc1/api) & [SDK](https://github.com/open-telemetry/opentelemetry-cpp/tree/v1.0.0-rc1/sdk): - Uses Standard C++ library for latest features (std::string_view, std::variant, std::span, std::shared_ptr, std::unique_ptr) with C++14/17/20 compiler if `WITH_STL` cmake option is enabled or `HAVE_CPP_STDLIB` macro is defined. License: `GNU General Public License` - For C++11/14/17 compilers, fallback to gsl::span if [GSL C++ library](https://github.com/microsoft/GSL) is installed. License: `MIT License` - - Uses Abseil C++ Library for `absl::variant` as default `nostd::variant` if `WITH_ABSEIL` cmake option is enabled. License: `Apache License 2.0` + - 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` - [OTLP/HTTP+JSON](https://github.com/open-telemetry/opentelemetry-cpp/tree/v1.0.0-rc1/exporters/otlp) exporter: - [protobuf](https://github.com/protocolbuffers/protobuf): Library to serialize structured data. diff --git a/examples/otlp/README.md b/examples/otlp/README.md index 92f96e96bf..53978ce764 100644 --- a/examples/otlp/README.md +++ b/examples/otlp/README.md @@ -57,7 +57,9 @@ 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. +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. 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` From 3a8157649c8ab0fb147252ce65ecce8ae4046b9c Mon Sep 17 00:00:00 2001 From: owentou Date: Thu, 13 Jan 2022 14:34:28 +0800 Subject: [PATCH 3/5] Add changelog, fix style Signed-off-by: owentou --- CHANGELOG.md | 1 + examples/otlp/README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae67939cd..e9d33a21fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Increment the: * [SDK] Add LogLevel to internal_log ([#1147](https://github.com/open-telemetry/opentelemetry-cpp/pull/1147)) * [API/SDK] Logger: Propagating resources through LoggerProvider ([#1154](https://github.com/open-telemetry/opentelemetry-cpp/pull/1154)) +* [API]: Allow to use external abseil for bazel targets ([#1172](https://github.com/open-telemetry/opentelemetry-cpp/pull/1172)) ## [1.1.1] 2021-12-20 diff --git a/examples/otlp/README.md b/examples/otlp/README.md index 53978ce764..91f86f8f50 100644 --- a/examples/otlp/README.md +++ b/examples/otlp/README.md @@ -57,7 +57,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 +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. From e429e22328cb79803f1df0856bf4d6ed660647d6 Mon Sep 17 00:00:00 2001 From: owentou Date: Fri, 14 Jan 2022 10:35:23 +0800 Subject: [PATCH 4/5] Use the same abseil as it in ci script. Signed-off-by: owentou --- bazel/repository.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 815051c54f..2b00ba18f6 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -32,10 +32,10 @@ def opentelemetry_cpp_deps(): maybe( http_archive, name = "com_google_absl", - sha256 = "59b862f50e710277f8ede96f083a5bb8d7c9595376146838b9580be90374ee1f", - strip_prefix = "abseil-cpp-20210324.2", + sha256 = "dd7db6815204c2a62a2160e32c55e97113b0a0178b2f090d6bab5ce36111db4b", + strip_prefix = "abseil-cpp-20210324.0", urls = [ - "https://github.com/abseil/abseil-cpp/archive/20210324.2.tar.gz", + "https://github.com/abseil/abseil-cpp/archive/20210324.0.tar.gz", ], ) From a95ac25aaaeda106dc603af7a8b71a14bbf99ba4 Mon Sep 17 00:00:00 2001 From: owentou Date: Fri, 14 Jan 2022 16:28:50 +0800 Subject: [PATCH 5/5] Remove useless dependencies. Signed-off-by: owentou --- api/BUILD | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api/BUILD b/api/BUILD index ca36943a3f..80ff5ad926 100644 --- a/api/BUILD +++ b/api/BUILD @@ -33,11 +33,7 @@ cc_library( deps = select({ ":with_external_abseil": [ "@com_google_absl//absl/base", - "@com_google_absl//absl/types:any", "@com_google_absl//absl/types:variant", - "@com_google_absl//absl/types:span", - "@com_google_absl//absl/numeric:bits", - "@com_google_absl//absl/hash:city", ], "//conditions:default": [], }),