Skip to content
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/ubuntu-minimal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Ubuntu

'on':
pull_request:
push:
branches:
- master
- develop
- feature/**

env:
JAVA_HOME: /usr/lib/jvm/java-17-openjdk-amd64
UBSAN_OPTIONS: print_stacktrace=1
ASAN_OPTIONS: detect_odr_violation=2
CCACHE_DIR: /home/runner/.cache/ccache
CCACHE_NOHASHDIR: true
CPM_SOURCE_CACHE: /home/runner/.cache/CPM
REDIS_SLEEP_WORKAROUND_SECONDS: 60

jobs:
posix:
strategy:
fail-fast: false
env:
CMAKE_FLAGS: >-
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CXX_STANDARD=17
-DUSERVER_SANITIZE="ub addr"
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1

name: ubuntu (minimal installation)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Restore cached directories
id: restore-cache
uses: actions/cache/restore@v4
with:
path: |
${{env.CCACHE_DIR}}
${{env.CPM_SOURCE_CACHE}}
key: 'ubuntu-cache-dir ${{matrix.id}} ${{github.ref}} run-${{github.run_number}}'
restore-keys: |
ubuntu-cache-dir ${{matrix.id}} ${{github.ref}}
ubuntu-cache-dir ${{matrix.id}}

- name: Setup ramdrive for testsuites
run: |
sudo mkdir -p "/mnt/ramdisk/$USER"
sudo chmod 777 "/mnt/ramdisk/$USER"
sudo mount -t tmpfs -o size=2048M tmpfs "/mnt/ramdisk/$USER"

- name: Free disk space
run: |
df -h
# See https://stackoverflow.com/questions/75536771/github-runner-out-of-disk-space-after-building-docker-image
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /usr/lib/php* /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/opt/hostedtoolcache/CodeQL || true
sudo docker image prune --all --force
df -h

- name: Install common deps
run: |
sudo apt update
sudo apt install build-essential clang cmake ccache libjemalloc-dev
sudo apt install \
libssl-dev \
libboost-context1.83-dev \
libboost-coroutine1.83-dev \
libboost-filesystem1.83-dev \
libboost-iostreams1.83-dev \
libboost-locale1.83-dev \
libboost-program-options1.83-dev \
libboost-stacktrace1.83-dev \
libbenchmark-dev

- name: Setup ccache
run: |
ccache -M 2.0GB
ccache -s -v

- name: Run cmake
run: |
cmake -S . -B build_debug

- name: Compile
run: |
pwd
cd build_debug
cmake --build . -j $(nproc)

- name: Save cached directories
uses: actions/cache/save@v4
with:
path: |
${{env.CCACHE_DIR}}
${{env.CPM_SOURCE_CACHE}}
key: ${{ steps.restore-cache.outputs.cache-primary-key }}

- name: Show cache stats
run: |
du -h -d 1 ${{env.CCACHE_DIR}}
du -h -d 1 ${{env.CPM_SOURCE_CACHE}}
ccache -s -v
84 changes: 76 additions & 8 deletions cmake/ModuleHelpers.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
include_guard(GLOBAL)

include(DownloadUsingCPM)

cmake_policy(SET CMP0054 NEW)

macro(_userver_module_begin)
set(options)
set(options
CPM_DOWNLOAD_ONLY
)
set(oneValueArgs # Target name, also used for package name by default
NAME VERSION
)
set(multiValueArgs
DEBIAN_NAMES FORMULA_NAMES RPM_NAMES PACMAN_NAMES PKG_NAMES
# For version detection of manually installed packages and unknown package managers.
PKG_CONFIG_NAMES
PKG_CONFIG_NAMES
# For CPM options
CPM_NAME
CPM_VERSION
CPM_GITHUB_REPOSITORY
CPM_URL
CPM_OPTIONS
CPM_SOURCE_SUBDIR
CPM_GIT_TAG
)

cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")

set(name "${ARG_NAME}")

string(TOUPPER "${ARG_CPM_NAME}" ARG_CPM_NAME)
string(REPLACE "-" "_" ARG_CPM_NAME "${ARG_CPM_NAME}")

if(ARG_CPM_NAME)
option(
USERVER_DOWNLOAD_PACKAGE_${ARG_CPM_NAME}
"Download and setup ${ARG_CPM_NAME} if no library of matching version was found"
${USERVER_DOWNLOAD_PACKAGES}
)
option(
USERVER_FORCE_DOWNLOAD_${ARG_CPM_NAME}
"Download ${ARG_CPM_NAME} even if there is an installed system package"
${USERVER_FORCE_DOWNLOAD_PACKAGES}
)
endif()

if(ARG_VERSION)
if(NOT ${name}_FIND_VERSION OR "${${name}_FIND_VERSION}" VERSION_LESS "${ARG_VERSION}")
set("${name}_FIND_VERSION" "${ARG_VERSION}")
Expand Down Expand Up @@ -78,6 +106,12 @@ endmacro()
macro(_userver_module_find_part)
# Also uses ARGs left over from _userver_find_module_begin

# TODO: return() doesn't work inside of macro
# if(USERVER_FORCE_DOWNLOAD_${ARG_CPM_NAME})
# message(STATUS "Skipping ${ARG_CPM_NAME} system package search due to USERVER_FORCE_DOWNLOAD_${ARG_CPM_NAME}=TRUE")
# return()
# endif()

set(options)
set(oneValueArgs PART_TYPE)
set(multiValueArgs NAMES PATHS PATH_SUFFIXES)
Expand Down Expand Up @@ -261,12 +295,25 @@ macro(_userver_module_end)
list(APPEND required_vars "${programs_variable}")
endif()
if(required_vars)
find_package_handle_standard_args(
"${current_package_name}"
REQUIRED_VARS ${required_vars}
FAIL_MESSAGE "${FULL_ERROR_MESSAGE}"
)
mark_as_advanced(${required_vars})
foreach(_CURRENT_VAR ${required_vars})
if(NOT ${_CURRENT_VAR})
set(NEED_CPM TRUE)
if(USERVER_DOWNLOAD_PACKAGE_${ARG_CPM_NAME})
set(${_CURRENT_VAR})
endif()
endif()
endforeach()

if(NEED_CPM AND USERVER_DOWNLOAD_PACKAGE_${ARG_CPM_NAME})
_userver_cpm_addpackage("${current_package_name}")
else()
find_package_handle_standard_args(
"${current_package_name}"
REQUIRED_VARS ${required_vars}
FAIL_MESSAGE "${FULL_ERROR_MESSAGE}"
)
mark_as_advanced(${required_vars})
endif()
else()
# Forward to another CMake module, add nice error messages if missing.
set(wrapped_package_name "${current_package_name}")
Expand Down Expand Up @@ -323,6 +370,27 @@ macro(_userver_module_end)
endif()
endmacro()

macro(_userver_cpm_addpackage name)
set(EXTRA_ARGS)
if(ARG_CPM_DOWNLOAD_ONLY)
set(EXTRA_ARGS ${EXTRA_ARGS} DOWNLOAD_ONLY)
endif()
cpmaddpackage(
NAME ${name}
VERSION ${ARG_CPM_VERSION}
GITHUB_REPOSITORY ${ARG_CPM_GITHUB_REPOSITORY}
URL ${ARG_CPM_URL}
OPTIONS ${ARG_CPM_OPTIONS}
SOURCE_SUBDIR ${ARG_CPM_SOURCE_SUBDIR}
GIT_TAG ${ARG_CPM_GIT_TAG}
${EXTRA_ARGS}
)
if(NOT ARG_CPM_DOWNLOAD_ONLY)
mark_targets_as_system("${${name}_SOURCE_DIR}")
endif()
set(${name}_FOUND 1)
endmacro()

function(_userver_macos_set_default_dir variable command_args)
set(default_value "")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT DEFINED ${variable})
Expand Down
10 changes: 10 additions & 0 deletions cmake/modules/Findc-ares.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ _userver_module_begin(
c-ares
PKG_CONFIG_NAMES
libcares

CPM_NAME c-ares
CPM_GITHUB_REPOSITORY c-ares/c-ares
CPM_VERSION 1.34.5
CPM_OPTIONS
"CARES_STATIC ON"
"CARES_SHARED OFF"
"CARES_INSTALL OFF"
"CARES_BUILD_TOOLS OFF"
"CARES_STATIC_PIC ON"
)

_userver_module_find_include(NAMES ares.h)
Expand Down
37 changes: 36 additions & 1 deletion cmake/modules/Findlibev.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ _userver_module_begin(
libev-devel
PACMAN_NAMES
libev

CPM_NAME libev
CPM_URL http://dist.schmorp.de/libev/libev-4.33.tar.gz
CPM_DOWNLOAD_ONLY
)

_userver_module_find_include(NAMES ev.h libev/ev.h)
Expand All @@ -18,5 +22,36 @@ _userver_module_find_library(NAMES ev)
_userver_module_end()

if(NOT TARGET libev::libev)
add_library(libev::libev ALIAS libev)
if(TARGET libev)
add_library(libev::libev ALIAS libev)
elseif(libev_ADDED)
# nghttp2 doesn't use find_package(), but calls find_path() and find_library()
# so we have to provide libev.a at the _configure_ time, not at build time, =(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it also necessary to build a fresh copy of libev on each reconfigure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_directory ${libev_SOURCE_DIR} ${libev_BINARY_DIR}
)
execute_process(
COMMAND ./configure
WORKING_DIRECTORY ${libev_BINARY_DIR}
)
execute_process(
COMMAND make
WORKING_DIRECTORY ${libev_BINARY_DIR}
)
execute_process(
COMMAND rm -rf ${libev_BINARY_DIR}/.libs/libev.so
)

add_library(libev STATIC IMPORTED)
target_include_directories(libev INTERFACE ${libev_BINARY_DIR})
set_target_properties(libev PROPERTIES IMPORTED_LOCATION ${libev_BINARY_DIR}/.libs/libev.a)

# For nghttp2 installed from CPM
list(APPEND CMAKE_INCLUDE_PATH ${libev_BINARY_DIR})
list(APPEND CMAKE_LIBRARY_PATH ${libev_BINARY_DIR}/.libs)

add_library(libev::libev ALIAS libev)
else()
message(FATAL_ERROR "libev cmake target not found, don't know how to link")
endif()
endif()
18 changes: 17 additions & 1 deletion cmake/modules/Findlibnghttp2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ _userver_module_begin(
nghttp2
PACMAN_NAMES
libnghttp2

CPM_NAME libnghttp2
CPM_GITHUB_REPOSITORY nghttp2/nghttp2
CPM_VERSION 1.66.0
CPM_GIT_TAG v1.66.0
CPM_OPTIONS
"BUILD_STATIC_LIBS ON"
"BUILD_SHARED_LIBS OFF"
"ENABLE_APP OFF"
"ENABLE_EXAMPLES OFF"
)

_userver_module_find_include(NAMES nghttp2/nghttp2.h)
Expand All @@ -16,5 +26,11 @@ _userver_module_find_library(NAMES nghttp2)
_userver_module_end()

if(NOT TARGET libnghttp2::nghttp2)
add_library(libnghttp2::nghttp2 ALIAS libnghttp2)
if(TARGET libnghttp2)
add_library(libnghttp2::nghttp2 ALIAS libnghttp2)
elseif(TARGET nghttp2_static)
add_library(libnghttp2::nghttp2 ALIAS nghttp2_static)
else()
message(FATAL_ERROR "libnghttp2{,_static} cmake target not found, don't know how to link")
endif()
endif()
4 changes: 4 additions & 0 deletions cmake/modules/Findyaml-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ _userver_module_begin(
yaml-cpp
PACMAN_NAMES
yaml-cpp

CPM_NAME yaml-cpp
CPM_GITHUB_REPOSITORY jbeder/yaml-cpp
CPM_GIT_TAG yaml-cpp-0.7.0
)

_userver_module_find_include(NAMES yaml-cpp/yaml.h yaml-cpp/node.h PATH_SUFFIXES include)
Expand Down
8 changes: 7 additions & 1 deletion cmake/modules/Findzstd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ _userver_module_begin(
libzstd-dev
PACMAN_NAMES
zstd

# TODO: CPM
)

_userver_module_find_include(NAMES zdict.h zstd.h zstd_errors.h PATH_SUFFIXES include)
Expand All @@ -18,7 +20,11 @@ _userver_module_find_library(NAMES zstd PATH_SUFFIXES lib)
_userver_module_end()

if(NOT TARGET zstd::zstd)
add_library(zstd::zstd ALIAS zstd)
if(TARGET libzstd_static)
add_library(zstd::zstd ALIAS libzstd_static)
else()
add_library(zstd::zstd ALIAS zstd)
endif()
endif()
if(NOT TARGET ZSTD::ZSTD)
add_library(ZSTD::ZSTD ALIAS zstd)
Expand Down
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ find_package(Iconv REQUIRED)
_userver_macos_set_default_dir(OPENSSL_ROOT_DIR "brew;--prefix;openssl")
find_package_required(OpenSSL "libssl-dev")

find_package(libnghttp2 REQUIRED)
find_package(libev REQUIRED)
find_package(libnghttp2 REQUIRED)

if(USERVER_CONAN)
find_package(c-ares REQUIRED)
Expand Down
Loading