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/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/api/BUILD b/api/BUILD index 58610c654e..80ff5ad926 100644 --- a/api/BUILD +++ b/api/BUILD @@ -12,11 +12,34 @@ # 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:variant", + ], + "//conditions:default": [], + }), +) + +config_setting( + name = "with_external_abseil", + flag_values = {":with_abseil": "true"}, ) 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/bazel/repository.bzl b/bazel/repository.bzl index eed7ebe157..2b00ba18f6 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 = "dd7db6815204c2a62a2160e32c55e97113b0a0178b2f090d6bab5ce36111db4b", + strip_prefix = "abseil-cpp-20210324.0", + urls = [ + "https://github.com/abseil/abseil-cpp/archive/20210324.0.tar.gz", + ], + ) + # Load gRPC dependency maybe( http_archive, 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..91f86f8f50 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`