Skip to content

Commit 7adcc20

Browse files
committed
feature: vcpkg compatibility
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent 503585f commit 7adcc20

27 files changed

+535
-31
lines changed

CMakeLists.txt

+29-7
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}")
@@ -114,6 +133,9 @@ if(EXAMPLES)
114133
add_subdirectory(example)
115134
endif()
116135
if(TESTING OR COVERAGE)
136+
if (PACKAGE_MANAGER STREQUAL "vcpkg")
137+
list(APPEND VCPKG_MANIFEST_FEATURES libp2p-tests)
138+
endif()
117139
enable_testing()
118140
add_subdirectory(test)
119141
endif()
@@ -126,11 +148,11 @@ include(CMakePackageConfigHelpers)
126148

127149
set(CONFIG_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR}/libp2p)
128150
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-
)
151+
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
152+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
153+
)
132154

133155
install(FILES
134-
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
135-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
136-
)
156+
${CMAKE_CURRENT_BINARY_DIR}/libp2pConfig.cmake
157+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libp2p
158+
)

cmake/Hunter/config.cmake

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
hunter_config(
1919
soralog
20-
URL https://github.com/xDimon/soralog/archive/35634db3126d7dc1784c883713c8e31ebb07d051.tar.gz
21-
SHA1 ee64d0982cffe0a3856c4e786161518e55a6ffd4
20+
URL https://github.com/xDimon/soralog/archive/4dfffd3d949b1c16a04db2e5756555a4031732f7.tar.gz
21+
SHA1 60e3dcaab2d8e43f0ed4fd22087677663c618716
2222
# VERSION 0.2.4
2323
KEEP_PACKAGE_SOURCES
2424
)
@@ -32,8 +32,8 @@ hunter_config(
3232

3333
hunter_config(
3434
scale
35-
URL https://github.com/qdrvm/scale-codec-cpp/archive/24fbd767c8975647a733b45f9c3df92380110fb2.tar.gz
36-
SHA1 c8570702805cdbacd31bd5caacead82c746ba901
35+
URL https://github.com/qdrvm/scale-codec-cpp/archive/156433264c90770c9eda2a2417852fd8e14a024e.tar.gz
36+
SHA1 d2b9edf1d67f48c1916caeae119df3065ef14062
3737
KEEP_PACKAGE_SOURCES
3838
)
3939

cmake/dependencies.cmake

+18-6
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)

src/crypto/rsa_provider/rsa_provider_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ 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());
160+
EVP_PKEY *key = X509_PUBKEY_get(x509_key.get());
161161
std::unique_ptr<RSA, void (*)(RSA *)> rsa{EVP_PKEY_get1_RSA(key), RSA_free};
162162
OUTCOME_TRY(digest, sha256(message));
163163
int result = RSA_verify(NID_sha256,

src/protocol_muxer/multiselect/multiselect_instance.cpp

+1-1
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

+7-5
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

+1
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
)

test/libp2p/storage/CMakeLists.txt

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7-
addtest(libp2p_sqlite_test
8-
sqlite_test.cpp
9-
)
10-
target_link_libraries(libp2p_sqlite_test
11-
Boost::filesystem
12-
p2p_sqlite
13-
)
7+
if (SQLITE_ENABLED)
8+
addtest(libp2p_sqlite_test
9+
sqlite_test.cpp
10+
)
11+
target_link_libraries(libp2p_sqlite_test
12+
Boost::filesystem
13+
p2p_sqlite
14+
)
15+
endif ()

vcpkg-configuration.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "fe1cde61e971d53c9687cf9a46308f8f55da19fa",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "artifact",
10+
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11+
"name": "microsoft"
12+
}
13+
],
14+
"overlay-ports": [
15+
"vcpkg-overlay"
16+
]
17+
}

