This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch fix/cpp-ci-bazel-and-coverage
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git

commit 6358349d44c688f52da09c56d86700864cf6aa9b
Author: terrance.lzm <[email protected]>
AuthorDate: Mon Jun 8 18:50:08 2026 +0800

    [C++] Upgrade Bazel 5.2.0 to 6.6.0, add Bazel CI, migrate coverage to CMake
    
    - Upgrade Bazel from EOL 5.2.0 to 6.6.0 (latest maintained Bazel 6 LTS).
      Bazel 8 is incompatible with gRPC 1.46.3's dependency stack due to
      autoloading conflicts with protobuf 3.20.1.
    - Add `--noincompatible_use_platforms_repo_for_constraints` for gRPC's
      upb which still references removed @bazel_tools//platforms.
    - Remove unused RBE config (buildbuddy) and hedron compile commands
      from WORKSPACE and .bazelrc.
    - Remove `--host_force_python=PY3` flag (incompatible with Bazel 6).
    - Add Bazel build+test CI job for 3 platforms (ubuntu-22.04, macos-latest,
      windows-2022) alongside existing CMake CI.
    - Migrate CPP Coverage from broken Bazel-based coverage to CMake + lcov,
      fixing failures caused by Abseil 20211102.0 vs GCC 14 incompatibility.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .github/workflows/cpp_build.yml    | 33 +++++++++++++++++++--
 .github/workflows/cpp_coverage.yml | 59 +++++++++++++++++++++++++++++++++-----
 cpp/.bazelrc                       | 24 +++-------------
 cpp/.bazelversion                  |  2 +-
 cpp/WORKSPACE                      | 39 +------------------------
 5 files changed, 89 insertions(+), 68 deletions(-)

diff --git a/.github/workflows/cpp_build.yml b/.github/workflows/cpp_build.yml
index 7b3e7a88..e47287cc 100644
--- a/.github/workflows/cpp_build.yml
+++ b/.github/workflows/cpp_build.yml
@@ -2,8 +2,8 @@ name: CPP Build
 on:
   workflow_call:
 jobs:
-  build:
-    name: "${{ matrix.os }}"
+  cmake-build:
+    name: "CMake ${{ matrix.os }}"
     runs-on: ${{ matrix.os }}
     strategy:
       fail-fast: false
@@ -72,3 +72,32 @@ jobs:
         working-directory: ./cpp/build
         shell: bash
         run: ctest --output-on-failure -j4 -C Release
+
+  bazel-build:
+    name: "Bazel ${{ matrix.os }}"
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-22.04, macos-latest, windows-2022]
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          submodules: true
+
+      - name: Setup Bazel
+        uses: bazelbuild/setup-bazel@v5
+        with:
+          bazelisk-cache: true
+          disk-cache: ${{ github.workflow }}-bazel-${{ matrix.os }}
+          repository-cache: true
+
+      - name: Build
+        working-directory: ./cpp
+        shell: bash
+        run: bazel build //...
+
+      - name: Test
+        working-directory: ./cpp
+        shell: bash
+        run: bazel test //...
diff --git a/.github/workflows/cpp_coverage.yml 
b/.github/workflows/cpp_coverage.yml
index 8cdeb5f7..be1f1f85 100644
--- a/.github/workflows/cpp_coverage.yml
+++ b/.github/workflows/cpp_coverage.yml
@@ -3,21 +3,66 @@ on:
   push:
     branches:
       - master
-# mainly refer to: 
https://github.com/merkrafter/Merkompiler/blob/development/.github/workflows/quality_assurance.yml
 jobs:
   calculate-coverage:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-22.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
         with:
           submodules: true
