Skip to content

Commit cac0fc7

Browse files
segoonapolukhin
authored andcommitted
feat cmake: add CPM to several depenencies
Partial fix for #1003 Tests: протестировано CI Pull Request resolved: #1004 commit_hash:8259817d03efb23e34ff84e28cd84403b48dd832
1 parent b0fcf81 commit cac0fc7

File tree

10 files changed

+280
-13
lines changed

10 files changed

+280
-13
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Ubuntu
2+
3+
'on':
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- develop
9+
- feature/**
10+
11+
env:
12+
JAVA_HOME: /usr/lib/jvm/java-17-openjdk-amd64
13+
UBSAN_OPTIONS: print_stacktrace=1
14+
ASAN_OPTIONS: detect_odr_violation=2
15+
CCACHE_DIR: /home/runner/.cache/ccache
16+
CCACHE_NOHASHDIR: true
17+
CPM_SOURCE_CACHE: /home/runner/.cache/CPM
18+
REDIS_SLEEP_WORKAROUND_SECONDS: 60
19+
20+
jobs:
21+
posix:
22+
strategy:
23+
fail-fast: false
24+
env:
25+
CMAKE_FLAGS: >-
26+
-DCMAKE_BUILD_TYPE=Debug
27+
-DCMAKE_CXX_STANDARD=17
28+
-DUSERVER_SANITIZE="ub addr"
29+
-DUSERVER_BUILD_SAMPLES=1
30+
-DUSERVER_BUILD_TESTS=1
31+
32+
name: ubuntu (minimal installation)
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Restore cached directories
39+
id: restore-cache
40+
uses: actions/cache/restore@v4
41+
with:
42+
path: |
43+
${{env.CCACHE_DIR}}
44+
${{env.CPM_SOURCE_CACHE}}
45+
key: 'ubuntu-cache-dir ${{matrix.id}} ${{github.ref}} run-${{github.run_number}}'
46+
restore-keys: |
47+
ubuntu-cache-dir ${{matrix.id}} ${{github.ref}}
48+
ubuntu-cache-dir ${{matrix.id}}
49+
50+
- name: Setup ramdrive for testsuites
51+
run: |
52+
sudo mkdir -p "/mnt/ramdisk/$USER"
53+
sudo chmod 777 "/mnt/ramdisk/$USER"
54+
sudo mount -t tmpfs -o size=2048M tmpfs "/mnt/ramdisk/$USER"
55+
56+
- name: Free disk space
57+
run: |
58+
df -h
59+
# See https://stackoverflow.com/questions/75536771/github-runner-out-of-disk-space-after-building-docker-image
60+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /usr/lib/php* /opt/ghc \
61+
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
62+
/opt/hostedtoolcache/CodeQL || true
63+
sudo docker image prune --all --force
64+
df -h
65+
66+
- name: Install common deps
67+
run: |
68+
sudo apt update
69+
sudo apt install build-essential clang cmake ccache libjemalloc-dev
70+
sudo apt install \
71+
libssl-dev \
72+
libboost-context1.83-dev \
73+
libboost-coroutine1.83-dev \
74+
libboost-filesystem1.83-dev \
75+
libboost-iostreams1.83-dev \
76+
libboost-locale1.83-dev \
77+
libboost-program-options1.83-dev \
78+
libboost-stacktrace1.83-dev \
79+
libbenchmark-dev
80+
81+
- name: Setup ccache
82+
run: |
83+
ccache -M 2.0GB
84+
ccache -s -v
85+
86+
- name: Run cmake
87+
run: |
88+
cmake -S . -B build_debug
89+
90+
- name: Compile
91+
run: |
92+
pwd
93+
cd build_debug
94+
cmake --build . -j $(nproc)
95+
96+
- name: Save cached directories
97+
uses: actions/cache/save@v4
98+
with:
99+
path: |
100+
${{env.CCACHE_DIR}}
101+
${{env.CPM_SOURCE_CACHE}}
102+
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
103+
104+
- name: Show cache stats
105+
run: |
106+
du -h -d 1 ${{env.CCACHE_DIR}}
107+
du -h -d 1 ${{env.CPM_SOURCE_CACHE}}
108+
ccache -s -v

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
".github/workflows/publish-ubuntu-22.04-base-images.yaml":"taxi/uservices/userver/.github/workflows/publish-ubuntu-22.04-base-images.yaml",
2222
".github/workflows/publish-ubuntu-22.04-images.yaml":"taxi/uservices/userver/.github/workflows/publish-ubuntu-22.04-images.yaml",
2323
".github/workflows/publish-ubuntu-24.04-images.yaml":"taxi/uservices/userver/.github/workflows/publish-ubuntu-24.04-images.yaml",
24+
".github/workflows/ubuntu-minimal.yml":"taxi/uservices/userver/.github/workflows/ubuntu-minimal.yml",
2425
".gitignore":"taxi/uservices/userver/.gitignore",
2526
"AUTHORS":"taxi/uservices/userver/AUTHORS",
2627
"CMakeLists.txt":"taxi/uservices/userver/CMakeLists.txt",

cmake/ModuleHelpers.cmake

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,46 @@ include_guard(GLOBAL)
33
cmake_policy(SET CMP0054 NEW)
44

55
macro(_userver_module_begin)
6-
set(options)
6+
set(options
7+
CPM_DOWNLOAD_ONLY
8+
)
79
set(oneValueArgs # Target name, also used for package name by default
810
NAME VERSION
911
)
1012
set(multiValueArgs
1113
DEBIAN_NAMES FORMULA_NAMES RPM_NAMES PACMAN_NAMES PKG_NAMES
1214
# For version detection of manually installed packages and unknown package managers.
13-
PKG_CONFIG_NAMES
15+
PKG_CONFIG_NAMES
16+
# For CPM options
17+
CPM_NAME
18+
CPM_VERSION
19+
CPM_GITHUB_REPOSITORY
20+
CPM_URL
21+
CPM_OPTIONS
22+
CPM_SOURCE_SUBDIR
23+
CPM_GIT_TAG
1424
)
1525

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

1828
set(name "${ARG_NAME}")
1929

30+
string(TOUPPER "${ARG_CPM_NAME}" ARG_CPM_NAME)
31+
string(REPLACE "-" "_" ARG_CPM_NAME "${ARG_CPM_NAME}")
32+
33+
if(ARG_CPM_NAME)
34+
option(
35+
USERVER_DOWNLOAD_PACKAGE_${ARG_CPM_NAME}
36+
"Download and setup ${ARG_CPM_NAME} if no library of matching version was found"
37+
${USERVER_DOWNLOAD_PACKAGES}
38+
)
39+
option(
40+
USERVER_FORCE_DOWNLOAD_${ARG_CPM_NAME}
41+
"Download ${ARG_CPM_NAME} even if there is an installed system package"
42+
${USERVER_FORCE_DOWNLOAD_PACKAGES}
43+
)
44+
endif()
45+
2046
if(ARG_VERSION)
2147
if(NOT ${name}_FIND_VERSION OR "${${name}_FIND_VERSION}" VERSION_LESS "${ARG_VERSION}")
2248
set("${name}_FIND_VERSION" "${ARG_VERSION}")
@@ -78,6 +104,12 @@ endmacro()
78104
macro(_userver_module_find_part)
79105
# Also uses ARGs left over from _userver_find_module_begin
80106

107+
# TODO: return() doesn't work inside of macro
108+
# if(USERVER_FORCE_DOWNLOAD_${ARG_CPM_NAME})
109+
# message(STATUS "Skipping ${ARG_CPM_NAME} system package search due to USERVER_FORCE_DOWNLOAD_${ARG_CPM_NAME}=TRUE")
110+
# return()
111+
# endif()
112+
81113
set(options)
82114
set(oneValueArgs PART_TYPE)
83115
set(multiValueArgs NAMES PATHS PATH_SUFFIXES)
@@ -261,12 +293,25 @@ macro(_userver_module_end)
261293
list(APPEND required_vars "${programs_variable}")
262294
endif()
263295
if(required_vars)
264-
find_package_handle_standard_args(
265-
"${current_package_name}"
266-
REQUIRED_VARS ${required_vars}
267-
FAIL_MESSAGE "${FULL_ERROR_MESSAGE}"
268-
)
269-
mark_as_advanced(${required_vars})
296+
foreach(_CURRENT_VAR ${required_vars})
297+
if(NOT ${_CURRENT_VAR})
298+
set(NEED_CPM TRUE)
299+
if(USERVER_DOWNLOAD_PACKAGE_${ARG_CPM_NAME})
300+
set(${_CURRENT_VAR})
301+
endif()
302+
endif()
303+
endforeach()
304+
305+
if(NEED_CPM AND USERVER_DOWNLOAD_PACKAGE_${ARG_CPM_NAME})
306+
_userver_cpm_addpackage("${current_package_name}")
307+
else()
308+
find_package_handle_standard_args(
309+
"${current_package_name}"
310+
REQUIRED_VARS ${required_vars}
311+
FAIL_MESSAGE "${FULL_ERROR_MESSAGE}"
312+
)
313+
mark_as_advanced(${required_vars})
314+
endif()
270315
else()
271316
# Forward to another CMake module, add nice error messages if missing.
272317
set(wrapped_package_name "${current_package_name}")
@@ -323,6 +368,29 @@ macro(_userver_module_end)
323368
endif()
324369
endmacro()
325370

371+
macro(_userver_cpm_addpackage name)
372+
include(DownloadUsingCPM)
373+
374+
set(EXTRA_ARGS)
375+
if(ARG_CPM_DOWNLOAD_ONLY)
376+
set(EXTRA_ARGS ${EXTRA_ARGS} DOWNLOAD_ONLY)
377+
endif()
378+
cpmaddpackage(
379+
NAME ${name}
380+
VERSION ${ARG_CPM_VERSION}
381+
GITHUB_REPOSITORY ${ARG_CPM_GITHUB_REPOSITORY}
382+
URL ${ARG_CPM_URL}
383+
OPTIONS ${ARG_CPM_OPTIONS}
384+
SOURCE_SUBDIR ${ARG_CPM_SOURCE_SUBDIR}
385+
GIT_TAG ${ARG_CPM_GIT_TAG}
386+
${EXTRA_ARGS}
387+
)
388+
if(NOT ARG_CPM_DOWNLOAD_ONLY)
389+
mark_targets_as_system("${${name}_SOURCE_DIR}")
390+
endif()
391+
set(${name}_FOUND 1)
392+
endmacro()
393+
326394
function(_userver_macos_set_default_dir variable command_args)
327395
set(default_value "")
328396
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT DEFINED ${variable})

cmake/modules/Findc-ares.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ _userver_module_begin(
1313
c-ares
1414
PKG_CONFIG_NAMES
1515
libcares
16+
17+
CPM_NAME c-ares
18+
CPM_GITHUB_REPOSITORY c-ares/c-ares
19+
CPM_VERSION 1.34.5
20+
CPM_OPTIONS
21+
"CARES_STATIC ON"
22+
"CARES_SHARED OFF"
23+
"CARES_INSTALL OFF"
24+
"CARES_BUILD_TOOLS OFF"
25+
"CARES_STATIC_PIC ON"
1626
)
1727

1828
_userver_module_find_include(NAMES ares.h)

cmake/modules/Findlibev.cmake

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ _userver_module_begin(
99
libev-devel
1010
PACMAN_NAMES
1111
libev
12+
13+
CPM_NAME libev
14+
CPM_URL http://dist.schmorp.de/libev/libev-4.33.tar.gz
15+
CPM_DOWNLOAD_ONLY
1216
)
1317

1418
_userver_module_find_include(NAMES ev.h libev/ev.h)
@@ -17,6 +21,52 @@ _userver_module_find_library(NAMES ev)
1721

1822
_userver_module_end()
1923

24+
function(_userver_execute_process)
25+
execute_process(
26+
${ARGV}
27+
RESULT_VARIABLE RET
28+
)
29+
if(NOT ("${RET}" EQUAL 0))
30+
message(FATAL_ERROR "Command failed with return code ${RET} (${ARGV})")
31+
endif()
32+
endfunction()
33+
2034
if(NOT TARGET libev::libev)
21-
add_library(libev::libev ALIAS libev)
35+
if(TARGET libev)
36+
add_library(libev::libev ALIAS libev)
37+
elseif(libev_ADDED)
38+
# nghttp2 doesn't use find_package(), but calls find_path() and find_library()
39+
# so we have to provide libev.a at the _configure_ time, not at build time, =(
40+
if(NOT EXISTS ${libev_BINARY_DIR}/.built)
41+
_userver_execute_process(
42+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${libev_SOURCE_DIR} ${libev_BINARY_DIR}
43+
)
44+
_userver_execute_process(
45+
COMMAND ./configure
46+
WORKING_DIRECTORY ${libev_BINARY_DIR}
47+
)
48+
_userver_execute_process(
49+
COMMAND make
50+
WORKING_DIRECTORY ${libev_BINARY_DIR}
51+
)
52+
_userver_execute_process(
53+
COMMAND rm -rf ${libev_BINARY_DIR}/.libs/libev.so
54+
)
55+
_userver_execute_process(
56+
COMMAND touch ${libev_BINARY_DIR}/.built
57+
)
58+
endif()
59+
60+
add_library(libev STATIC IMPORTED)
61+
target_include_directories(libev INTERFACE ${libev_BINARY_DIR})
62+
set_target_properties(libev PROPERTIES IMPORTED_LOCATION ${libev_BINARY_DIR}/.libs/libev.a)
63+
64+
# For nghttp2 installed from CPM
65+
list(APPEND CMAKE_INCLUDE_PATH ${libev_BINARY_DIR})
66+
list(APPEND CMAKE_LIBRARY_PATH ${libev_BINARY_DIR}/.libs)
67+
68+
add_library(libev::libev ALIAS libev)
69+
else()
70+
message(FATAL_ERROR "libev cmake target not found, don't know how to link")
71+
endif()
2272
endif()

cmake/modules/Findlibnghttp2.cmake

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ _userver_module_begin(
77
nghttp2
88
PACMAN_NAMES
99
libnghttp2
10+
11+
CPM_NAME libnghttp2
12+
CPM_GITHUB_REPOSITORY nghttp2/nghttp2
13+
CPM_VERSION 1.66.0
14+
CPM_GIT_TAG v1.66.0
15+
CPM_OPTIONS
16+
"BUILD_STATIC_LIBS ON"
17+
"BUILD_SHARED_LIBS OFF"
18+
"ENABLE_APP OFF"
19+
"ENABLE_EXAMPLES OFF"
1020
)
1121

1222
_userver_module_find_include(NAMES nghttp2/nghttp2.h)
@@ -16,5 +26,11 @@ _userver_module_find_library(NAMES nghttp2)
1626
_userver_module_end()
1727

1828
if(NOT TARGET libnghttp2::nghttp2)
19-
add_library(libnghttp2::nghttp2 ALIAS libnghttp2)
29+
if(TARGET libnghttp2)
30+
add_library(libnghttp2::nghttp2 ALIAS libnghttp2)
31+
elseif(TARGET nghttp2_static)
32+
add_library(libnghttp2::nghttp2 ALIAS nghttp2_static)
33+
else()
34+
message(FATAL_ERROR "libnghttp2{,_static} cmake target not found, don't know how to link")
35+
endif()
2036
endif()

cmake/modules/Findyaml-cpp.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ _userver_module_begin(
77
yaml-cpp
88
PACMAN_NAMES
99
yaml-cpp
10+
11+
CPM_NAME yaml-cpp
12+
CPM_GITHUB_REPOSITORY jbeder/yaml-cpp
13+
CPM_GIT_TAG yaml-cpp-0.7.0
1014
)
1115

1216
_userver_module_find_include(NAMES yaml-cpp/yaml.h yaml-cpp/node.h PATH_SUFFIXES include)

cmake/modules/Findzstd.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ _userver_module_begin(
99
libzstd-dev
1010
PACMAN_NAMES
1111
zstd
12+
13+
# TODO: CPM
1214
)
1315

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

2022
if(NOT TARGET zstd::zstd)
21-
add_library(zstd::zstd ALIAS zstd)
23+
if(TARGET libzstd_static)
24+
add_library(zstd::zstd ALIAS libzstd_static)
25+
else()
26+
add_library(zstd::zstd ALIAS zstd)
27+
endif()
2228
endif()
2329
if(NOT TARGET ZSTD::ZSTD)
2430
add_library(ZSTD::ZSTD ALIAS zstd)

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ find_package(Iconv REQUIRED)
4545
_userver_macos_set_default_dir(OPENSSL_ROOT_DIR "brew;--prefix;openssl")
4646
find_package_required(OpenSSL "libssl-dev")
4747

48-
find_package(libnghttp2 REQUIRED)
4948
find_package(libev REQUIRED)
49+
find_package(libnghttp2 REQUIRED)
5050

5151
if(USERVER_CONAN)
5252
find_package(c-ares REQUIRED)

0 commit comments

Comments
 (0)