Skip to content

Add comprehensive C++ SDK implementation guidelines #22

Add comprehensive C++ SDK implementation guidelines

Add comprehensive C++ SDK implementation guidelines #22

Workflow file for this run

name: C++ SDK CI
on:
push:
branches: [ main, develop ]
paths:
- 'cpp_sdk/**'
- '.github/workflows/cpp_sdk.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'cpp_sdk/**'
- '.github/workflows/cpp_sdk.yml'
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build-type: [Debug, Release]
compiler: [gcc, clang, msvc]
exclude:
- os: windows-latest
compiler: gcc
- os: macos-latest
compiler: gcc
- os: ubuntu-latest
compiler: msvc
- os: macos-latest
compiler: msvc
steps:
- uses: actions/checkout@v4
- name: Install libsodium
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y cmake ninja-build pkg-config valgrind
if [ "${{ matrix.compiler }}" = "clang" ]; then
sudo apt-get install -y clang-15
echo "CC=clang-15" >> $GITHUB_ENV
echo "CXX=clang++-15" >> $GITHUB_ENV
fi
- name: Install dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install cmake ninja libsodium pkg-config lcov
BREW_PREFIX=$(brew --prefix)
echo "PKG_CONFIG_PATH=${BREW_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}" >> $GITHUB_ENV
echo "CMAKE_PREFIX_PATH=${BREW_PREFIX}:${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
echo "LIBRARY_PATH=${BREW_PREFIX}/lib:${LIBRARY_PATH}" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=${BREW_PREFIX}/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
echo "DYLD_LIBRARY_PATH=${BREW_PREFIX}/lib:${DYLD_LIBRARY_PATH}" >> $GITHUB_ENV
if [ "${{ matrix.compiler }}" = "clang" ]; then
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
fi
- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install cmake ninja pkgconfiglite
vcpkg install libsodium:x64-windows pkgconf:x64-windows
echo "CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV
echo "PKG_CONFIG_PATH=C:/vcpkg/installed/x64-windows/lib/pkgconfig" >> $env:GITHUB_ENV
if ("${{ matrix.compiler }}" -eq "msvc") {
echo "Using MSVC compiler"
} else {
echo "Using Clang compiler"
}
- name: Install Google Test (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib
- name: Install Google Test (macOS)
if: matrix.os == 'macos-latest'
run: |
git clone https://github.com/google/googletest.git
cd googletest
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
cmake --build . --config ${{ matrix.build-type }}
sudo cmake --install . --config ${{ matrix.build-type }}
- name: Install Google Test (Windows)
if: matrix.os == 'windows-latest'
run: |
git clone https://github.com/google/googletest.git
cd googletest
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_TOOLCHAIN_FILE=$env:CMAKE_TOOLCHAIN_FILE
cmake --build . --config ${{ matrix.build-type }}
cmake --install . --config ${{ matrix.build-type }}
- name: Configure CMake
run: |
cd cpp_sdk
mkdir build && cd build
if [[ "${{ matrix.compiler }}" == "msvc" ]]; then
cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DENABLE_SANITIZERS=ON -DCMAKE_TOOLCHAIN_FILE=${{ env.CMAKE_TOOLCHAIN_FILE }}
else
cmake .. -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DENABLE_SANITIZERS=ON
fi
shell: bash
env:
CI: true
- name: Build
run: |
cd cpp_sdk/build
if [[ "${{ matrix.compiler }}" == "msvc" ]]; then
cmake --build . --config ${{ matrix.build-type }}
else
ninja
fi
shell: bash
- name: Run tests
run: |
cd cpp_sdk/build
ctest --verbose --output-on-failure
- name: Generate coverage report (Debug builds only)
if: matrix.build-type == 'Debug'
run: |
cd cpp_sdk/build
ninja coverage
- name: Upload coverage to Codecov
if: matrix.build-type == 'Debug' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v4
with:
file: ./cpp_sdk/build/coverage.info
flags: cpp_sdk
name: cpp-sdk-coverage
fail_ci_if_error: true
memory-safety:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Clean build directories
run: |
cd cpp_sdk
rm -rf build-asan build-valgrind
- name: Install libsodium
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
- name: Install dependencies
run: |
sudo apt-get install -y cmake ninja-build pkg-config valgrind clang-15
echo "CC=clang-15" >> $GITHUB_ENV
echo "CXX=clang++-15" >> $GITHUB_ENV
- name: Install Google Test
run: |
sudo apt-get install -y libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib
- name: Configure with AddressSanitizer
run: |
cd cpp_sdk
mkdir -p build-asan && cd build-asan
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON
- name: Build with AddressSanitizer
run: |
cd cpp_sdk/build-asan
ninja
- name: Test with AddressSanitizer
run: |
cd cpp_sdk/build-asan
ninja test-sanitizers
- name: Configure with Valgrind
run: |
cd cpp_sdk
mkdir -p build-valgrind && cd build-valgrind
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_VALGRIND=ON
- name: Build with Valgrind
run: |
cd cpp_sdk/build-valgrind
ninja
- name: Test with Valgrind
run: |
cd cpp_sdk/build-valgrind
ninja test-valgrind
static-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install libsodium
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
- name: Install dependencies
run: |
sudo apt-get install -y cmake ninja-build pkg-config clang-15 clang-tidy-15 clang-format-15 # Add clang-format-15 here
echo "CC=clang-15" >> $GITHUB_ENV
echo "CXX=clang++-15" >> $GITHUB_ENV
- name: Install Google Test
run: |
sudo apt-get install -y libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib
- name: Configure
run: |
cd cpp_sdk
mkdir build && cd build
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Run clang-tidy
run: |
cd cpp_sdk
clang-tidy-15 src/*.cpp -p build/ --warnings-as-errors=*
- name: Run clang-format check
run: |
cd cpp_sdk
find . -name "*.cpp" -o -name "*.hpp" | grep -v "^./build" | xargs clang-format-15 --dry-run --Werror
documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install libsodium
run: sudo apt-get update && sudo apt-get install -y libsodium-dev lcov
- name: Install dependencies
run: |
sudo apt-get install -y doxygen graphviz libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib
- name: Generate documentation
run: |
cd cpp_sdk
mkdir build && cd build
cmake .. -GNinja
ninja docs
- name: Upload documentation
uses: actions/upload-artifact@v4
with:
name: cpp-sdk-docs
path: cpp_sdk/build/docs/html/