From 00216eb18fc677789c5cb7460550d7b0d8259e72 Mon Sep 17 00:00:00 2001 From: tilsche Date: Sun, 3 Dec 2023 17:15:11 +0100 Subject: [PATCH 1/7] fix: types const repeated field iterators with new protobuf See #38 --- include/metricq/types.hpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/include/metricq/types.hpp b/include/metricq/types.hpp index 3503a08..8e172a1 100644 --- a/include/metricq/types.hpp +++ b/include/metricq/types.hpp @@ -128,8 +128,8 @@ class DataChunkIter { public: DataChunkIter( - google::protobuf::RepeatedField::iterator iter_time, - google::protobuf::RepeatedField::iterator iter_value) + google::protobuf::RepeatedField::const_iterator iter_time, + google::protobuf::RepeatedField::const_iterator iter_value) : iter_time(iter_time), iter_value(iter_value) { } @@ -153,8 +153,8 @@ class DataChunkIter } private: - google::protobuf::RepeatedField::iterator iter_time; - google::protobuf::RepeatedField::iterator iter_value; + google::protobuf::RepeatedField::const_iterator iter_time; + google::protobuf::RepeatedField::const_iterator iter_value; int64_t timestamp = 0; }; @@ -180,10 +180,10 @@ class [[deprecated]] HistoryRepsonseIter #pragma GCC diagnostic ignored "-Wdeprecated" #pragma GCC diagnostic ignored "-Wdeprecated-declarations" HistoryRepsonseIter( - google::protobuf::RepeatedField::iterator iter_time, - google::protobuf::RepeatedField::iterator iter_value_min, - google::protobuf::RepeatedField::iterator iter_value_max, - google::protobuf::RepeatedField::iterator iter_value_avg) + google::protobuf::RepeatedField::const_iterator iter_time, + google::protobuf::RepeatedField::const_iterator iter_value_min, + google::protobuf::RepeatedField::const_iterator iter_value_max, + google::protobuf::RepeatedField::const_iterator iter_value_avg) : iter_time(iter_time), iter_value_min(iter_value_min), iter_value_max(iter_value_max), iter_value_avg(iter_value_avg) { @@ -212,13 +212,13 @@ class [[deprecated]] HistoryRepsonseIter } private: - google::protobuf::RepeatedField::iterator iter_time; + google::protobuf::RepeatedField::const_iterator iter_time; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated" - google::protobuf::RepeatedField::iterator iter_value_min; - google::protobuf::RepeatedField::iterator iter_value_max; - google::protobuf::RepeatedField::iterator iter_value_avg; + google::protobuf::RepeatedField::const_iterator iter_value_min; + google::protobuf::RepeatedField::const_iterator iter_value_max; + google::protobuf::RepeatedField::const_iterator iter_value_avg; #pragma GCC diagnostic pop int64_t timestamp = 0; @@ -244,8 +244,8 @@ class HistoryResponseValueIterator { public: HistoryResponseValueIterator( - google::protobuf::RepeatedField::iterator iter_time, - google::protobuf::RepeatedField::iterator iter_value) + google::protobuf::RepeatedField::const_iterator iter_time, + google::protobuf::RepeatedField::const_iterator iter_value) : iter_time(iter_time), iter_value(iter_value) { } @@ -272,8 +272,8 @@ class HistoryResponseValueIterator } private: - google::protobuf::RepeatedField::iterator iter_time; - google::protobuf::RepeatedField::iterator iter_value; + google::protobuf::RepeatedField::const_iterator iter_time; + google::protobuf::RepeatedField::const_iterator iter_value; int64_t timestamp = 0; }; @@ -282,7 +282,7 @@ class HistoryResponseAggregateIterator { public: HistoryResponseAggregateIterator( - google::protobuf::RepeatedField::iterator iter_time, + google::protobuf::RepeatedField::const_iterator iter_time, google::protobuf::RepeatedPtrField::const_iterator iter_aggregate) : iter_time(iter_time), iter_aggregate(iter_aggregate) @@ -314,7 +314,7 @@ class HistoryResponseAggregateIterator } private: - google::protobuf::RepeatedField::iterator iter_time; + google::protobuf::RepeatedField::const_iterator iter_time; google::protobuf::RepeatedPtrField::const_iterator iter_aggregate; int64_t timestamp = 0; From 8f64c21e8453361c6714039d094d1da25eff875e Mon Sep 17 00:00:00 2001 From: tilsche Date: Sun, 3 Dec 2023 17:15:55 +0100 Subject: [PATCH 2/7] fix: CMake/protobuf/abseil, fixes #38 This uses the config version of FindPackage. But we have to sue the module compatibiltiy, because the build commands of config version are totally different and undocumented. see https://github.com/protocolbuffers/protobuf/issues/12637#issuecomment-1537453958 see https://stackoverflow.com/a/56896032/620382 --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb517bd..410ba82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,9 @@ include(cmake/DefaultBuildType.cmake) include(cmake/GitSubmoduleUpdate.cmake) git_submodule_update() -find_package(Protobuf 3.0 REQUIRED) +set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "") +find_package(Protobuf CONFIG REQUIRED) + find_package(Git) if(NOT METRICQ_POSITION_INDEPENDENT_CODE) From 024e85589615d141bea2b1f5c356604e7006449f Mon Sep 17 00:00:00 2001 From: tilsche Date: Sun, 3 Dec 2023 17:24:59 +0100 Subject: [PATCH 3/7] fix: update clang-format - remove duplicates - remove unsupported options - fix options that were previsouly bool and are now string - manual BraceWrapping to avoid breaking lambdas (that would be really bad for our callback-hell) --- .clang-format | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/.clang-format b/.clang-format index eef51dd..40ffa28 100644 --- a/.clang-format +++ b/.clang-format @@ -1,56 +1,65 @@ --- BasedOnStyle: LLVM AccessModifierOffset: -4 -AlignEscapedNewlinesLeft: false AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -AlwaysBreakTemplateDeclarations: true +AllowShortFunctionsOnASingleLine: None +AlwaysBreakTemplateDeclarations: Yes AlwaysBreakBeforeMultilineStrings: false BinPackParameters: true -BreakBeforeBinaryOperators: false -BreakBeforeBraces: Allman +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyNamespace: true + SplitEmptyRecord: true BreakBeforeTernaryOperators: false BreakConstructorInitializersBeforeComma: false ColumnLimit: 100 ConstructorInitializerIndentWidth: 0 ConstructorInitializerAllOnOneLineOrOnePerLine: false Cpp11BracedListStyle: false -DerivePointerBinding: false ExperimentalAutoDetectBinPacking: false IndentCaseLabels: false IndentWidth: 4 -IndentFunctionDeclarationAfterType: false MaxEmptyLinesToKeep: 1 NamespaceIndentation: Inner -PointerBindsToType: true - PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 60 PenaltyBreakString: 1000 PenaltyBreakFirstLessLess: 120 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 - +PointerAlignment: Left SpaceBeforeAssignmentOperators: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 - -Standard: Cpp11 +Standard: Latest TabWidth: 4 UseTab: Never SpacesInParentheses: false SpacesInAngles: false -SpaceInEmptyParentheses: false SpacesInCStyleCastParentheses: false -SpaceAfterControlStatementKeyword: true -SpaceBeforeAssignmentOperators: true ContinuationIndentWidth: 4 ... - From 17df385da5c53110759a23c46d8da9a73a9114e9 Mon Sep 17 00:00:00 2001 From: tilsche Date: Sun, 3 Dec 2023 18:11:16 +0100 Subject: [PATCH 4/7] update asio --- lib/asio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asio b/lib/asio index efff0de..fa27820 160000 --- a/lib/asio +++ b/lib/asio @@ -1 +1 @@ -Subproject commit efff0de89920eb66afead00dfd8bb8cf588ccee4 +Subproject commit fa27820c05afd740fa2adc1ecfb9da5afe026443 From e72eafcb4780b48ced6e5acd260925630efe3f87 Mon Sep 17 00:00:00 2001 From: tilsche Date: Sun, 3 Dec 2023 18:26:52 +0100 Subject: [PATCH 5/7] fix: avoid using deprecated asio function --- src/connection_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection_handler.cpp b/src/connection_handler.cpp index 1320d95..7056b12 100644 --- a/src/connection_handler.cpp +++ b/src/connection_handler.cpp @@ -118,7 +118,7 @@ void AsioConnectionHandler::connect(const AMQP::Address& address) void AsioConnectionHandler::connect(asio::ip::tcp::resolver::iterator endpoint_iterator) { - asio::async_connect(this->underlying_socket(), endpoint_iterator, + asio::async_connect(this->underlying_socket(), endpoint_iterator, asio::ip::tcp::resolver::iterator(), [this](const auto& error, auto successful_endpoint) { if (error) { From f6a25c50a398526b70e91f7f9ab4d7c4fe14c554 Mon Sep 17 00:00:00 2001 From: tilsche Date: Sun, 3 Dec 2023 23:43:13 +0100 Subject: [PATCH 6/7] fix: compilation with gcc/C++20 For some reason there is a weird template instantiation that breaks with the lambda auto parameter. --- src/connection_handler.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/connection_handler.cpp b/src/connection_handler.cpp index 7056b12..6cca10b 100644 --- a/src/connection_handler.cpp +++ b/src/connection_handler.cpp @@ -118,20 +118,21 @@ void AsioConnectionHandler::connect(const AMQP::Address& address) void AsioConnectionHandler::connect(asio::ip::tcp::resolver::iterator endpoint_iterator) { - asio::async_connect(this->underlying_socket(), endpoint_iterator, asio::ip::tcp::resolver::iterator(), - [this](const auto& error, auto successful_endpoint) { - if (error) - { - log::error("[{}] Failed to connect to: {}", name_, error.message()); - this->onError("Connect failed"); - return; - } - log::debug("[{}] Established connection to {} at {}", name_, - successful_endpoint->host_name(), - successful_endpoint->endpoint()); - - this->handshake(successful_endpoint->host_name()); - }); + asio::async_connect( + this->underlying_socket(), endpoint_iterator, asio::ip::tcp::resolver::iterator(), + [this](const std::error_code& error, + asio::ip::tcp::resolver::iterator successful_endpoint) { + if (error) + { + log::error("[{}] Failed to connect to: {}", name_, error.message()); + this->onError("Connect failed"); + return; + } + log::debug("[{}] Established connection to {} at {}", name_, + successful_endpoint->host_name(), successful_endpoint->endpoint()); + + this->handshake(successful_endpoint->host_name()); + }); } void PlainConnectionHandler::handshake(const std::string& hostname) From 7cb0bf3b0943a38683fd8a87681ff09e52f69821 Mon Sep 17 00:00:00 2001 From: Thomas Ilsche Date: Mon, 4 Dec 2023 10:27:27 +0100 Subject: [PATCH 7/7] fix: CMake fallback to protobuf MODULE dependency --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 410ba82..4a6ee71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,14 @@ include(cmake/GitSubmoduleUpdate.cmake) git_submodule_update() set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "") -find_package(Protobuf CONFIG REQUIRED) +find_package(Protobuf CONFIG) +if(NOT Protobuf_FOUND) + find_package(Protobuf REQUIRED) + message(STATUS "Using protobuf MODULE mode") + # TODO Abseil dependencies +else() + message(STATUS "Using protobuf CONFIG mode") +endif() find_package(Git)