Skip to content

Commit

Permalink
feat cmake: re2 by default
Browse files Browse the repository at this point in the history
------------------------
Note: by creating a PR or an issue you automatically agree to the CLA. See [CONTRIBUTING.md](https://github.com/userver-framework/userver/blob/develop/CONTRIBUTING.md). Feel free to remove this note, the agreement holds.

Tests: протестировано CI
Pull Request resolved: #832

Co-authored-by: fdr400 <[email protected]>
commit_hash:873a68f1602d75dbca25964f23ca62411ceed2c4
  • Loading branch information
fdr400 committed Jan 20, 2025
1 parent 39f5100 commit bbf5a29
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
-DUSERVER_FEATURE_PATCH_LIBPQ=OFF \
-DUSERVER_DOWNLOAD_PACKAGE_PROTOBUF=ON \
-DUSERVER_DISABLE_RSEQ_ACCELERATION=YES \
-DUSERVER_FORCE_DOWNLOAD_RE2=1 \
-DUSERVER_FORCE_DOWNLOAD_ABSEIL=1 \
-DUSERVER_FORCE_DOWNLOAD_PROTOBUF=1 \
-DUSERVER_FORCE_DOWNLOAD_GRPC=1 \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
-DUSERVER_FEATURE_REDIS_HI_MALLOC=1
-DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0
-DUSERVER_USE_LD=lld
-DUSERVER_FORCE_DOWNLOAD_RE2=1
-DUSERVER_FORCE_DOWNLOAD_ABSEIL=1
-DUSERVER_FORCE_DOWNLOAD_PROTOBUF=1
-DUSERVER_FORCE_DOWNLOAD_GRPC=1
Expand Down
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@
"cmake/SetupPostgresqlDeps.cmake":"taxi/uservices/userver/cmake/SetupPostgresqlDeps.cmake",
"cmake/SetupProtobuf.cmake":"taxi/uservices/userver/cmake/SetupProtobuf.cmake",
"cmake/SetupRdKafka.cmake":"taxi/uservices/userver/cmake/SetupRdKafka.cmake",
"cmake/SetupRe2.cmake":"taxi/uservices/userver/cmake/SetupRe2.cmake",
"cmake/SetupRocksDB.cmake":"taxi/uservices/userver/cmake/SetupRocksDB.cmake",
"cmake/SetupYdbCppSDK.cmake":"taxi/uservices/userver/cmake/SetupYdbCppSDK.cmake",
"cmake/Stacktrace.cmake":"taxi/uservices/userver/cmake/Stacktrace.cmake",
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0028 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

project(userver)
Expand Down
5 changes: 2 additions & 3 deletions cmake/SetupGrpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ CPMAddPackage(
"gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF"
"gRPC_BUILD_GRPC_PHP_PLUGIN OFF"
"gRPC_BUILD_GRPC_RUBY_PLUGIN OFF"
"gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF"
"gRPC_ZLIB_PROVIDER package"
"gRPC_CARES_PROVIDER package"
# TODO if we ever decide to use re2 ourselves, this will be a conflict
# TODO should use 'package' and download it using CPM instead
"gRPC_RE2_PROVIDER module"
"gRPC_RE2_PROVIDER package"
"gRPC_SSL_PROVIDER package"
"gRPC_PROTOBUF_PROVIDER package"
"gRPC_BENCHMARK_PROVIDER none"
Expand Down
1 change: 0 additions & 1 deletion cmake/SetupPostgresqlDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ _userver_macos_set_default_dir(USERVER_PG_INCLUDE_DIR "pg_config;--includedir")
_userver_macos_set_default_dir(USERVER_PG_LIBRARY_DIR "pg_config;--libdir")
_userver_macos_set_default_dir(USERVER_PG_SERVER_INCLUDE_DIR "pg_config;--includedir-server")
_userver_macos_set_default_dir(USERVER_PG_SERVER_LIBRARY_DIR "pg_config;--pkglibdir")
_userver_macos_set_default_dir(OPENSSL_ROOT_DIR "brew;--prefix;openssl")

# We need libldap to statically link with libpq
# There is no FindLdap.cmake and no package config files
Expand Down
30 changes: 30 additions & 0 deletions cmake/SetupRe2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
option(USERVER_DOWNLOAD_PACKAGE_RE2 "Download and setup Re2 if no Re2 matching version was found" ${USERVER_DOWNLOAD_PACKAGES})
option(USERVER_FORCE_DOWNLOAD_RE2 "Download Re2 even if it exists in a system" ${USERVER_FORCE_DOWNLOAD_PACKAGES})

if(NOT USERVER_FORCE_DOWNLOAD_RE2)
if(USERVER_DOWNLOAD_PACKAGE_RE2)
find_package(re2 QUIET)
else()
find_package(re2 REQUIRED)
endif()

if(re2_FOUND)
return()
endif()
endif()

include(DownloadUsingCPM)

CPMAddPackage(
NAME re2
VERSION 2023-03-01 # newest version without abseil requirements
GIT_TAG 2023-03-01
GITHUB_REPOSITORY google/re2
SYSTEM
OPTIONS
"RE2_BUILD_TESTING OFF"
"RE2_USE_ICU ON"
)

mark_targets_as_system("${re2_SOURCE_DIR}")
write_package_stub(re2)
1 change: 1 addition & 0 deletions cmake/install/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(USERVER_TESTSUITE_DIR "${USERVER_CMAKE_DIR}/testsuite")
set(USERVER_CONAN @USERVER_CONAN@)
set(USERVER_IMPL_ORIGINAL_CXX_STANDARD @CMAKE_CXX_STANDARD@)
set(USERVER_IMPL_FEATURE_JEMALLOC @USERVER_FEATURE_JEMALLOC@)
set(USERVER_IMPL_FEATURE_RE2 @USERVER_FEATURE_RE2@)
set(USERVER_USE_STATIC_LIBS @USERVER_USE_STATIC_LIBS@)

set_property(GLOBAL PROPERTY userver_cmake_dir "${USERVER_CMAKE_DIR}")
Expand Down
8 changes: 8 additions & 0 deletions cmake/install/userver-universal-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ if (USERVER_IMPL_FEATURE_JEMALLOC AND
endif()
endif()

if(USERVER_IMPL_FEATURE_RE2)
if(USERVER_CONAN)
find_package(re2 REQUIRED CONFIG)
else()
find_package(re2 REQUIRED)
endif()
endif()

if (USERVER_CONAN)
find_package(cryptopp REQUIRED CONFIG)
find_package(yaml-cpp REQUIRED CONFIG)
Expand Down
6 changes: 5 additions & 1 deletion cmake/modules/Findre2.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
if(TARGET re2::re2)
return()
endif()

_userver_module_begin(
NAME re2
VERSION 20180101
DEBIAN_NAMES libre2-dev
FORMULA_NAMES re2
RPM_NAMES re2
PACMAN_NAMES re2
PKG_CONFIG_NAMES dev-libs/re2
PKG_CONFIG_NAMES re2
)

_userver_module_find_include(
Expand Down
7 changes: 7 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class UserverConan(ConanFile):
'fPIC': [True, False],
'lto': [True, False],
'with_jemalloc': [True, False],
'with_re2': [True, False],
'with_mongodb': [True, False],
'with_postgresql': [True, False],
'with_postgresql_extra': [True, False],
Expand All @@ -53,6 +54,7 @@ class UserverConan(ConanFile):
'fPIC': True,
'lto': False,
'with_jemalloc': (platform.system() != 'Darwin'),
'with_re2': True,
'with_mongodb': True,
'with_postgresql': True,
'with_postgresql_extra': False,
Expand Down Expand Up @@ -81,6 +83,7 @@ class UserverConan(ConanFile):
'librdkafka/*:sasl': True,
'librdkafka/*:zlib': True,
'librdkafka/*:zstd': True,
're2/*:with_icu': True,
}

def set_version(self):
Expand Down Expand Up @@ -118,6 +121,9 @@ def requirements(self):

if self.options.with_jemalloc:
self.requires('jemalloc/5.3.0')
if self.options.with_re2:
self.requires('icu/74.1', force=True)
self.requires('re2/20230301')
if self.options.with_grpc or self.options.with_clickhouse:
self.requires('abseil/20240116.2', force=True)
if self.options.with_grpc:
Expand Down Expand Up @@ -196,6 +202,7 @@ def generate(self):

tool_ch.variables['USERVER_LTO'] = self.options.lto
tool_ch.variables['USERVER_FEATURE_JEMALLOC'] = self.options.with_jemalloc
tool_ch.variables['USERVER_FEATURE_RE2'] = self.options.with_re2
tool_ch.variables['USERVER_FEATURE_MONGODB'] = self.options.with_mongodb
tool_ch.variables['USERVER_FEATURE_POSTGRESQL'] = self.options.with_postgresql
tool_ch.variables['USERVER_FEATURE_PATCH_LIBPQ'] = self.options.with_postgresql_extra
Expand Down
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ find_package(Boost REQUIRED CONFIG COMPONENTS
find_package_required(ZLIB "zlib1g-dev")

find_package(Iconv REQUIRED)
_userver_macos_set_default_dir(OPENSSL_ROOT_DIR "brew;--prefix;openssl")
find_package_required(OpenSSL "libssl-dev")

if (USERVER_CONAN)
Expand Down
1 change: 1 addition & 0 deletions scripts/docker/core-ubuntu-20-gcc8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RUN apt-get update && apt-get install -y --allow-unauthenticated \
libboost-coroutine1.71-dev \
libboost-stacktrace1.71-dev \
libpugixml-dev \
libre2-dev \
libev-dev \
zlib1g-dev \
libcurl4-openssl-dev \
Expand Down
1 change: 0 additions & 1 deletion scripts/docs/en/deps/macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ openldap
openssl
postgresql@16
pugixml
re2
rocksdb
yaml-cpp
zlib
13 changes: 11 additions & 2 deletions universal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ if (USERVER_FEATURE_JEMALLOC AND NOT USERVER_SANITIZE AND NOT CMAKE_SYSTEM_NAME
endif()
endif()

option(USERVER_FEATURE_RE2 "Build userver with re2 support" OFF)
if(NOT USERVER_CONAN)
_userver_macos_set_default_dir(ICU_ROOT "brew;--prefix;icu4c")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(ICU_INCLUDE_DIR "${USERVER_BREW_PREFIX}/include" CACHE PATH "" FORCE)
endif()
endif()

option(USERVER_FEATURE_RE2 "Build userver with re2 support" ON)
if(USERVER_FEATURE_RE2)
if(USERVER_CONAN)
find_package(re2 REQUIRED CONFIG)
else()
find_package(re2 REQUIRED)
include(SetupRe2)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE re2::re2)
else()
Expand Down Expand Up @@ -391,6 +398,7 @@ _userver_directory_install(COMPONENT universal FILES
"${USERVER_ROOT_DIR}/cmake/SetupCURL.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupGTest.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupGBench.cmake"
"${USERVER_ROOT_DIR}/cmake/SetupRe2.cmake"
"${USERVER_ROOT_DIR}/cmake/sanitize.blacklist.txt"
"${USERVER_ROOT_DIR}/cmake/sanitize-macos.blacklist.txt"
"${USERVER_ROOT_DIR}/cmake/RequireLTO.cmake"
Expand All @@ -414,6 +422,7 @@ _userver_directory_install(COMPONENT universal FILES
"${USERVER_ROOT_DIR}/cmake/modules/Findlibyamlcpp.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findlibzstd.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findcctz.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/Findre2.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindJemalloc.cmake"
"${USERVER_ROOT_DIR}/cmake/modules/FindUserverGBench.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
Expand Down

0 comments on commit bbf5a29

Please sign in to comment.