Skip to content

Commit 6eb1520

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 6eb1520

File tree

16 files changed

+236
-39
lines changed

16 files changed

+236
-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: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,92 @@ 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 dependencies with special handling
66+
67+
Most third-party dependencies follow the same pattern: prefer the pinned submodule under `3rdparty/` (submodule-first) and fall back to `FetchContent` at configure time when the submodule is not present. See the top-level `CMakeLists.txt` and the modules in `cmake/` for details.
68+
69+
There are two cases worth calling out because their consumption/build steps differ slightly:
70+
71+
- gRPC
72+
73+
gRPC is not header-only and typically needs configuration and a build step (or its targets must be available via `find_package`). This repository includes a pinned copy of gRPC at `3rdparty/grpc` (tag `v1.74.1`) so builds are reproducible. CI is configured to build gRPC from that submodule.
74+
75+
To build gRPC locally from the submodule and install it for the rest of the project:
76+
77+
```bash
78+
# initialize submodules (if you haven't already)
79+
git submodule update --init --recursive
80+
81+
# install build deps
82+
sudo apt-get update
83+
sudo apt-get install -y cmake build-essential
84+
85+
# configure & install gRPC from the submodule
86+
cmake -S 3rdparty/grpc -B 3rdparty/grpc/build
87+
cmake --build 3rdparty/grpc/build --parallel 8 --target install
88+
89+
# configure & build cpp2sky
90+
cmake -S . -B build
91+
cmake --build build --parallel $(nproc)
92+
```
93+
94+
If you prefer not to use the submodule you can still clone and build gRPC separately and make its CMake targets available to the project, but using the pinned submodule is recommended for reproducibility.
95+
96+
- skywalking-data-collect-protocol (protobufs)
97+
98+
The SkyWalking protocol repository contains the protobuf definitions used to generate code for the project. The `cmake/skywalking.cmake` module sets `SKYWALKING_PROTOCOL_PATH` when the `3rdparty/skywalking-data-collect-protocol` submodule is present so the proto generation step can locate the `.proto` files.
99+
100+
You can override that behavior by supplying an explicit path:
101+
102+
```bash
103+
cmake -DSKYWALKING_PROTOCOL_PATH=/path/to/skywalking-data-collect-protocol -S . -B build
104+
cmake --build build
105+
```
106+
107+
Alternatively, enable FetchContent for SkyWalking with `-DSKYWALKING_FETCHCONTENT=ON` to let CMake fetch the proto repo at configure time.
108+
109+
How to bump a submodule (example for skywalking-data-collect-protocol):
110+
```bash
111+
cd 3rdparty/skywalking-data-collect-protocol
112+
git fetch --tags
113+
git checkout tags/v10.4.0 # or a specific commit
114+
cd ../..
115+
git add 3rdparty/skywalking-data-collect-protocol
116+
git commit -m "Pin skywalking-data-collect-protocol to v10.4.0"
117+
git push
118+
```
119+
120+
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'`).
121+
45122
You can also use find_package to get target libary in your project. Like this:
46123
```
47124
find_package(cpp2sky CONFIG REQUIRED)

0 commit comments

Comments
 (0)