diff --git a/.bazelrc b/.bazelrc index 01a3b4c7bb..fc170b0e8b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -4,12 +4,18 @@ # bazel configurations for running tests under sanitizers. # Based on https://github.com/bazelment/trunk/blob/master/tools/bazel.rc +# TODO: Remove once support is added, avoid MODULE.bazel creation for now +common --enable_bzlmod=false + # Enable automatic configs based on platform common --enable_platform_specific_config # Needed by gRPC to build on some platforms. build --copt -DGRPC_BAZEL_BUILD +# Workaround abseil libraries missing symbols +build:windows --dynamic_mode=off + # Set minimum supported C++ version build:macos --host_cxxopt=-std=c++14 --cxxopt=-std=c++14 build:linux --host_cxxopt=-std=c++14 --cxxopt=-std=c++14 diff --git a/.bazelversion b/.bazelversion index ade65226e0..21c8c7b46b 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.4.1 +7.1.1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcdf4f0ed8..5834ca2fd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -558,27 +558,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 diff --git a/api/BUILD b/api/BUILD index fa4da45a66..2eca1de986 100644 --- a/api/BUILD +++ b/api/BUILD @@ -1,15 +1,10 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") package(default_visibility = ["//visibility:public"]) -bool_flag( - name = "with_abseil", - build_setting_default = False, -) - CPP_STDLIBS = [ "none", "best", @@ -28,10 +23,7 @@ string_flag( cc_library( name = "api", hdrs = glob(["include/**/*.h"]), - defines = select({ - ":with_external_abseil": ["HAVE_ABSEIL"], - "//conditions:default": [], - }) + select({ + defines = ["HAVE_ABSEIL"] + select({ ":set_cxx_stdlib_none": [], ### automatic selection ":set_cxx_stdlib_best": ["OPENTELEMETRY_STL_VERSION=(__cplusplus/100)"], @@ -46,19 +38,11 @@ cc_library( }), 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( diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index cdd1ed7cf4..eae9f6b8c0 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -1,17 +1,11 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -DEFAULT_WIN_COPTS = [ -] - # gcc and clang, assumed to be used on this platform DEFAULT_NOWIN_COPTS = [ "-fvisibility=default", ] -HIDDEN_WIN_COPTS = [ -] - # gcc and clang, assumed to be used on this platform HIDDEN_NOWIN_COPTS = [ "-fvisibility=hidden", @@ -26,6 +20,10 @@ cc_library( "component_a.h", ], linkstatic = True, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -40,6 +38,10 @@ cc_library( "component_b.h", ], linkstatic = True, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -53,11 +55,12 @@ cc_library( hdrs = [ "component_c.h", ], - copts = select({ - "//bazel:windows": DEFAULT_WIN_COPTS, - "//conditions:default": DEFAULT_NOWIN_COPTS, - }), + copts = DEFAULT_NOWIN_COPTS, linkstatic = False, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -71,11 +74,12 @@ cc_library( hdrs = [ "component_d.h", ], - copts = select({ - "//bazel:windows": HIDDEN_WIN_COPTS, - "//conditions:default": HIDDEN_NOWIN_COPTS, - }), + copts = HIDDEN_NOWIN_COPTS, linkstatic = False, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -89,11 +93,12 @@ cc_library( hdrs = [ "component_e.h", ], - copts = select({ - "//bazel:windows": DEFAULT_WIN_COPTS, - "//conditions:default": DEFAULT_NOWIN_COPTS, - }), + copts = DEFAULT_NOWIN_COPTS, linkstatic = False, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -107,11 +112,12 @@ cc_library( hdrs = [ "component_f.h", ], - copts = select({ - "//bazel:windows": HIDDEN_WIN_COPTS, - "//conditions:default": HIDDEN_NOWIN_COPTS, - }), + copts = HIDDEN_NOWIN_COPTS, linkstatic = False, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -123,11 +129,12 @@ cc_binary( srcs = [ "component_g.cc", ], - copts = select({ - "//bazel:windows": DEFAULT_WIN_COPTS, - "//conditions:default": DEFAULT_NOWIN_COPTS, - }), + copts = DEFAULT_NOWIN_COPTS, linkshared = True, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -139,11 +146,12 @@ cc_binary( srcs = [ "component_h.cc", ], - copts = select({ - "//bazel:windows": HIDDEN_WIN_COPTS, - "//conditions:default": HIDDEN_NOWIN_COPTS, - }), + copts = HIDDEN_NOWIN_COPTS, linkshared = True, + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "//api", ], @@ -176,6 +184,10 @@ cc_test( "api", "test", ], + target_compatible_with = select({ + "//bazel:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), deps = [ "component_a", "component_b", diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 9ba8ad5388..bac1e45b34 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -1,17 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") - -_ALL_CONTENT = """ -filegroup( - name = "all_srcs", - srcs = glob(["**"]), - visibility = ["//visibility:public"], -) -""" +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") # # MAINTAINER @@ -55,54 +46,40 @@ def opentelemetry_cpp_deps(): # Load abseil dependency(optional) maybe( - # - # Important note: - # - # The bazel build uses abseil-cpp-20230802.2 here, - # while CMake uses more recent versions. - # - # bazel with abseil-cpp-20240116.2 : build failures in CI - # bazel with abseil-cpp-20240116.1 : build failures in CI - # - # TODO: Fix issue #2619 - # http_archive, name = "com_google_absl", - sha256 = "7c11539617af1f332f0854a6fb21e296a1b29c27d03f23c7b49d4adefcd102cc", - strip_prefix = "abseil-cpp-20230802.2", + sha256 = "733726b8c3a6d39a4120d7e45ea8b41a434cdacde401cba500f14236c49b39dc", + strip_prefix = "abseil-cpp-20240116.2", urls = [ - "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.2.tar.gz", + "https://github.com/abseil/abseil-cpp/archive/refs/tags/20240116.2.tar.gz", ], ) - # Load gRPC dependency + # gRPC transitively depends on apple_support and rules_apple at older + # versions. Bazel 7.x requires newer versions of these rules. By loading + # them before grpc, these newer versions are preferrred. maybe( http_archive, - name = "com_github_grpc_grpc_legacy", - sha256 = "024118069912358e60722a2b7e507e9c3b51eeaeee06e2dd9d95d9c16f6639ec", - strip_prefix = "grpc-1.39.1", - urls = [ - "https://github.com/grpc/grpc/archive/v1.39.1.tar.gz", - ], + name = "build_bazel_apple_support", + sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80", + url = "https://github.com/bazelbuild/apple_support/releases/download/1.15.1/apple_support.1.15.1.tar.gz", ) maybe( http_archive, - name = "com_github_grpc_grpc_latest11", - sha256 = "e266aa0d9d9cddb876484a370b94f468248594a96ca0b6f87c21f969db2b8c5b", - strip_prefix = "grpc-1.46.4", - urls = [ - "https://github.com/grpc/grpc/archive/v1.46.4.tar.gz", - ], + name = "build_bazel_rules_apple", + sha256 = "b4df908ec14868369021182ab191dbd1f40830c9b300650d5dc389e0b9266c8d", + url = "https://github.com/bazelbuild/rules_apple/releases/download/3.5.1/rules_apple.3.5.1.tar.gz", ) + # Load gRPC dependency maybe( http_archive, name = "com_github_grpc_grpc", - sha256 = "cdeb805385fba23242bf87073e68d590c446751e09089f26e5e0b3f655b0f089", - strip_prefix = "grpc-1.49.2", + sha256 = "f40bde4ce2f31760f65dc49a2f50876f59077026494e67dccf23992548b1b04f", + strip_prefix = "grpc-1.62.0", urls = [ - "https://github.com/grpc/grpc/archive/v1.49.2.tar.gz", + "https://github.com/grpc/grpc/archive/refs/tags/v1.62.0.tar.gz", ], ) @@ -144,10 +121,10 @@ def opentelemetry_cpp_deps(): maybe( http_archive, name = "platforms", - sha256 = "5308fc1d8865406a49427ba24a9ab53087f17f5266a7aabbfc28823f3916e1ca", + sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", ], ) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index f6a12e3877..62e174854e 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -10,6 +10,8 @@ $nproc = (Get-ComputerInfo).CsNumberOfLogicalProcessors $SRC_DIR = (Get-Item -Path ".\").FullName +# Workaround https://github.com/bazelbuild/bazel/issues/18683 +$BAZEL_STARTUP_OPTIONS = "--output_base=C:\Out" $BAZEL_OPTIONS = "--copt=-DENABLE_ASYNC_EXPORT" $BAZEL_TEST_OPTIONS = "$BAZEL_OPTIONS --test_output=errors" @@ -27,7 +29,7 @@ $VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg" switch ($action) { "bazel.build" { - bazel build $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //... + bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //... $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 2d089ef21e..7855ed4175 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -425,10 +425,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}" @@ -507,7 +503,7 @@ elif [[ "$1" == "bazel.tsan" ]]; then exit 0 elif [[ "$1" == "bazel.valgrind" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC //... - bazel $BAZEL_STARTUP_OPTIONS test --run_under="/usr/bin/valgrind --leak-check=full --error-exitcode=1 --suppressions=\"${SRC_DIR}/ci/valgrind-suppressions\"" $BAZEL_TEST_OPTIONS_ASYNC //... + bazel $BAZEL_STARTUP_OPTIONS test --run_under="/usr/bin/valgrind --leak-check=full --error-exitcode=1 --errors-for-leak-kinds=definite --suppressions=\"${SRC_DIR}/ci/valgrind-suppressions\"" $BAZEL_TEST_OPTIONS_ASYNC //... exit 0 elif [[ "$1" == "bazel.e2e" ]]; then cd examples/e2e diff --git a/docs/dependencies.md b/docs/dependencies.md index dd495f4888..6375ec79e2 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -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` + `WITH_ABSEIL` cmake option (always enabled with bazel) + License: `Apache License 2.0` - [OTLP/HTTP+JSON](/exporters/otlp) exporter: