Skip to content

Commit 974d0c8

Browse files
authored
Feature: vcpkg compatibility (#296)
* refactor: adapt to new qtils, scale, soralog Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> # Conflicts: # test/acceptance/p2p/host/peer/test_peer.cpp * feature: vcpkg compatibility Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: CI Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: CI Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * clean: remove mentions of SCALE update: qtils Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: libp2pConfig.cmake Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: possible mem-leaks at X509_PUBKEY_get Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> --------- Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent f1c9c71 commit 974d0c8

File tree

61 files changed

+892
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+892
-343
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
run: |
2424
set -e
2525
sudo apt-get update || true
26-
sudo apt-get install -y ninja-build
27-
sudo python3 -m pip install --upgrade pip
26+
sudo apt-get install -y ninja-build python3-pip
2827
sudo pip3 install scikit-build
2928
sudo pip3 install cmake requests gitpython gcovr pyyaml
3029
- name: "cmake"

CMakeLists.txt

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
cmake_minimum_required(VERSION 3.12)
22

3+
if (PACKAGE_MANAGER)
4+
if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$")
5+
message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set")
6+
endif ()
7+
else ()
8+
set(PACKAGE_MANAGER "hunter")
9+
if (CMAKE_TOOLCHAIN_FILE)
10+
get_filename_component(ACTUAL_NAME ${CMAKE_TOOLCHAIN_FILE} NAME)
11+
if(ACTUAL_NAME STREQUAL "vcpkg.cmake")
12+
message(STATUS "vcpkg will be used because vcpkg.cmake has found")
13+
set(PACKAGE_MANAGER "vcpkg")
14+
endif ()
15+
endif ()
16+
endif ()
17+
message(STATUS "Selected package manager: ${PACKAGE_MANAGER}")
18+
319
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
420
cmake_policy(SET CMP0144 NEW)
521
endif()
@@ -20,7 +36,9 @@ set(CMAKE_TOOLCHAIN_FILE
2036
cmake_policy(SET CMP0048 NEW)
2137
cmake_policy(SET CMP0135 NEW)
2238

23-
include("cmake/Hunter/init.cmake")
39+
if (PACKAGE_MANAGER STREQUAL "hunter")
40+
include("cmake/Hunter/init.cmake")
41+
endif ()
2442

2543
project(libp2p VERSION 0.1.17 LANGUAGES C CXX)
2644

@@ -39,6 +57,7 @@ option(TSAN "Enable thread sanitizer" OFF)
3957
option(UBSAN "Enable UB sanitizer" OFF)
4058
option(EXPOSE_MOCKS "Make mocks header files visible for child projects" ON)
4159
option(METRICS_ENABLED "Enable libp2p metrics" OFF)
60+
option(SQLITE_ENABLED "Enable sqlite based libp2p storage" OFF)
4261

4362
include(cmake/print.cmake)
4463
print("C flags: ${CMAKE_C_FLAGS}")
@@ -59,6 +78,10 @@ if (METRICS_ENABLED)
5978
add_compile_definitions("LIBP2P_METRICS_ENABLED")
6079
endif ()
6180

81+
if(SQLITE_ENABLED)
82+
set(SQLITE_FIND_DEP "find_dependency(SQLiteModernCpp CONFIG REQUIRED)")
83+
endif()
84+
6285
## setup compilation flags
6386
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
6487
# enable those flags
@@ -114,6 +137,9 @@ if(EXAMPLES)
114137
add_subdirectory(example)
115138
endif()
116139
if(TESTING OR COVERAGE)
140+
if (PACKAGE_MANAGER STREQUAL "vcpkg")
141+
list(APPEND VCPKG_MANIFEST_FEATURES libp2p-tests)
142+
endif()
117143
enable_testing()
118144
add_subdirectory(test)
119145
endif()
@@ -126,11 +152,11 @@ include(CMakePackageConfigHelpers)
126152

127153
set(CONFIG_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR}/libp2p)
128154
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/libp2pConfig.cmake.in
129-
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
130-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
131-
)
155+
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
156+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
157+
)
132158

133159
install(FILES
134-
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
135-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
136-
)
160+
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
161+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
162+
)

cmake/Hunter/config.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,27 @@
1414
# SHA1 1234567890abcdef1234567890abcdef12345678
1515
# CMAKE_ARGS "CMAKE_VARIABLE=value"
1616
# )
17+
18+
hunter_config(
19+
soralog
20+
URL https://github.com/xDimon/soralog/archive/4dfffd3d949b1c16a04db2e5756555a4031732f7.tar.gz
21+
SHA1 60e3dcaab2d8e43f0ed4fd22087677663c618716
22+
# VERSION 0.2.4
23+
KEEP_PACKAGE_SOURCES
24+
)
25+
26+
hunter_config(
27+
ZLIB
28+
VERSION 1.3.0-p0
29+
URL https://github.com/cpp-pm/zlib/archive/refs/tags/v1.3.0-p0.tar.gz
30+
SHA1 311ca59e20cbbfe9d9e05196c12c6ae109093987
31+
)
32+
33+
hunter_config(
34+
qtils
35+
URL https://github.com/qdrvm/qtils/archive/1e492cf09a3640570cae59a951502614320c0797.tar.gz
36+
SHA1 033dd907e2566c95ce2ccf1fa6dd9766bc896894
37+
CMAKE_ARGS
38+
FORMAT_ERROR_WITH_FULLTYPE=ON
39+
KEEP_PACKAGE_SOURCES
40+
)