-      - name: Generate coverage report
+
+      - name: Install dependencies
+        run: sudo apt-get update && sudo apt-get install -y libssl-dev 
zlib1g-dev lcov
+
+      - name: Cache gRPC
+        id: cache-grpc
+        uses: actions/cache@v3
+        with:
+          path: ${{ runner.temp }}/grpc-install
+          key: grpc-1.46.3-ubuntu-22.04
+
+      - name: Build gRPC from source
+        if: steps.cache-grpc.outputs.cache-hit != 'true'
+        run: |
+          git clone --recurse-submodules -b v1.46.3 --depth 1 
https://github.com/grpc/grpc.git "${{ runner.temp }}/grpc-src"
+          cmake -S "${{ runner.temp }}/grpc-src" -B "${{ runner.temp 
}}/grpc-build" \
+            -DCMAKE_BUILD_TYPE=Release \
+            -DCMAKE_INSTALL_PREFIX="${{ runner.temp }}/grpc-install" \
+            -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
+            -DgRPC_INSTALL=ON \
+            -DgRPC_BUILD_TESTS=OFF \
+            -DgRPC_SSL_PROVIDER=package \
+            -DgRPC_ZLIB_PROVIDER=package
+          cmake --build "${{ runner.temp }}/grpc-build" --parallel 4 --config 
Release
+          cmake --install "${{ runner.temp }}/grpc-build" --config Release
+
+      - name: Build with coverage
+        working-directory: ./cpp
+        run: |
+          cmake -S . -B build \
+            -DCMAKE_BUILD_TYPE=Debug \
+            -DCMAKE_PREFIX_PATH="${{ runner.temp }}/grpc-install" \
+            -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
+            -DCMAKE_C_FLAGS="--coverage" \
+            -DCMAKE_CXX_FLAGS="--coverage" \
+            -DBUILD_EXAMPLES=OFF
+          cmake --build build --parallel 4
+
+      - name: Run tests
+        working-directory: ./cpp/build
+        run: ctest --output-on-failure -j4
+
+      - name: Collect coverage
         working-directory: ./cpp
-        run: bazel coverage  //...
+        run: |
+          lcov --capture --directory build --output-file coverage.info
+          lcov --remove coverage.info '/usr/*' '*/build/_deps/*' '*/proto/*' 
--output-file coverage.info
+          lcov --list coverage.info
+
       - name: Upload to Codecov
-        uses: codecov/codecov-action@v3
+        uses: codecov/codecov-action@v4
         with:
-          file: ./cpp/bazel-out/_coverage/_coverage_report.dat
+          file: ./cpp/coverage.info
           flags: cpp
           fail_ci_if_error: true
           verbose: true
diff --git a/cpp/.bazelrc b/cpp/.bazelrc
index 38aff1d3..562e8937 100644
--- a/cpp/.bazelrc
+++ b/cpp/.bazelrc
@@ -8,12 +8,14 @@
 # Startup options cannot be selected via config.
 startup --host_jvm_args=-Xmx2g
 
+# gRPC 1.46.3's upb uses @bazel_tools//platforms which was removed in Bazel 6.
+# Re-enable the old behavior until gRPC is upgraded.
+common --noincompatible_use_platforms_repo_for_constraints
+
 run --color=yes
 
 build --color=yes
 
-build --host_force_python=PY3
-
 # 
https://docs.bazel.build/versions/main/command-line-reference.html#flag--enable_platform_specific_config
 # If true, Bazel picks up host-OS-specific config lines from bazelrc files. 
For example, if the host OS is Linux and
 # you run bazel build, Bazel picks up lines starting with build:linux. 
Supported OS identifiers are linux, macos, 
@@ -131,22 +133,4 @@ build:coverage 
--instrumentation_filter="//source[/:],//include[/:],-//source/ba
 
 test --test_output=errors
 
