Skip to content

Commit

Permalink
Add deb packaging and move to C++17 (#336)
Browse files Browse the repository at this point in the history
* change workflows

* fix container names

* wip

* fix debian packaging

* use venv for python

* static-analysis with submodules

* add array headers

* allow misc-include

* suppress alpine related error

* format

* fix some errors + enable C++17

* 14 -> 17

* nodiscard

* fix compile error

* fix endl

* replace u_long

* fix strerror_r for xsi version

* minor format + add rocky runners

* update

* fix sonarcloud warnings

* update readme

* this should fix alpine

* push more fixes

* use /*unused*/

* include time headers

* add zeromq port

* use revision as version for prom

* const

* use optional

* fix for sonarcloud

* reduce scope

* add rpm packaging

* update codeql build

* add ccache dir
  • Loading branch information
egecetin authored Oct 26, 2024
1 parent 0c4273c commit 38dc3a9
Show file tree
Hide file tree
Showing 35 changed files with 522 additions and 506 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ portability-*,
readability-*,
-clang-diagnostic-unused-command-line-argument,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-vararg,
-modernize-use-trailing-return-type,
-misc-include-cleaner,
-readability-function-cognitive-complexity,
-readability-magic-numbers'

Expand Down
68 changes: 33 additions & 35 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,22 @@ concurrency:
cancel-in-progress: true

jobs:
clang-tidy:
static-analysis:
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
container: egecetinn/alpine
steps:
- name: Checkout Code
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
submodules: recursive
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Configure
run: cmake -S . -B build
- name: Clang-tidy
run: run-clang-tidy -j`nproc` -p=build -header-filter=`pwd`/include/ src/*.cpp src/**/*.cpp

format:
runs-on: ubuntu-latest
container: egecetinn/alpine
steps:
- name: Checkout Code
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Run clang-format
run: clang-format include/**/*.hpp src/*.cpp src/**/*.cpp --verbose --dry-run --Werror
- name: Run cppcheck
run: cppcheck -Iinclude/ src --verbose --enable=all --error-exitcode=1 --std=c++14 --language=c++ --suppressions-list=cppcheckSuppressions.txt --inline-suppr --check-level=exhaustive
run: cppcheck -Iinclude/ src --verbose --enable=all --error-exitcode=1 --std=c++17 --language=c++ --suppressions-list=cppcheckSuppressions.txt --inline-suppr --check-level=exhaustive
- name: Configure for clang-tidy
run: cmake -S . -B build
- name: Clang-tidy
run: run-clang-tidy -j`nproc` -p=build -header-filter=`pwd`/include/ src/*.cpp src/**/*.cpp

memleak:
runs-on: ubuntu-latest
Expand All @@ -62,20 +53,25 @@ jobs:
restore-keys: |
memleak-ccache
- name: Install Test Requirements
run: pip3 install -r tests/data/requirements.txt
run: |
python3 -m venv .venv
. .venv/bin/activate
pip3 install -r tests/data/requirements.txt
- name: Configure
run: cmake -DXXX_ENABLE_MEMLEAK_CHECK=ON -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Run tests
run: ctest --output-on-failure --test-dir build
run: |
. .venv/bin/activate
ctest --output-on-failure --test-dir build
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}

fuzzer:
fuzztests:
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
strategy:
Expand All @@ -98,13 +94,18 @@ jobs:
restore-keys: |
${{ matrix.sanitizer }}-ccache
- name: Install Test Requirements
run: pip3 install -r tests/data/requirements.txt
run: |
python3 -m venv .venv
. .venv/bin/activate
pip3 install -r tests/data/requirements.txt
- name: Configure
run: cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DXXX_BUILD_UNITTESTS=OFF -DXXX_BUILD_FUZZTESTS=ON -DXXX_ENABLE_${{ matrix.sanitizer }}=ON -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Run tests
run: ctest --output-on-failure --test-dir build
run: |
. .venv/bin/activate
ctest --output-on-failure --test-dir build
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
Expand All @@ -117,18 +118,16 @@ jobs:
name: regressions-${{ matrix.sanitizer }}
path: build/tests/fuzztests/crash*