cmake/dependencies.cmake

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7+
if (NOT PACKAGE_MANAGER STREQUAL "hunter")
8+
function(hunter_add_package)
9+
endfunction()
10+
endif ()
11+
712
if (TESTING)
813
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
914
hunter_add_package(GTest)
1015
find_package(GTest CONFIG REQUIRED)
1116
endif()
1217

13-
# https://docs.hunter.sh/en/latest/packages/pkg/Boost.html
14-
hunter_add_package(Boost COMPONENTS random filesystem program_options)
15-
find_package(Boost CONFIG REQUIRED random filesystem program_options)
18+
if (PACKAGE_MANAGER STREQUAL "hunter")
19+
hunter_add_package(Boost COMPONENTS random filesystem program_options)
20+
find_package(Boost CONFIG REQUIRED filesystem random program_options)
21+
else ()
22+
find_package(Boost CONFIG REQUIRED filesystem random beast program_options)
23+
endif ()
1624

1725
# https://www.openssl.org/
1826
hunter_add_package(BoringSSL)
@@ -53,6 +61,10 @@ find_package(tsl_hat_trie CONFIG REQUIRED)
5361
hunter_add_package(Boost.DI)
5462
find_package(Boost.DI CONFIG REQUIRED)
5563

56-
# https://github.com/qdrvm/libp2p-sqlite-modern-cpp/tree/hunter
57-
hunter_add_package(SQLiteModernCpp)
58-
find_package(SQLiteModernCpp CONFIG REQUIRED)
64+
if (SQLITE_ENABLED)
65+
# https://github.com/qdrvm/libp2p-sqlite-modern-cpp/tree/hunter
66+
hunter_add_package(SQLiteModernCpp)
67+
find_package(SQLiteModernCpp CONFIG REQUIRED)
68+
endif ()
69+
70+
find_package(ZLIB REQUIRED)

cmake/libp2pConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ find_dependency(yaml-cpp CONFIG REQUIRED)
1313
find_dependency(soralog CONFIG REQUIRED)
1414
find_dependency(tsl_hat_trie CONFIG REQUIRED)
1515
find_dependency(Boost.DI CONFIG REQUIRED)
16-
find_dependency(SQLiteModernCpp CONFIG REQUIRED)
16+
@SQLITE_FIND_DEP@
1717

1818
include("${CMAKE_CURRENT_LIST_DIR}/libp2pTargets.cmake")
1919

include/libp2p/multi/multiaddress_protocol_list.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <functional>
1111
#include <map>
1212
#include <string_view>
13+
#include <unistd.h>
1314

1415
namespace libp2p::multi {
1516

src/crypto/rsa_provider/rsa_provider_impl.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,19 @@ namespace libp2p::crypto::rsa {
157157
const Signature &signature,
158158
const PublicKey &public_key) const {
159159
OUTCOME_TRY(x509_key, RsaProviderImpl::getPublicKeyFromBytes(public_key));
160-
EVP_PKEY *key = X509_PUBKEY_get0(x509_key.get());
161-
std::unique_ptr<RSA, void (*)(RSA *)> rsa{EVP_PKEY_get1_RSA(key), RSA_free};
160+
161+
EVP_PKEY *key = X509_PUBKEY_get(x509_key.get());
162+
if (!key) {
163+
return CryptoProviderError::SIGNATURE_VERIFICATION_FAILED;
164+
}
165+
std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)> key_ptr{key,
166+
EVP_PKEY_free};
167+
std::unique_ptr<RSA, decltype(&RSA_free)> rsa{
168+
EVP_PKEY_get1_RSA(key_ptr.get()), RSA_free};
169+
if (!rsa) {
170+
return CryptoProviderError::SIGNATURE_VERIFICATION_FAILED;
171+
}
172+
162173
OUTCOME_TRY(digest, sha256(message));
163174
int result = RSA_verify(NID_sha256,
164175
digest.data(),

src/protocol_muxer/multiselect/multiselect_instance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ namespace libp2p::protocol_muxer::multiselect {
328328

329329
SL_DEBUG(log(),
330330
"Failed to negotiate protocols: {}",
331-
fmt::join(protocols_.begin(), protocols_.end(), ", "));
331+
fmt::join(protocols_, ", "));
332332
return MaybeResult(ProtocolMuxer::Error::NEGOTIATION_FAILED);
333333
}
334334

src/storage/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7-
libp2p_add_library(p2p_sqlite sqlite.cpp)
8-
target_link_libraries(p2p_sqlite
9-
SQLiteModernCpp::SQLiteModernCpp
10-
p2p_logger
11-
)
7+
if (SQLITE_ENABLED)
8+
libp2p_add_library(p2p_sqlite sqlite.cpp)
9+
target_link_libraries(p2p_sqlite
10+
SQLiteModernCpp::SQLiteModernCpp
11+
p2p_logger
12+
)
13+
endif ()

src/transport/quic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ libp2p_add_library(p2p_quic
1414
target_link_libraries(p2p_quic
1515
lsquic::lsquic
1616
p2p_tls
17+
ZLIB::ZLIB
1718
)

0 commit comments

Comments
 (0)