-# RBE
-build:remote --bes_results_url=https://app.buildbuddy.io/invocation/
-build:remote --bes_backend=grpcs://remote.buildbuddy.io
-build:remote --remote_cache=grpcs://remote.buildbuddy.io
-build:remote --remote_timeout=3600
-build:remote --grpc_keepalive_time=360s
-build:remote --grpc_keepalive_timeout=360s
-build:remote --remote_executor=grpcs://remote.buildbuddy.io
-build:remote --host_platform=@buildbuddy_toolchain//:platform
-build:remote --platforms=@buildbuddy_toolchain//:platform
-build:remote --extra_execution_platforms=@buildbuddy_toolchain//:platform
-build:remote --crosstool_top=@buildbuddy_toolchain//:toolchain
-build:remote --extra_toolchains=@buildbuddy_toolchain//:cc_toolchain
-build:remote --jobs=250
-build:remote --remote_download_minimal
-build:remote --experimental_remote_cache_compression
-build:remote --experimental_remote_cache_async
-build:remote --spawn_strategy=remote
 # try-import %workspace%/user.bazelrc
\ No newline at end of file
diff --git a/cpp/.bazelversion b/cpp/.bazelversion
index 91ff5727..826f5ce0 100644
--- a/cpp/.bazelversion
+++ b/cpp/.bazelversion
@@ -1 +1 @@
-5.2.0
+6.6.0
diff --git a/cpp/WORKSPACE b/cpp/WORKSPACE
index 3c3d6476..86484441 100644
--- a/cpp/WORKSPACE
+++ b/cpp/WORKSPACE
@@ -14,41 +14,4 @@ rules_proto_grpc_repos()
 
 load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", 
"rules_proto_toolchains")
 rules_proto_dependencies()
-rules_proto_toolchains()
-
-# Support Bazel RBE(remote build execution)
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-http_archive(
-    name = "io_buildbuddy_buildbuddy_toolchain",
-    sha256 = 
"a2a5cccec251211e2221b1587af2ce43c36d32a42f5d881737db3b546a536510",
-    strip_prefix = 
"buildbuddy-toolchain-829c8a574f706de5c96c54ca310f139f4acda7dd",
-    urls = 
["https://github.com/buildbuddy-io/buildbuddy-toolchain/archive/829c8a574f706de5c96c54ca310f139f4acda7dd.tar.gz";],
-)
-load("@io_buildbuddy_buildbuddy_toolchain//:deps.bzl", "buildbuddy_deps")
-buildbuddy_deps()
-load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy")
-buildbuddy(name = "buildbuddy_toolchain")
-
-# Generate compile_commands.json
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-
-# Hedron's Compile Commands Extractor for Bazel
-# https://github.com/hedronvision/bazel-compile-commands-extractor
-http_archive(
-    name = "hedron_compile_commands",
-
-    # Replace the commit hash (0e990032f3c5a866e72615cf67e5ce22186dcb97) in 
both places (below) with the latest 
(https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main),
 rather than using the stale one here.
-    # Even better, set up Renovate and let it do the work for you (see 
"Suggestion: Updates" in the README).
-    url = 
"https://github.com/hedronvision/bazel-compile-commands-extractor/archive/204aa593e002cbd177d30f11f54cff3559110bb9.tar.gz";,
-    strip_prefix = 
"bazel-compile-commands-extractor-204aa593e002cbd177d30f11f54cff3559110bb9",
-    # When you first run this tool, it'll recommend a sha256 hash to put here 
with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a 
canonical reproducible form can be obtained by modifying arguments sha256 = ..."
-)
-load("@hedron_compile_commands//:workspace_setup.bzl", 
"hedron_compile_commands_setup")
-hedron_compile_commands_setup()
-load("@hedron_compile_commands//:workspace_setup_transitive.bzl", 
"hedron_compile_commands_setup_transitive")
-hedron_compile_commands_setup_transitive()
-load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", 
"hedron_compile_commands_setup_transitive_transitive")
-hedron_compile_commands_setup_transitive_transitive()
-load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl",
 "hedron_compile_commands_setup_transitive_transitive_transitive")
-hedron_compile_commands_setup_transitive_transitive_transitive()
\ No newline at end of file
+rules_proto_toolchains()
\ No newline at end of file

Reply via email to