rockylinux:
unittests:
runs-on: ubuntu-latest
container: egecetinn/${{ matrix.image }}
strategy:
matrix:
include:
- image: rockylinux8
- image: rockylinux8-icx
additional-flags: -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
- image: rockylinux9
- image: rockylinux9-icx
additional-flags: -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
- image: ubuntu2204
- image: ubuntu2404

steps:
- name: Checkout Code
Expand All @@ -137,11 +136,6 @@ jobs:
submodules: recursive
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Setup Intel Compiler variables
if: contains(matrix.image, 'icx')
run: |
. /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
- name: Restore ccache
id: ccache-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
Expand All @@ -152,14 +146,18 @@ jobs:
restore-keys: |
${{ matrix.image }}-ccache
- name: Install Test Requirements
run: pip3 install -r tests/data/requirements.txt
run: |
python3 -m venv .venv
. .venv/bin/activate
pip3 install -r tests/data/requirements.txt
- name: Configure
run: cmake ${{ matrix.additional-flags }} -S . -B build
run: cmake -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Run Tests
id: test-step
run: ctest --output-on-failure --test-dir build
run: |
. .venv/bin/activate
ctest --output-on-failure --test-dir build
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
Expand Down
27 changes: 22 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ on:
permissions:
contents: read

env:
CCACHE_DIR: ${{ github.workspace }}/.ccache

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
permissions:
actions: read
contents: read
Expand All @@ -31,14 +35,27 @@ jobs:
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
submodules: recursive
- name: Prepare system
run: |
sudo apt update && sudo apt install libcurl4-openssl-dev -y
- name: Restore ccache
id: ccache-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
${{ env.CCACHE_DIR }}
key: codeql-ccache-${{ github.run_id }}
restore-keys: |
codeql-ccache
- name: Initialize CodeQL
uses: github/codeql-action/init@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
- name: Configure
run: cmake -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
deploy:
permissions:
contents: write # for JamesIves/github-pages-deploy-action to push changes in repo
runs-on: ubuntu-22.04
container: egecetinn/ubuntu2204
runs-on: ubuntu-latest
container: egecetinn/alpine
steps:
- name: Checkout repository
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ doc
tests/data
Testing
.git
.venv
.vscode
.sentry-native

Expand Down
48 changes: 35 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ option(XXX_BUILD_FUZZTESTS "Build XXX fuzz tests" OFF)
option(XXX_ENABLE_COVERAGE "Enables coverage report generation" OFF)
option(XXX_ENABLE_MEMLEAK_CHECK "Enables Memory Leak Checker for unit tests" OFF)
option(XXX_ENABLE_SYMBOL_GENERATION "Enables symbol generation for binaries (Requires breakpad)" OFF)
option(XXX_ENABLE_PACKAGING "Enables RPM packaging" OFF)
option(XXX_ENABLE_PACKAGING "Enables DEB/RPM packaging" OFF)

