Skip to content

Commit 19aa619

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 19aa619

File tree

16 files changed

+282
-39
lines changed

16 files changed

+282
-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" OFF)
1815
option(GENERATE_CPP2SKY_PKGCONFIG "Generate and install pkg-config files for UNIX" OFF)
19-
16+
option(GRPC_FETCHCONTENT "Using gRPC FetchContent to build" OFF)
17+
option(HTTPLIB_FETCHCONTENT "Using httplib FetchContent to build" OFF)
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" OFF)
20+
option(SPDLOG_FETCHCONTENT "Using spdlog FetchContent to build" OFF)
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: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,98 @@ 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
43+
```
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`.
50+
51+
Important: this project now defaults `*_FETCHCONTENT` to `OFF` to favour a submodule-first workflow (reproducible builds). Each dependency module will auto-detect a local `3rdparty/<lib>` submodule and, unless you explicitly set the corresponding `-D` option, enable the submodule and only enable FetchContent as a fallback when the submodule is absent.
52+
53+
If you need to force FetchContent for any dependency (for example, to debug or when you prefer not to initialize submodules), you can pass `-D<LIB>_FETCHCONTENT=ON` on the `cmake` command line. If you pass conflicting options (both `-D<LIB>_AS_SUBMODULE=ON` and `-D<LIB>_FETCHCONTENT=ON`) CMake will stop with a helpful error and you must choose one.
54+
55+
For SkyWalking you can enable FetchContent with:
56+
57+
```bash
58+
cmake -DSKYWALKING_FETCHCONTENT=ON -S . -B build
59+
cmake --build build
60+
```
61+
62+
- Explicit path (developer workflow):
63+
64+
If you already have a local checkout of `skywalking-data-collect-protocol`, point CMake to it:
65+
66+
```bash
67+
cmake -DSKYWALKING_PROTOCOL_PATH=/path/to/skywalking-data-collect-protocol -S . -B build
68+
cmake --build build
3769
```
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
70+
71+
Notes about dependencies with special handling
72+
73+
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.
74+
75+
There are two cases worth calling out because their consumption/build steps differ slightly:
76+
77+
- gRPC
78+
79+
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.
80+
81+
To build gRPC locally from the submodule and install it for the rest of the project:
82+
83+
```bash
84+
# initialize submodules (if you haven't already)
85+
git submodule update --init --recursive
86+
87+
# install build deps
88+
sudo apt-get update
89+
sudo apt-get install -y cmake build-essential
90+
91+
# configure & install gRPC from the submodule
92+
cmake -S 3rdparty/grpc -B 3rdparty/grpc/build
93+
cmake --build 3rdparty/grpc/build --parallel 8 --target install
94+
95+
# configure & build cpp2sky
96+
cmake -S . -B build
97+
cmake --build build --parallel $(nproc)
98+
```
99+
100+
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.
101+
102+
- skywalking-data-collect-protocol (protobufs)
103+
104+
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.
105+
106+
You can override that behavior by supplying an explicit path:
107+
108+
```bash
109+
cmake -DSKYWALKING_PROTOCOL_PATH=/path/to/skywalking-data-collect-protocol -S . -B build
110+
cmake --build build
111+
```
112+
113+
Alternatively, enable FetchContent for SkyWalking with `-DSKYWALKING_FETCHCONTENT=ON` to let CMake fetch the proto repo at configure time.
114+
115+
How to bump a submodule (example for skywalking-data-collect-protocol):
116+
```bash
117+
cd 3rdparty/skywalking-data-collect-protocol
118+
git fetch --tags
119+
git checkout tags/v10.4.0 # or a specific commit
120+
cd ../..
121+
git add 3rdparty/skywalking-data-collect-protocol
122+
git commit -m "Pin skywalking-data-collect-protocol to v10.4.0"
123+
git push
43124
```
44125

126+
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'`).
127+
45128
You can also use find_package to get target libary in your project. Like this:
46129
```
47130
find_package(cpp2sky CONFIG REQUIRED)

0 commit comments

Comments
 (0)