Skip to content

Commit e4e4b73

Browse files
authored
Merge pull request #44 from openSVM/copilot/fix-43
Add comprehensive C++ SDK implementation guidelines
2 parents a0b811c + 8611a2d commit e4e4b73

39 files changed

+11164
-0
lines changed

.github/workflows/cpp_sdk.yml

Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
name: C++ SDK CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
paths:
7+
- 'cpp_sdk/**'
8+
- '.github/workflows/cpp_sdk.yml'
9+
pull_request:
10+
branches: [ main, develop ]
11+
paths:
12+
- 'cpp_sdk/**'
13+
- '.github/workflows/cpp_sdk.yml'
14+
15+
jobs:
16+
test:
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest, windows-latest]
21+
build-type: [Debug, Release]
22+
compiler: [gcc, clang, msvc]
23+
exclude:
24+
- os: windows-latest
25+
compiler: gcc
26+
- os: macos-latest
27+
compiler: gcc
28+
- os: ubuntu-latest
29+
compiler: msvc
30+
- os: macos-latest
31+
compiler: msvc
32+
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Install libsodium
37+
if: matrix.os == 'ubuntu-latest'
38+
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
39+
40+
41+
42+
- name: Install dependencies (Ubuntu)
43+
if: matrix.os == 'ubuntu-latest'
44+
run: |
45+
sudo apt-get install -y cmake ninja-build pkg-config valgrind
46+
if [ "${{ matrix.compiler }}" = "clang" ]; then
47+
sudo apt-get install -y clang-15
48+
echo "CC=clang-15" >> $GITHUB_ENV
49+
echo "CXX=clang++-15" >> $GITHUB_ENV
50+
fi
51+
52+
- name: Install dependencies (macOS)
53+
if: matrix.os == 'macos-latest'
54+
run: |
55+
brew install cmake ninja libsodium pkg-config lcov
56+
BREW_PREFIX=$(brew --prefix)
57+
echo "PKG_CONFIG_PATH=${BREW_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}" >> $GITHUB_ENV
58+
echo "CMAKE_PREFIX_PATH=${BREW_PREFIX}:${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
59+
echo "LIBRARY_PATH=${BREW_PREFIX}/lib:${LIBRARY_PATH}" >> $GITHUB_ENV
60+
echo "LD_LIBRARY_PATH=${BREW_PREFIX}/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
61+
echo "DYLD_LIBRARY_PATH=${BREW_PREFIX}/lib:${DYLD_LIBRARY_PATH}" >> $GITHUB_ENV
62+
if [ "${{ matrix.compiler }}" = "clang" ]; then
63+
echo "CC=clang" >> $GITHUB_ENV
64+
echo "CXX=clang++" >> $GITHUB_ENV
65+
fi
66+
67+
- name: Install dependencies (Windows)
68+
if: matrix.os == 'windows-latest'
69+
shell: pwsh
70+
timeout-minutes: 15
71+
run: |
72+
# Install basic tools
73+
choco install cmake ninja pkgconfiglite --yes
74+
75+
# Use the pre-installed vcpkg on GitHub Actions
76+
$vcpkgPath = "C:\vcpkg"
77+
if (Test-Path $vcpkgPath) {
78+
echo "Using pre-installed vcpkg at $vcpkgPath"
79+
} else {
80+
echo "Installing fresh vcpkg..."
81+
git clone https://github.com/Microsoft/vcpkg.git C:\vcpkg
82+
C:\vcpkg\bootstrap-vcpkg.bat
83+
}
84+
85+
# Install required packages
86+
C:\vcpkg\vcpkg.exe install libsodium:x64-windows pkgconf:x64-windows gtest:x64-windows
87+
88+
# Set environment variables
89+
echo "CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV
90+
echo "PKG_CONFIG_PATH=C:/vcpkg/installed/x64-windows/lib/pkgconfig" >> $env:GITHUB_ENV
91+
echo "VCPKG_ROOT=C:/vcpkg" >> $env:GITHUB_ENV
92+
93+
if ("${{ matrix.compiler }}" -eq "msvc") {
94+
echo "Using MSVC compiler"
95+
} else {
96+
echo "Using Clang compiler"
97+
echo "CC=clang" >> $env:GITHUB_ENV
98+
echo "CXX=clang++" >> $env:GITHUB_ENV
99+
}
100+
101+
- name: Install Google Test (Ubuntu)
102+
if: matrix.os == 'ubuntu-latest'
103+
run: |
104+
sudo apt-get install -y libgtest-dev
105+
cd /usr/src/gtest
106+
sudo cmake .
107+
sudo make
108+
sudo cp lib/*.a /usr/lib
109+
110+
- name: Install Google Test (macOS)
111+
if: matrix.os == 'macos-latest'
112+
run: |
113+
git clone https://github.com/google/googletest.git
114+
cd googletest
115+
mkdir build && cd build
116+
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
117+
cmake --build . --config ${{ matrix.build-type }}
118+
sudo cmake --install . --config ${{ matrix.build-type }}
119+
120+
- name: Configure CMake (Windows)
121+
if: matrix.os == 'windows-latest'
122+
shell: pwsh
123+
run: |
124+
cd cpp_sdk
125+
New-Item -ItemType Directory -Force -Path build
126+
cd build
127+
128+
# Debug output
129+
echo "CMAKE_TOOLCHAIN_FILE: $env:CMAKE_TOOLCHAIN_FILE"
130+
echo "PKG_CONFIG_PATH: $env:PKG_CONFIG_PATH"
131+
echo "VCPKG_ROOT: $env:VCPKG_ROOT"
132+
133+
if ("${{ matrix.compiler }}" -eq "msvc") {
134+
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" -DCMAKE_VERBOSE_MAKEFILE=ON
135+
} else {
136+
cmake .. -G"Ninja" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" -DCMAKE_VERBOSE_MAKEFILE=ON
137+
}
138+
env:
139+
CI: true
140+
141+
- name: Configure CMake (Unix)
142+
if: matrix.os != 'windows-latest'
143+
shell: bash
144+
run: |
145+
cd cpp_sdk
146+
mkdir build && cd build
147+
cmake .. -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DENABLE_SANITIZERS=ON
148+
env:
149+
CI: true
150+
151+
- name: Build (Windows)
152+
if: matrix.os == 'windows-latest'
153+
shell: pwsh
154+
run: |
155+
cd cpp_sdk/build
156+
if ("${{ matrix.compiler }}" -eq "msvc") {
157+
cmake --build . --config ${{ matrix.build-type }}
158+
} else {
159+
ninja
160+
}
161+
162+
- name: Build (Unix)
163+
if: matrix.os != 'windows-latest'
164+
shell: bash
165+
run: |
166+
cd cpp_sdk/build
167+
ninja
168+
169+
- name: Run tests (Windows)
170+
if: matrix.os == 'windows-latest'
171+
shell: pwsh
172+
run: |
173+
cd cpp_sdk/build
174+
ctest --verbose --output-on-failure --build-config ${{ matrix.build-type }}
175+
176+
- name: Run tests (Unix)
177+
if: matrix.os != 'windows-latest'
178+
shell: bash
179+
run: |
180+
cd cpp_sdk/build
181+
ctest --verbose --output-on-failure
182+
183+
- name: Generate coverage report (Debug builds only)
184+
if: matrix.build-type == 'Debug' && matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc'
185+
run: |
186+
cd cpp_sdk/build
187+
ninja coverage
188+
189+
- name: Debug coverage files
190+
if: matrix.build-type == 'Debug' && matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc'
191+
run: |
192+
echo "Listing files in cpp_sdk/build:"
193+
ls -la cpp_sdk/build/
194+
echo "Looking for coverage files:"
195+
find cpp_sdk/build/ -name "*.info" -o -name "*.gcno" -o -name "*.gcda" | head -20
196+
197+
- name: Upload coverage to Codecov
198+
if: matrix.build-type == 'Debug' && matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc'
199+
uses: codecov/codecov-action@v4
200+
with:
201+
token: ${{ secrets.CODECOV_TOKEN }}
202+
file: ./cpp_sdk/build/coverage.info
203+
flags: cpp_sdk
204+
name: cpp-sdk-coverage
205+
fail_ci_if_error: true
206+
207+
memory-safety:
208+
runs-on: ubuntu-latest
209+
steps:
210+
- uses: actions/checkout@v4
211+
212+
- name: Clean build directories
213+
run: |
214+
cd cpp_sdk
215+
rm -rf build-asan build-valgrind
216+
217+
- name: Install libsodium
218+
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
219+
220+
- name: Install dependencies
221+
run: |
222+
sudo apt-get install -y cmake ninja-build pkg-config valgrind clang-15
223+
echo "CC=clang-15" >> $GITHUB_ENV
224+
echo "CXX=clang++-15" >> $GITHUB_ENV
225+
226+
- name: Install Google Test
227+
run: |
228+
sudo apt-get install -y libgtest-dev
229+
cd /usr/src/gtest
230+
sudo cmake .
231+
sudo make
232+
sudo cp lib/*.a /usr/lib
233+
234+
- name: Configure with AddressSanitizer
235+
run: |
236+
cd cpp_sdk
237+
mkdir -p build-asan && cd build-asan
238+
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON
239+
240+
- name: Build with AddressSanitizer
241+
run: |
242+
cd cpp_sdk/build-asan
243+
ninja
244+
245+
- name: Test with AddressSanitizer
246+
run: |
247+
cd cpp_sdk/build-asan
248+
ninja test-sanitizers
249+
250+
- name: Configure with Valgrind
251+
run: |
252+
cd cpp_sdk
253+
mkdir -p build-valgrind && cd build-valgrind
254+
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_VALGRIND=ON
255+
256+
- name: Build with Valgrind
257+
run: |
258+
cd cpp_sdk/build-valgrind
259+
ninja
260+
261+
- name: Test with Valgrind
262+
run: |
263+
cd cpp_sdk/build-valgrind
264+
ninja test-valgrind
265+
266+
static-analysis:
267+
runs-on: ubuntu-latest
268+
steps:
269+
- uses: actions/checkout@v4
270+
271+
- name: Install libsodium
272+
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
273+
274+
- name: Install dependencies
275+
run: |
276+
sudo apt-get install -y cmake ninja-build pkg-config clang-15 clang-tidy-15 clang-format-15 # Add clang-format-15 here
277+
echo "CC=clang-15" >> $GITHUB_ENV
278+
echo "CXX=clang++-15" >> $GITHUB_ENV
279+
280+
- name: Install Google Test
281+
run: |
282+
sudo apt-get install -y libgtest-dev
283+
cd /usr/src/gtest
284+
sudo cmake .
285+
sudo make
286+
sudo cp lib/*.a /usr/lib
287+
288+
- name: Configure
289+
run: |
290+
cd cpp_sdk
291+
mkdir build && cd build
292+
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
293+
294+
- name: Run clang-tidy
295+
run: |
296+
cd cpp_sdk
297+
clang-tidy-15 src/*.cpp -p build/ --warnings-as-errors=*
298+
299+
- name: Run clang-format check
300+
run: |
301+
cd cpp_sdk
302+
find . -name "*.cpp" -o -name "*.hpp" | grep -v "^./build" | xargs clang-format-15 --dry-run --Werror
303+
304+
documentation:
305+
runs-on: ubuntu-latest
306+
steps:
307+
- uses: actions/checkout@v4
308+
309+
- name: Install libsodium
310+
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
311+
312+
- name: Install dependencies
313+
run: |
314+
sudo apt-get install -y doxygen graphviz libgtest-dev
315+
cd /usr/src/gtest
316+
sudo cmake .
317+
sudo make
318+
sudo cp lib/*.a /usr/lib
319+
320+
- name: Generate documentation
321+
run: |
322+
cd cpp_sdk
323+
mkdir build && cd build
324+
cmake .. -GNinja
325+
ninja docs
326+
327+
- name: Upload documentation
328+
uses: actions/upload-artifact@v4
329+
with:
330+
name: cpp-sdk-docs
331+
path: cpp_sdk/build/docs/html/

cpp_sdk/.gitignore

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Build directories
2+
build/
3+
build-*/
4+
cmake-build-*/
5+
_build/
6+
out/
7+
8+
# Generated files
9+
CMakeCache.txt
10+
CMakeFiles/
11+
cmake_install.cmake
12+
Makefile
13+
*.cmake
14+
!CMakeLists.txt
15+
!cmake/*.cmake.in
16+
17+
# Testing
18+
CTestTestfile.cmake
19+
Testing/
20+
21+
# Coverage
22+
*.gcov
23+
*.gcno
24+
*.gcda
25+
coverage.info
26+
coverage_html/
27+
28+
# Documentation
29+
docs/doxygen/html/
30+
docs/doxygen/latex/
31+
docs/doxygen/xml/
32+
33+
# Compiled binaries
34+
*.a
35+
*.so
36+
*.dylib
37+
*.dll
38+
*.exe
39+
40+
# IDE files
41+
.vscode/
42+
.idea/
43+
*.swp
44+
*.swo
45+
*~
46+
47+
# OS files
48+
.DS_Store
49+
Thumbs.db
50+
51+
# Temporary files
52+
*.tmp
53+
*.temp
54+
/tmp/

0 commit comments

Comments
 (0)