Skip to content

Commit

Permalink
Setup github actions based CI
Browse files Browse the repository at this point in the history
  • Loading branch information
elsid committed May 3, 2024
1 parent 3ea1f95 commit a9ef6e2
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 97 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Build
on: push
jobs:
build:
strategy:
matrix:
build_type:
- Release
- Debug

deps:
- os: ubuntu-20.04
compiler: g++-7
compiler_package: g++-7
boost: '1.67'

- os: ubuntu-20.04
compiler: clang++-7
compiler_package: clang-7
boost: '1.67'

- os: ubuntu-22.04
compiler: g++-11
compiler_package: g++-11
boost: '1.74'

- os: ubuntu-22.04
compiler: clang++-15
compiler_package: clang-15
boost: '1.74'

name: Build ${{ matrix.build_type }} ${{ matrix.deps.compiler }} 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 }}-${{ 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 }}
-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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
57 changes: 15 additions & 42 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 14 additions & 55 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a9ef6e2

Please sign in to comment.