From f15a30d827a739cac15a057721f17325193204b3 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 3 May 2024 23:27:29 +0200 Subject: [PATCH] Setup github actions based CI --- .github/workflows/build.yaml | 94 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 + benchmarks/CMakeLists.txt | 57 ++++++---------------- tests/CMakeLists.txt | 69 ++++++-------------------- 4 files changed, 125 insertions(+), 97 deletions(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..fe4baf8 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,94 @@ +name: Build +on: push +jobs: + build: + strategy: + matrix: + build_type: + - Release + - Debug + + deps: + - os: ubuntu-20.04 + compiler: + - binary: g++-7 + package: g++-7 + - binary: clang++-7 + package: clang-7 + boost: '1.67' + + - os: ubuntu-22.04 + compiler: + - binary: g++-11 + package: g++-11 + - binary: clang++-15 + package: clang-15 + boost: '1.74' + + name: Build ${{ matrix.build_type }} ${{ matrix.deps.compiler.binary }} boost ${{ matrix.deps.boost }} ${{ matrix.deps.os }} + runs-on: ${{ matrix.deps.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Update apt-get + run: sudo apt-get update + + - name: Install apt packages for dependencies + run: > + sudo apt-get install -y --no-install-recommends + ccache + cmake + libboost-atomic${{ matrix.deps.boost }}-dev + libboost-context${{ matrix.deps.boost }}-dev + libboost-coroutine${{ matrix.deps.boost }}-dev + libboost-date-time${{ matrix.deps.boost }}-dev + libboost-thread${{ matrix.deps.boost }}-dev + ninja-build + ${{ matrix.deps.compiler.package }} + + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1 + with: + key: ${{ matrix.deps.os }}-${{ matrix.deps.compiler.binary }}-${{ matrix.deps.boost }}-${{ matrix.build_type }} + max-size: 1G + + - name: Configure + run: > + cmake + -B build + -S . + -G Ninja + -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} + -D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/install + -D CMAKE_CXX_COMPILER=${{ matrix.deps.compiler.binary }} + -D CMAKE_CXX_COMPILER_LAUNCHER=ccache + -D RESOURCE_POOL_BUILD_TESTS=ON + -D RESOURCE_POOL_BUILD_EXAMPLES=ON + -D RESOURCE_POOL_BUILD_BENCHMARKS=ON + -D RESOURCE_POOL_USE_SYSTEM_GOOGLETEST=OFF + -D RESOURCE_POOL_USE_SYSTEM_BENCHMARK=OFF + + - name: Build + run: cmake --build build + + - name: Install + run: cmake --install build + + - name: Run tests + run: build/tests/resource_pool_test + + - name: Run benchmark + run: build/benchmarks/resource_pool_benchmark_async + + - name: Run async_pool example + run: build/examples/async_pool + + - name: Run async_strand example + run: build/examples/async_strand + + - name: Run coro_pool example + run: build/examples/coro_pool + + - name: Run sync_pool example + run: build/examples/sync_pool diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c57343..917d27b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(resource_pool VERSION 0.1.0 LANGUAGES CXX) option(RESOURCE_POOL_BUILD_EXAMPLES OFF) option(RESOURCE_POOL_BUILD_TESTS OFF) option(RESOURCE_POOL_BUILD_BENCHMARKS OFF) +option(RESOURCE_POOL_USE_SYSTEM_GOOGLETEST OFF) +option(RESOURCE_POOL_USE_SYSTEM_BENCHMARK OFF) add_subdirectory(include) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index cdcaa55..a02493d 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -6,55 +6,28 @@ include_directories(SYSTEM ${RESOURCE_POOL_DEPENDENCY_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}/include) find_package(Boost COMPONENTS coroutine context REQUIRED) -find_package(benchmark) - -if(NOT TARGET google_benchmark AND NOT benchmark_FOUND) - include(ExternalProject) - - set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/external) - - if(NOT GOOGLE_BENCHMARK_REPOSITORY) - if(NOT DEFINED ENV{GOOGLE_BENCHMARK_REPOSITORY}) - set(GOOGLE_BENCHMARK_REPOSITORY https://github.com/google/benchmark.git) - else() - set(GOOGLE_BENCHMARK_REPOSITORY $ENV{GOOGLE_BENCHMARK_REPOSITORY}) - endif() - endif() - - ExternalProject_Add( - google_benchmark - GIT_REPOSITORY ${GOOGLE_BENCHMARK_REPOSITORY} - TIMEOUT 1 - CONFIGURE_COMMAND cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=OFF ../google_benchmark - INSTALL_COMMAND "" - UPDATE_COMMAND "" - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON - ) - - ExternalProject_Get_Property(google_benchmark source_dir) - include_directories(SYSTEM ${source_dir}/include) - - ExternalProject_Get_Property(google_benchmark binary_dir) - link_directories(${binary_dir}/src) -endif() -if(benchmark_FOUND) - include_directories(SYSTEM ${benchmark_INCLUDE_DIRS}) - get_filename_component(_BENCHMARK_LIB_DIR ${benchmark_LIBRARIES} PATH) - link_directories(${_BENCHMARK_LIB_DIR}) +if(RESOURCE_POOL_USE_SYSTEM_BENCHMARK) + find_package(benchmark) +else() + set(BENCHMARK_ENABLE_TESTING OFF) + set(BENCHMARK_ENABLE_INSTALL OFF) + set(BENCHMARK_ENABLE_GTEST_TESTS OFF) + + include(FetchContent) + FetchContent_Declare(benchmark + URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip + URL_HASH SHA512=d73587ad9c49338749e1d117a6f8c7ff9c603a91a2ffa91a7355c7df7dea82710b9a810d34ddfef20973ecdc77092ec10fb2b4e4cc8d2e7810cbed79617b3828 + SOURCE_DIR fetched/benchmark + ) + FetchContent_MakeAvailable(benchmark) endif() add_executable(resource_pool_benchmark_async async.cc) -if(TARGET google_benchmark) - add_dependencies(resource_pool_benchmark_async google_benchmark) -endif() - set(LIBRARIES pthread - benchmark + benchmark::benchmark Boost::coroutine Boost::context elsid::resource_pool diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3744cde..629bb4d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,59 +10,22 @@ include_directories(SYSTEM ${RESOURCE_POOL_DEPENDENCY_INCLUDE_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/include) -find_package(GTest) -find_package(GMock) - -if(NOT TARGET googletest AND (NOT GTEST_FOUND OR NOT GMOCK_FOUND)) - include(ExternalProject) - - set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/external) - - if(NOT GOOGLETEST_REPOSITORY) - if(NOT DEFINED ENV{GOOGLETEST_REPOSITORY}) - set(GOOGLETEST_REPOSITORY https://github.com/google/googletest.git) - else() - set(GOOGLETEST_REPOSITORY $ENV{GOOGLETEST_REPOSITORY}) - endif() - endif() - - ExternalProject_Add( - googletest - GIT_REPOSITORY ${GOOGLETEST_REPOSITORY} - GIT_TAG release-1.10.0 - TIMEOUT 1 - CONFIGURE_COMMAND cmake - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/lib - ../googletest - UPDATE_COMMAND "" - LOG_DOWNLOAD ON - LOG_CONFIGURE ON - LOG_BUILD ON - ) -endif() - -if (GTEST_FOUND AND GMOCK_FOUND) - include_directories(SYSTEM ${GTEST_INCLUDE_DIRS}) - include_directories(SYSTEM ${GMOCK_INCLUDE_DIRS}) - get_filename_component(_GOOGLETEST_LIB_DIR ${GMOCK_MAIN_LIBRARY} PATH) +if(RESOURCE_POOL_USE_SYSTEM_GOOGLETEST) + find_package(GTest) + find_package(GMock) else() - include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/include) - - set(_GOOGLETEST_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib) - - set(GTEST_LIBRARIES ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a) - set(GTEST_MAIN_LIBRARY ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a) - set(GTEST_BOTH_LIBRARIES "${GTEST_LIBRARIES};${GTEST_MAIN_LIBRARY}") + include(FetchContent) + FetchContent_Declare(googletest + URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip + URL_HASH SHA512=1479ea2f3172c622c0ca305f5b2bc45a42941221ec0ac7865e6d6d020ec4d008d952fc64e01a4c5138d7bed4148cf75596f25bb9e9044a98bbbf5662053ea11c + SOURCE_DIR fetched/googletest + ) + FetchContent_MakeAvailable(googletest) - set(GMOCK_LIBRARIES ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock.a) - set(GMOCK_MAIN_LIBRARY ${_GOOGLETEST_LIB_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock_main.a) - set(GMOCK_BOTH_LIBRARIES "${GMOCK_LIBRARIES};${GMOCK_MAIN_LIBRARY}") + add_library(GTest::GTest ALIAS gtest) + add_library(GMock::GMock ALIAS gmock) endif() -link_directories(${_GOOGLETEST_LIB_DIR}) - add_executable(resource_pool_test main.cc error.cc @@ -76,14 +39,10 @@ add_executable(resource_pool_test async/integration.cc ) -if(TARGET googletest) - add_dependencies(resource_pool_test googletest) -endif() - set(LIBRARIES pthread - gtest - gmock + GTest::GTest + GMock::GMock Boost::coroutine Boost::context elsid::resource_pool