vcpkg-overlay/boost-di/portfile.cmake

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
2+
vcpkg_from_github(
3+
OUT_SOURCE_PATH SOURCE_PATH
4+
REPO qdrvm/boost-di
5+
REF d5de6c9840c7fc2e44bf37134b4a14b88151ecc4
6+
SHA512 98e924d02bde23940ab59330730de6d4198d1e98cbb303ef713e3ee06f88e90707a952e6aa9a0372213b46d6c9d3478e86ed5cd64d74899861984e786e21c319
7+
)
8+
vcpkg_cmake_configure(
9+
SOURCE_PATH "${SOURCE_PATH}"
10+
OPTIONS
11+
-DBOOST_DI_OPT_BUILD_TESTS=OFF
12+
-DBOOST_DI_OPT_BUILD_EXAMPLES=OFF
13+
)
14+
vcpkg_cmake_install()

vcpkg-overlay/boost-di/vcpkg.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "boost-di",
3+
"version": "1.1.0.1",
4+
"dependencies": [
5+
{ "name": "vcpkg-cmake", "host": true },
6+
{ "name": "vcpkg-cmake-config", "host": true }
7+
]
8+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 65c4776..5d4086a 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -60,12 +60,12 @@ ENDIF()
6+
7+
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
8+
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
9+
- IF(CMAKE_C_COMPILER MATCHES "clang" AND
10+
- NOT "$ENV{TRAVIS}" MATCHES "^true$" AND
11+
- NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize")
12+
- SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
13+
- SET(LIBS ${LIBS} -fsanitize=address)
14+
- ENDIF()
15+
+ # IF(CMAKE_C_COMPILER MATCHES "clang" AND
16+
+ # NOT "$ENV{TRAVIS}" MATCHES "^true$" AND
17+
+ # NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize")
18+
+ # SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
19+
+ # SET(LIBS ${LIBS} -fsanitize=address)
20+
+ # ENDIF()
21+
# Uncomment to enable cleartext protocol mode (no crypto):
22+
#SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1")
23+
ELSE()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 5d4086a..e085a83 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -120,10 +120,12 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
6+
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
7+
#SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
8+
#SET(LIBS ${LIBS} fiu)
9+
+ SET(LIB_NAME ssld cryptod)
10+
ELSE()
11+
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
12+
# Comment out the following line to compile out debug messages:
13+
#SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
14+
+ SET(LIB_NAME ssl crypto)
15+
ENDIF()
16+
17+
ENDIF() #MSVC
18+
@@ -191,7 +193,7 @@ IF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR)
19+
ELSE()
20+
21+
22+
- FOREACH(LIB_NAME ssl crypto)
23+
+ FOREACH(LIB ${LIB_NAME})
24+
# If BORINGSSL_LIB is defined, try find each lib. Otherwise, user should define BORINGSSL_LIB_ssl,
25+
# BORINGSSL_LIB_crypto and so on explicitly. For example, including boringssl and lsquic both via
26+
# add_subdirectory:
27+
@@ -201,20 +203,20 @@ ELSE()
28+
# add_subdirectory(third_party/lsquic)
29+
IF (DEFINED BORINGSSL_LIB)
30+
IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
31+
- FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
32+
- NAMES ${LIB_NAME}
33+
+ FIND_LIBRARY(BORINGSSL_LIB_${LIB}
34+
+ NAMES ${LIB}
35+
PATHS ${BORINGSSL_LIB}
36+
PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
37+
NO_DEFAULT_PATH)
38+
ELSE()
39+
- FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
40+
- NAMES lib${LIB_NAME}${LIB_SUFFIX}
41+
+ FIND_LIBRARY(BORINGSSL_LIB_${LIB}
42+
+ NAMES lib${LI}${LIB_SUFFIX}
43+
PATHS ${BORINGSSL_LIB}
44+
- PATH_SUFFIXES ${LIB_NAME}
45+
+ PATH_SUFFIXES ${LIB}
46+
NO_DEFAULT_PATH)
47+
ENDIF()
48+
ENDIF()
49+
- IF(BORINGSSL_LIB_${LIB_NAME})
50+
+ IF(BORINGSSL_LIB_${LIB})
51+
MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}")
52+
ELSE()
53+
MESSAGE(FATAL_ERROR "BORINGSSL_LIB_${LIB_NAME} library not found")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
diff --git a/include/lsquic.h b/include/lsquic.h
2+
index 389fbcc..c38d027 100644
3+
--- a/include/lsquic.h
4+
+++ b/include/lsquic.h
5+
@@ -1671,6 +1671,10 @@ int lsquic_stream_close(lsquic_stream_t *s);
6+
int
7+
lsquic_stream_has_unacked_data (lsquic_stream_t *s);
8+
9+
+/* Return SSL object associated with this connection */
10+
+struct ssl_st *
11+
+lsquic_conn_ssl(struct lsquic_conn *conn);
12+
+
13+
/**
14+
* Get certificate chain returned by the server. This can be used for
15+
* server certificate verification.
16+
diff --git a/src/liblsquic/lsquic_conn.c b/src/liblsquic/lsquic_conn.c
17+
index f76550d..31e5285 100644
18+
--- a/src/liblsquic/lsquic_conn.c
19+
+++ b/src/liblsquic/lsquic_conn.c
20+
@@ -128,6 +128,12 @@ lsquic_conn_crypto_alg_keysize (const lsquic_conn_t *lconn)
21+
}
22+
23+
24+
+struct ssl_st *
25+
+lsquic_conn_ssl(struct lsquic_conn *lconn) {
26+
+ return lconn->cn_esf_c->esf_get_ssl(lconn->cn_enc_session);
27+
+}
28+
+
29+
+
30+
struct stack_st_X509 *
31+
lsquic_conn_get_server_cert_chain (struct lsquic_conn *lconn)
32+
{
33+
diff --git a/src/liblsquic/lsquic_enc_sess.h b/src/liblsquic/lsquic_enc_sess.h
34+
index f45c15f..3505fbd 100644
35+
--- a/src/liblsquic/lsquic_enc_sess.h
36+
+++ b/src/liblsquic/lsquic_enc_sess.h
37+
@@ -115,6 +115,9 @@ struct enc_session_funcs_common
38+
(*esf_decrypt_packet)(enc_session_t *, struct lsquic_engine_public *,
39+
const struct lsquic_conn *, struct lsquic_packet_in *);
40+
41+
+ struct ssl_st *
42+
+ (*esf_get_ssl)(enc_session_t *);
43+
+
44+
struct stack_st_X509 *
45+
(*esf_get_server_cert_chain) (enc_session_t *);
46+
47+
diff --git a/src/liblsquic/lsquic_enc_sess_ietf.c b/src/liblsquic/lsquic_enc_sess_ietf.c
48+
index 66329c1..076c4c5 100644
49+
--- a/src/liblsquic/lsquic_enc_sess_ietf.c
50+
+++ b/src/liblsquic/lsquic_enc_sess_ietf.c
51+
@@ -2519,6 +2519,13 @@ iquic_esf_global_cleanup (void)
52+
}
53+
54+
55+
+static struct ssl_st *
56+
+iquic_esf_get_ssl(enc_session_t *enc_session_p) {
57+
+ struct enc_sess_iquic *const enc_sess = enc_session_p;
58+
+ return enc_sess->esi_ssl;
59+
+}
60+
+
61+
+
62+
static struct stack_st_X509 *
63+
iquic_esf_get_server_cert_chain (enc_session_t *enc_session_p)
64+
{
65+
@@ -2744,6 +2751,7 @@ const struct enc_session_funcs_common lsquic_enc_session_common_ietf_v1 =
66+
.esf_global_cleanup = iquic_esf_global_cleanup,
67+
.esf_global_init = iquic_esf_global_init,
68+
.esf_tag_len = IQUIC_TAG_LEN,
69+
+ .esf_get_ssl = iquic_esf_get_ssl,
70+
.esf_get_server_cert_chain
71+
= iquic_esf_get_server_cert_chain,
72+
.esf_get_sni = iquic_esf_get_sni,
73+
@@ -2763,6 +2771,7 @@ const struct enc_session_funcs_common lsquic_enc_session_common_ietf_v1_no_flush
74+
.esf_global_cleanup = iquic_esf_global_cleanup,
75+
.esf_global_init = iquic_esf_global_init,
76+
.esf_tag_len = IQUIC_TAG_LEN,
77+
+ .esf_get_ssl = iquic_esf_get_ssl,
78+
.esf_get_server_cert_chain
79+
= iquic_esf_get_server_cert_chain,
80+
.esf_get_sni = iquic_esf_get_sni,

0 commit comments

Comments
 (0)