Skip to content

Commit 2789813

Browse files
authored
Bazel module support (#135)
* Bazel module support Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Modernize workflows Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * configure Docker Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Define ci cache Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * restore sudo commands Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * use skywalking-data-collect-protocol upstream version Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Remove C++ standard specification from build steps Removed C++ standard specification from cmake commands. * Fix "Build main project" job failure by updating to C++17 and optimizing CI workflow Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Fix protobuf compilation errors, add missing Command.proto, and fix Bazel coverage Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Fix coverage test failure: correct Bazel workspace references and LLVM version Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Fix test coverage: use official Bazel coverage support with absolute paths Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Fix coverage report generation with bzlmod using Bazel-native path resolution Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Fix package installation commands in CI workflow: use apt-get for consistency and add lld Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update genhtml command to ignore unsupported sources * Disable lcov installation and coverage test Comment out installation and coverage test steps in CI workflow. --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent d8b7b81 commit 2789813

25 files changed

+223
-331
lines changed

.bazelrc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
common --enable_bzlmod
2+
3+
# CI-specific configuration
4+
build:ci --loading_phase_threads=1
5+
build:ci --jobs=2
6+
build:ci --verbose_failures
7+
build:ci --experimental_repository_cache_hardlinks
8+
build:ci --repository_cache=~/.cache/bazel/_bazel_runner/cache/repos/v1
9+
build:ci --disk_cache=~/.cache/bazel/_bazel_runner/cache/cas
10+
111
build --enable_platform_specific_config
212
build --features=-supports_dynamic_linker
313
build --copt="-Wall"
4-
build --copt="-Werror"
14+
build --cxxopt="-std=c++17"
15+
build --host_cxxopt="-std=c++17"
516
build:windows --copt=/wd4716
17+
build:windows --cxxopt="/std:c++17"
18+
build:windows --host_cxxopt="/std:c++17"
619

720
# Pass PATH variable from the environment
821
build --action_env=PATH
@@ -18,17 +31,14 @@ coverage --build_tests_only
1831
build:coverage --config=clang
1932
build:coverage --action_env=BAZEL_USE_LLVM_NATIVE_COVERAGE=1
2033
build:coverage --action_env=GCOV=llvm-profdata
34+
build:coverage --action_env=LLVM_COV=llvm-cov
2135
build:coverage --combined_report=lcov
2236
build:coverage --experimental_use_llvm_covmap
2337
build:coverage --experimental_generate_llvm_lcov
2438
build:coverage --collect_code_coverage
2539
build:coverage --instrumentation_filter="//source[/:],//cpp2sky[/:]"
26-
build:coverage --coverage_support=@cpp2sky//bazel/coverage:coverage_support
27-
build:coverage --test_env=CC_CODE_COVERAGE_SCRIPT=external/cpp2sky/bazel/coverage/collect_cc_coverage.sh
2840
build:coverage --strategy=TestRunner=local
2941
build:coverage --strategy=CoverageReport=local
30-
build:coverage --experimental_use_llvm_covmap
31-
build:coverage --collect_code_coverage
3242
build:coverage --test_tag_filters=-nocoverage
3343

3444
try-import %workspace%/user.bazelrc

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0
1+
7.6.1

.github/workflows/main.yml

Lines changed: 113 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,140 @@ on:
88
pull_request:
99
branches: [ main ]
1010

11+
permissions:
12+
contents: read
13+
14+
env:
15+
GRPC_VERSION: v1.74.1
16+
SKYWALKING_PROTOCOL_REF: a9ee9b1b2b9b3e74a152ebb8b61aac50934ac9ed
17+
1118
jobs:
1219
format:
13-
runs-on: ubuntu-20.04
20+
runs-on: ubuntu-22.04
1421
steps:
15-
- uses: actions/checkout@v3
16-
- name: Setup clang-format
17-
run: |
18-
git clone https://github.com/Sarcasm/run-clang-format.git
22+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
24+
- name: Checkout clang-format
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
26+
with:
27+
repository: Sarcasm/run-clang-format
28+
path: run-clang-format
29+
1930
- name: Run clang-format
2031
run: find ./ -iname "*.h" -o -iname "*.cc" | xargs ./run-clang-format/run-clang-format.py
2132

2233
unit-test:
23-
runs-on: ubuntu-20.04
34+
runs-on: ubuntu-22.04
2435
steps:
25-
- run: |
26-
echo "/opt/llvm/bin" >> $GITHUB_PATH
27-
- uses: actions/checkout@v3
28-
- name: Run bazel test with GCC c++11
29-
run: |
30-
bazel test --test_output=all --cxxopt=-std=c++0x //...
31-
- name: Run bazel test with GCC c++17
32-
run: |
33-
bazel test --test_output=all --cxxopt=-std=c++17 //...
34-
- name: Run bazel test with CLANG c++11
35-
run: |
36-
bazel test --test_output=all -c dbg --config=clang --cxxopt=-std=c++0x //...
37-
- name: Run bazel test with CLANG c++17
36+
- run: echo "/opt/llvm/bin" >> $GITHUB_PATH
37+
38+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
39+
40+
# Cache Bazel repository cache
41+
- name: Cache Bazel repository cache
42+
uses: actions/cache@v3
43+
with:
44+
path: ~/.cache/bazel/_bazel_runner/cache/repos/v1
45+
key: bazel-repo-cache-${{ runner.os }}-${{ hashFiles('MODULE.bazel', 'WORKSPACE', 'WORKSPACE.bzlmod') }}
46+
restore-keys: |
47+
bazel-repo-cache-${{ runner.os }}-
48+
49+
# Cache Bazel build outputs
50+
- name: Cache Bazel build cache
51+
uses: actions/cache@v3
52+
with:
53+
path: ~/.cache/bazel
54+
key: bazel-build-cache-${{ runner.os }}-${{ github.sha }}
55+
restore-keys: |
56+
bazel-build-cache-${{ runner.os }}-${{ github.base_ref }}
57+
bazel-build-cache-${{ runner.os }}-
58+
59+
- name: Run bazel test with GCC
60+
run: bazel test --config=ci --test_output=all //...
61+
62+
- name: Run bazel test with CLANG
63+
run: bazel test --config=ci --test_output=all -c opt --config=clang //...
64+
65+
# TODO: enable when fixed
66+
# - name: Install lcov and genhtml and link llvm
67+
# run: |
68+
# sudo apt-get update
69+
# sudo apt-get install -y lcov lld
70+
# sudo ln -s /usr/bin/llvm-profdata-16 /usr/bin/llvm-profdata
71+
# sudo ln -s /usr/bin/llvm-cov-16 /usr/bin/llvm-cov
72+
73+
# - name: Run coverage test
74+
# run: |
75+
# ./coverage.sh
76+
77+
cmake-build:
78+
runs-on: ubuntu-22.04
79+
steps:
80+
- run: echo "/opt/llvm/bin" >> $GITHUB_PATH
81+
82+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
83+
84+
- name: Generate dependencies hash
85+
id: deps-hash
3886
run: |
39-
bazel test --test_output=all -c opt --config=clang --cxxopt=-std=c++17 //...
87+
# Create a hash from dependency names and versions
88+
DEPS_STRING="grpc:${{ env.GRPC_VERSION }}|skywalking:${{ env.SKYWALKING_PROTOCOL_REF }}"
89+
DEPS_HASH=$(echo -n "$DEPS_STRING" | sha256sum | cut -c1-8)
90+
echo "hash=$DEPS_HASH" >> $GITHUB_OUTPUT
91+
echo "Dependencies hash (first 8 chars): $DEPS_HASH"
92+
93+
- name: Checkout skywalking-data-collect-protocol
94+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
95+
with:
96+
repository: apache/skywalking-data-collect-protocol
97+
ref: ${{ env.SKYWALKING_PROTOCOL_REF }}
98+
path: 3rdparty/skywalking-data-collect-protocol
99+
100+
# Cache gRPC build
101+
- name: Cache gRPC build
102+
uses: actions/cache@v3
103+
with:
104+
path: |
105+
grpc/build
106+
/usr/local/lib/libgrpc*
107+
/usr/local/lib/libprotobuf*
108+
/usr/local/lib/cmake/grpc
109+
/usr/local/lib/cmake/protobuf
110+
/usr/local/include/grpc*
111+
/usr/local/include/google/protobuf
112+
/usr/local/bin/grpc_*
113+
/usr/local/bin/protoc
114+
key: grpc-cmake-${{ runner.os }}-${{ steps.deps-hash.outputs.hash }}-${{ hashFiles('CMakeLists.txt', 'cmake/grpc.cmake') }}
115+
restore-keys: |
116+
grpc-cmake-${{ runner.os }}-${{ steps.deps-hash.outputs.hash }}-
117+
grpc-cmake-${{ runner.os }}-
118+
119+
- name: Checkout grpc
120+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
121+
with:
122+
repository: grpc/grpc
123+
ref: ${{ env.GRPC_VERSION }}
124+
path: grpc
125+
submodules: true
126+
40127
- name: Install cmake dependencies and run cmake compile
41128
run: |
42-
sudo apt update
43-
sudo apt -y install cmake
44-
sudo git clone -b v9.1.0 https://github.com/apache/skywalking-data-collect-protocol.git ./3rdparty/skywalking-data-collect-protocol
45-
sudo git clone -b v1.46.6 https://github.com/grpc/grpc.git --recursive
129+
sudo apt-get update
130+
sudo apt-get install -y cmake build-essential
46131
sudo cmake -S ./grpc -B ./grpc/build
47132
sudo cmake --build ./grpc/build --parallel 8 --target install
48133
sudo cmake -S . -B ./build
49134
sudo cmake --build ./build
50-
- name: Install lcov and genhtml and link llvm
51-
run: |
52-
sudo apt update
53-
sudo apt -y install lcov
54-
sudo ln -s /usr/bin/llvm-profdata-11 /usr/bin/llvm-profdata
55-
sudo ln -s /usr/bin/llvm-cov-11 /usr/bin/llvm-cov
56-
- name: Run coverage test
57-
run: |
58-
./coverage.sh
59135
60136
e2e-test:
61-
runs-on: ubuntu-20.04
137+
runs-on: ubuntu-22.04
62138
steps:
63-
- uses: actions/checkout@v3
139+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
140+
64141
- name: Prepare service container
65142
run: |
66143
docker compose -f test/e2e/docker/docker-compose.yml up -d
144+
67145
- name: Run e2e
68146
run: |
69147
sleep 10

.gitignore

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@
3434
# user's bazel configuration files
3535
user.bazelrc
3636

37-
# bazel artifacts
38-
/bazel-bin
39-
/bazel-out
40-
/bazel-cpp2sky
41-
/bazel-testlogs
37+
# Ignore links to Bazel's output. The pattern needs the `*` because people can change the name of the directory into which your repository is cloned (changing the `bazel-<workspace_name>` symlink), and must not end with a trailing `/` because it's a symlink on macOS/Linux.
38+
/bazel-*
39+
MODULE.bazel.lock
4240

4341
# editor settings
4442
.vscode/
@@ -48,11 +46,14 @@ compile_commands.json
4846

4947
coverage_report
5048

49+
# CMake build directories and dependencies
50+
build/
51+
3rdparty/
52+
grpc/
53+
5154
### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
5255
# Ignore the `external` link (that is added by `bazel-compile-commands-extractor`). The link differs between macOS/Linux and Windows, so it shouldn't be checked in. The pattern must not end with a trailing `/` because it's a symlink on macOS/Linux.
5356
/external
54-
# Ignore links to Bazel's output. The pattern needs the `*` because people can change the name of the directory into which your repository is cloned (changing the `bazel-<workspace_name>` symlink), and must not end with a trailing `/` because it's a symlink on macOS/Linux.
55-
/bazel-*
5657
# Ignore generated output. Although valuable (after all, the primary purpose of `bazel-compile-commands-extractor` is to produce `compile_commands.json`!), it should not be checked in.
5758
/compile_commands.json
5859
# Ignore the directory in which `clangd` stores its local index.

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if(POLICY CMP0091)
55
endif()
66

77
project(cpp2sky
8-
VERSION 0.5.1
8+
VERSION 0.6.1
99
DESCRIPTION "Distributed tracing and monitor SDK in CPP for Apache SkyWalking APM"
1010
HOMEPAGE_URL "https://github.com/SkyAPM/cpp2sky"
1111
)
@@ -19,7 +19,7 @@ option(GENERATE_CPP2SKY_PKGCONFIG "Generate and install pkg-config files for UN
1919

2020

2121
if(OVERRIDE_CXX_STANDARD_FLAGS)
22-
set(CMAKE_CXX_STANDARD 11)
22+
set(CMAKE_CXX_STANDARD 17)
2323
set(CMAKE_CXX_EXTENSIONS OFF)
2424
endif()
2525

MODULE.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module(
2+
name = "cpp2sky",
3+
version = "0.6.1-dev",
4+
)
5+
6+
bazel_dep(name = "abseil-cpp", version = "20250512.1", repo_name = "com_google_absl")
7+
bazel_dep(name = "fmt", version = "8.1.1", repo_name = "com_github_fmtlib_fmt")
8+
bazel_dep(name = "grpc", version = "1.74.1", repo_name = "com_github_grpc_grpc")
9+
bazel_dep(name = "cpp-httplib", version = "0.22.0", repo_name = "com_github_httplib")
10+
bazel_dep(name = "protobuf", version = "32.0", repo_name = "com_google_protobuf")
11+
bazel_dep(name = "rules_cc", version = "0.2.2")
12+
bazel_dep(name = "skywalking-data-collect-protocol", repo_name = "skywalking_data_collect_protocol")
13+
git_override(
14+
module_name = "skywalking-data-collect-protocol",
15+
commit = "a9ee9b1b2b9b3e74a152ebb8b61aac50934ac9ed",
16+
remote = "https://github.com/apache/skywalking-data-collect-protocol.git",
17+
)
18+
19+
bazel_dep(name = "spdlog", version = "1.10.0", repo_name = "com_github_gabime_spdlog")
20+
21+
bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True, repo_name = "com_google_googletest")
22+
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
23+
git_override(
24+
module_name = "hedron_compile_commands",
25+
commit = "abb61a688167623088f8768cc9264798df6a9d10",
26+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
27+
)

WORKSPACE

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ load("//bazel:repositories.bzl", "cpp2sky_dependencies")
44

55
cpp2sky_dependencies()
66

7-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
8-
9-
rules_proto_dependencies()
10-
11-
rules_proto_toolchains()
12-
137
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
148

159
grpc_deps()
@@ -18,6 +12,10 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
1812

1913
grpc_extra_deps()
2014

15+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
16+
17+
protobuf_deps()
18+
2119
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
2220

2321
hedron_compile_commands_setup()

WORKSPACE.bzlmod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace(name = "cpp2sky")

bazel/coverage/BUILD

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)