Skip to content

Commit 092db69

Browse files
committed
chore(cmake): adopt submodule-first dependency strategy
- Adopt a "submodule-first, FetchContent-fallback" approach for third‑party deps. - Add and pin submodules under 3rdparty: spdlog, fmt, httplib, skywalking-data-collect-protocol, grpc (pinned tags included). - Move auto-detection and conflict validation into each dependency module (cmake/*.cmake) and simplify top-level CMakeLists.txt. - Update CI (main.yml) to checkout submodules and to build gRPC from grpc. - Add skywalking.cmake and wire proto2cpp to use SKYWALKING_PROTOCOL_PATH. - Update README.md with submodule workflow, build instructions and bump procedure. Rationale: improves reproducibility, makes dependency handling explicit and easier to maintain. Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 9d1bcfa commit 092db69

File tree

16 files changed

+217
-39
lines changed

16 files changed

+217
-39
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ jobs:
8080
- run: echo "/opt/llvm/bin" >> $GITHUB_PATH
8181

8282
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
83+
with:
84+
submodules: 'recursive'
85+
fetch-depth: 0
8386

8487
- name: Generate dependencies hash
8588
id: deps-hash
@@ -90,19 +93,12 @@ jobs:
9093
echo "hash=$DEPS_HASH" >> $GITHUB_OUTPUT
9194
echo "Dependencies hash (first 8 chars): $DEPS_HASH"
9295
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-
10096
# Cache gRPC build
10197
- name: Cache gRPC build
10298
uses: actions/cache@v3
10399
with:
104100
path: |
105-
grpc/build
101+
3rdparty/grpc/build
106102
/usr/local/lib/libgrpc*
107103
/usr/local/lib/libprotobuf*
108104
/usr/local/lib/cmake/grpc
@@ -115,21 +111,12 @@ jobs:
115111
restore-keys: |
116112
grpc-cmake-${{ runner.os }}-${{ steps.deps-hash.outputs.hash }}-
117113
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-
127114
- name: Install cmake dependencies and run cmake compile
128115
run: |
129116
sudo apt-get update
130117
sudo apt-get install -y cmake build-essential
131-
sudo cmake -S ./grpc -B ./grpc/build
132-
sudo cmake --build ./grpc/build --parallel 8 --target install
118+
sudo cmake -S ./3rdparty/grpc -B ./3rdparty/grpc/build
119+
sudo cmake --build ./3rdparty/grpc/build --parallel 8 --target install
133120
sudo cmake -S . -B ./build
134121
sudo cmake --build ./build
135122

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ coverage_report
4848

4949
# CMake build directories and dependencies
5050
build/
51-
3rdparty/
5251
grpc/
5352

5453
### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor

.gitmodules

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[submodule "3rdparty/fmt"]
2+
path = 3rdparty/fmt
3+
url = https://github.com/fmtlib/fmt.git
4+
5+
[submodule "3rdparty/grpc"]
6+
path = 3rdparty/grpc
7+
url = https://github.com/grpc/grpc.git
8+
9+
[submodule "3rdparty/httplib"]
10+
path = 3rdparty/httplib
11+
url = https://github.com/yhirose/cpp-httplib.git
12+
13+
[submodule "3rdparty/skywalking-data-collect-protocol"]
14+
path = 3rdparty/skywalking-data-collect-protocol
15+
url = https://github.com/apache/skywalking-data-collect-protocol.git
16+
17+
[submodule "3rdparty/spdlog"]
18+
path = 3rdparty/spdlog
19+
url = https://github.com/gabime/spdlog.git

3rdparty/fmt

Submodule fmt added at b6f4cea

3rdparty/grpc

Submodule grpc added at 893bdad

3rdparty/httplib

Submodule httplib added at b6c55c6

3rdparty/spdlog

Submodule spdlog added at 76fb40d

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ project(cpp2sky
1010
HOMEPAGE_URL "https://github.com/SkyAPM/cpp2sky"
1111
)
1212

13-
option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++11 even if the CXXFLAGS are configured differently" ON)
14-
option(SPDLOG_FETCHCONTENT "Using spdlog FetchContent to build" ON)
15-
option(FMTLIB_FETCHCONTENT "Using fmt FetchContent to build" ON)
16-
option(HTTPLIB_FETCHCONTENT "Using httplib FetchContent to build" ON)
1713
option(CPP2SKY_INSTALL "Generate the install target." OFF)
14+
option(FMTLIB_FETCHCONTENT "Using fmt FetchContent to build" ON)
1815
option(GENERATE_CPP2SKY_PKGCONFIG "Generate and install pkg-config files for UNIX" OFF)
19-
16+
option(GRPC_FETCHCONTENT "Using gRPC FetchContent to build" ON)
17+
option(HTTPLIB_FETCHCONTENT "Using httplib FetchContent to build" ON)
18+
option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++11 even if the CXXFLAGS are configured differently" ON)
19+
option(SKYWALKING_FETCHCONTENT "Using skywalking-data-collect-protocol FetchContent to build" ON)
20+
option(SPDLOG_FETCHCONTENT "Using spdlog FetchContent to build" ON)
2021

2122
if(OVERRIDE_CXX_STANDARD_FLAGS)
2223
set(CMAKE_CXX_STANDARD 17)
@@ -46,6 +47,7 @@ include(fmtlib)
4647
include(spdlog)
4748
include(httplib)
4849
include(grpc)
50+
include(skywalking)
4951
include(proto2cpp)
5052

5153
target_link_libraries(${PROJECT_NAME}

README.md

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,73 @@ cc_binary(
3333

3434
#### Cmake
3535

36-
You can compile this project, according to the following steps:
36+
You can compile this project in one of three supported ways (submodule-first is recommended):
37+
38+
- Recommended — Submodule-first (most reproducible):
39+
40+
```bash
41+
git clone --recurse-submodules [email protected]:SkyAPM/cpp2sky.git
42+
git submodule update --init --recursive
3743
```
38-
step 01: git clone [email protected]:SkyAPM/cpp2sky.git
39-
step 02: git clone -b v9.1.0 https://github.com/apache/skywalking-data-collect-protocol.git ./3rdparty/skywalking-data-collect-protocol
40-
step 03: git clone -b v1.46.6 https://github.com/grpc/grpc.git --recursive
41-
step 04: cmake -S ./grpc -B ./grpc/build && cmake --build ./grpc/build --parallel 8 --target install
42-
step 05: cmake -S . -B ./build && cmake --build ./build
44+
45+
This repository pins several third-party dependencies under `3rdparty/` (example: `spdlog`, `fmt`, `httplib`, `skywalking-data-collect-protocol`). The top-level CMake will auto-detect these submodules and use them via `add_subdirectory()`.
46+
47+
- FetchContent fallback (automatic clone at configure time):
48+
49+
If a submodule is not present, CMake can automatically download the dependency at configure time using FetchContent. This is controlled by CMake options of the form `-D<LIB>_FETCHCONTENT=ON` (these are `ON` by default for some deps). For SkyWalking you can enable FetchContent with:
50+
51+
```bash
52+
cmake -DSKYWALKING_FETCHCONTENT=ON -S . -B build
53+
cmake --build build
4354
```
4455

56+
- Explicit path (developer workflow):
57+
58+
If you already have a local checkout of `skywalking-data-collect-protocol`, point CMake to it:
59+
60+
```bash
61+
cmake -DSKYWALKING_PROTOCOL_PATH=/path/to/skywalking-data-collect-protocol -S . -B build
62+
cmake --build build
63+
```
64+
65+
Notes about building `grpc`:
66+
67+
If you are using the recommended submodule-first workflow, this repository includes a pinned copy of gRPC under `3rdparty/grpc` (tag `v1.74.1`). CI is updated to build gRPC from that submodule.
68+
69+
Build gRPC locally from the submodule:
70+
71+
```bash
72+
# initialize submodules (if you haven't already)
73+
git submodule update --init --recursive
74+
75+
# install build deps
76+
sudo apt-get update
77+
sudo apt-get install -y cmake build-essential
78+
79+
# configure & install gRPC from the submodule
80+
cmake -S 3rdparty/grpc -B 3rdparty/grpc/build
81+
cmake --build 3rdparty/grpc/build --parallel 8 --target install
82+
83+
# configure & build cpp2sky
84+
cmake -S . -B build
85+
cmake --build build --parallel $(nproc)
86+
```
87+
88+
If you prefer not to use the submodule, the previous approach (cloning gRPC separately at a chosen tag and building it) still works, but using the pinned submodule provides reproducible builds and is recommended.
89+
90+
How to bump a submodule (example for skywalking-data-collect-protocol):
91+
```bash
92+
cd 3rdparty/skywalking-data-collect-protocol
93+
git fetch --tags
94+
git checkout tags/v10.4.0 # or a specific commit
95+
cd ../..
96+
git add 3rdparty/skywalking-data-collect-protocol
97+
git commit -m "Pin skywalking-data-collect-protocol to v10.4.0"
98+
git push
99+
```
100+
101+
If you prefer CI to always fetch the latest submodules, ensure the workflow initializes submodules (this repo's CI uses `actions/checkout` with `submodules: 'recursive'`).
102+
45103
You can also use find_package to get target libary in your project. Like this:
46104
```
47105
find_package(cpp2sky CONFIG REQUIRED)

0 commit comments

Comments
 (0)