# Set project properties
set(PROJECT_VERSION_MAJOR 0)
Expand All @@ -31,7 +31,7 @@ set(PROJECT_VERSION_TWEAK ${REVISION_VERSION})
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${REVISION_VERSION}")
message(STATUS "Compiling Version ${PROJECT_VERSION}")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -165,32 +165,54 @@ install(FILES ${CMAKE_BINARY_DIR}/config.json DESTINATION ${CMAKE_INSTALL_PREFIX
if(XXX_ENABLE_PACKAGING)
set(EXE_PATH ${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
set(SERVICE_NAME ${PROJECT_NAME}.service)
set(POST_INSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/postinst.sh)
set(POST_UNINSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/postuninst.sh)
set(PRE_UNINSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/preuninst.sh)
set(POST_INSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/postinst)
set(PRE_UNINSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/prerm)

configure_file(${PROJECT_SOURCE_DIR}/scripts/template.service.in ${CMAKE_CURRENT_BINARY_DIR}/${SERVICE_NAME} @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/scripts/post.sh.in ${POST_INSTALL_SCRIPT})
configure_file(${PROJECT_SOURCE_DIR}/scripts/postun.sh.in ${POST_UNINSTALL_SCRIPT})
configure_file(${PROJECT_SOURCE_DIR}/scripts/preun.sh.in ${PRE_UNINSTALL_SCRIPT})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.service DESTINATION ${CMAKE_INSTALL_PREFIX}/share)
configure_file(${PROJECT_SOURCE_DIR}/scripts/postinst.in ${POST_INSTALL_SCRIPT})
configure_file(${PROJECT_SOURCE_DIR}/scripts/prerm.in ${PRE_UNINSTALL_SCRIPT})

set(CPACK_GENERATOR "RPM")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.service DESTINATION /lib/systemd/system)

set(CPACK_PACKAGE_CONTACT "Ege Cetin <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION "C++ Application Template. It has already integrated a Telnet and ZeroMQ server to \
receive commands, Crashpad handler to generate minidump, a Prometheus server to broadcast performance metrics. \
Also, it can send logs to syslog using Spdlog, to a Sentry server and Grafana Loki instance")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Repository template for C++ applications")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

# Debian package specific parameters
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${POST_INSTALL_SCRIPT};${PRE_UNINSTALL_SCRIPT}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libcurl4 (>= 7.0), libspdlog1 (>= 1.8.0), libzmq5 (>= 4.0.0), systemd")
set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)

# RPM package specific parameters
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_REQUIRES_POSTUN "systemd")
set(CPACK_RPM_PACKAGE_REQUIRES_PREUN "systemd")
set(CPACK_RPM_PACKAGE_REQUIRES_POST "systemd")
set(CPACK_RPM_PACKAGE_REQUIRES "libcurl >= 7.0, spdlog >= 1.8.0, zeromq >= 4.0.0")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${POST_INSTALL_SCRIPT})
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${POST_UNINSTALL_SCRIPT})
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${PRE_UNINSTALL_SCRIPT})

include(CPack)

if(XXX_ENABLE_SYMBOL_GENERATION)
# Create archive from symbols
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar cfvz ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}-syms.tar.gz
--format=gnutar ${CMAKE_BINARY_DIR}/syms
COMMENT "Creating tar gz archive from ${CMAKE_BINARY_DIR}/syms"
)
endif()
endif()

# Enable test framework
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

## Project
CMake template to create new C++ applications with basic codes/interfaces are already defined. Requires a C++14 supported compiler.
CMake template to create new C++ applications with basic codes/interfaces are already defined. Requires a C++17 supported compiler.

It provides the following features
- Tracing
Expand Down Expand Up @@ -90,5 +90,5 @@ Full dependency graph can be seen [here](doc/XXX-tree.svg)
- coverage : Prepares coverage report
- docs : Prepares documentation
- dependency-graph : Prepares graphviz visualization of dependencies
- package : Prepares default packages
- package : Prepares default packages which includes deb/rpm package and symbols with a systemd service. You should specify the desired package type with -DCPACK_GENERATOR="DEB" (or "RPM")
- test : Prepares gtest target
2 changes: 1 addition & 1 deletion include/connection/Http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class HTTP {
* Gets the host address of the object
* @return The host address
*/
const std::string &getHostAddress() const { return _hostAddr; }
[[nodiscard]] const std::string &getHostAddress() const { return _hostAddr; }

/**
* Sends a GET request
Expand Down
2 changes: 1 addition & 1 deletion include/connection/RawSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RawSocket {
* Returns the binded ethernet interface
* @return std::string Name of the interface
*/
const std::string &getInterfaceName() const { return _iFace; }
[[nodiscard]] const std::string &getInterfaceName() const { return _iFace; }

/**
* Writes data to the interface
Expand Down
2 changes: 1 addition & 1 deletion include/logging/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainLogger {
* Returns pointer to mainlogger instance
* @return std::shared_ptr<spdlog::logger> Main logger
*/
std::shared_ptr<spdlog::logger> getLogger() const { return _mainLogger; }
[[nodiscard]] std::shared_ptr<spdlog::logger> getLogger() const { return _mainLogger; }

/**
* Deconstructs the main logger
Expand Down
Loading

0 comments on commit 38dc3a9

Please sign in to comment.