Skip to content

Commit

Permalink
Enable C++20 for the compile-options build
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Avlasov <yavlasov@google.com>
  • Loading branch information
yanavlasov committed Jul 12, 2023
1 parent 0ac8eea commit 1a344a3
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ build:libc++ --action_env=BAZEL_LINKOPTS=-lm:-pthread
build:libc++ --define force_libcpp=enabled

build:libc++20 --config=libc++
build:libc++20 --cxxopt=-std=c++20
# gRPC has a lot of deprecated-enum-enum-conversion warning. Remove once it is addressed
build:libc++20 --cxxopt=-std=c++20 --copt=-Wno-error=deprecated-enum-enum-conversion

# Optimize build for binary size reduction.
build:sizeopt -c opt --copt -Os
Expand Down
27 changes: 27 additions & 0 deletions bazel/io_opentracing_cpp.patch
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,30 @@ index c57dc9f..587bf0e 100644
- rm -rf $$TEMP_DIR
- """,
-)
diff --git a/3rd_party/include/opentracing/variant/variant.hpp b/3rd_party/include/opentracing/variant/variant.hpp
--- a/3rd_party/include/opentracing/variant/variant.hpp 2023-07-11 17:17:48.563874883 +0000
+++ b/3rd_party/include/opentracing/variant/variant.hpp 2023-07-11 17:45:38.558235212 +0000
@@ -167,7 +167,11 @@
template <typename F, typename V, typename Enable = void>
struct result_of_unary_visit
{
+#if __cplusplus >= 202002L
+ using type = typename std::invoke_result<F, V&>::type;
+#else
using type = typename std::result_of<F(V&)>::type;
+#endif
};

template <typename F, typename V>
@@ -179,7 +183,11 @@
template <typename F, typename V, typename Enable = void>
struct result_of_binary_visit
{
+#if __cplusplus >= 202002L
+ using type = typename std::invoke_result<F, V&, V&>::type;
+#else
using type = typename std::result_of<F(V&, V&)>::type;
+#endif
};

template <typename F, typename V>
3 changes: 2 additions & 1 deletion ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ case $CI_TARGET in
"--@envoy//bazel:http3=False"
"--@envoy//source/extensions/filters/http/kill_request:enabled"
"--test_env=ENVOY_HAS_EXTRA_EXTENSIONS=true"
"--remote_download_minimal")
"--remote_download_minimal"
"--config=libc++20")
ENVOY_STDLIB="${ENVOY_STDLIB:-libstdc++}"
setup_clang_toolchain
# This doesn't go into CI but is available for developer convenience.
Expand Down
6 changes: 3 additions & 3 deletions source/common/common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class ExtractedMessage : public spdlog::custom_flag_formatter {
do { \
if (ENVOY_LOG_COMP_LEVEL(LOGGER, LEVEL)) { \
ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, \
::Envoy::Logger::Utility::serializeLogTags(TAGS) + FORMAT, \
fmt::runtime(::Envoy::Logger::Utility::serializeLogTags(TAGS) + FORMAT), \
##__VA_ARGS__); \
} \
} while (0)
Expand All @@ -579,7 +579,7 @@ class ExtractedMessage : public spdlog::custom_flag_formatter {
if (ENVOY_LOG_COMP_LEVEL(LOGGER, LEVEL)) { \
TAGS.emplace("ConnectionId", std::to_string((CONNECTION).id())); \
ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, \
::Envoy::Logger::Utility::serializeLogTags(TAGS) + FORMAT, \
fmt::runtime(::Envoy::Logger::Utility::serializeLogTags(TAGS) + FORMAT), \
##__VA_ARGS__); \
} \
} while (0)
Expand All @@ -591,7 +591,7 @@ class ExtractedMessage : public spdlog::custom_flag_formatter {
(STREAM).connection() ? std::to_string((STREAM).connection()->id()) : "0"); \
TAGS.emplace("StreamId", std::to_string((STREAM).streamId())); \
ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, \
::Envoy::Logger::Utility::serializeLogTags(TAGS) + FORMAT, \
fmt::runtime(::Envoy::Logger::Utility::serializeLogTags(TAGS) + FORMAT), \
##__VA_ARGS__); \
} \
} while (0)
Expand Down
8 changes: 4 additions & 4 deletions source/extensions/common/aws/signer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ std::string SignerImpl::createContentHash(Http::RequestMessage& message, bool si

std::string SignerImpl::createCredentialScope(absl::string_view short_date,
absl::string_view override_region) const {
return fmt::format(SignatureConstants::get().CredentialScopeFormat, short_date,
return fmt::format(fmt::runtime(SignatureConstants::get().CredentialScopeFormat), short_date,
override_region.empty() ? region_ : override_region, service_name_);
}

Expand All @@ -102,7 +102,7 @@ std::string SignerImpl::createStringToSign(absl::string_view canonical_request,
absl::string_view credential_scope) const {
auto& crypto_util = Envoy::Common::Crypto::UtilitySingleton::get();
return fmt::format(
SignatureConstants::get().StringToSignFormat, long_date, credential_scope,
fmt::runtime(SignatureConstants::get().StringToSignFormat), long_date, credential_scope,
Hex::encode(crypto_util.getSha256Digest(Buffer::OwnedImpl(canonical_request))));
}

Expand All @@ -129,8 +129,8 @@ SignerImpl::createAuthorizationHeader(absl::string_view access_key_id,
const std::map<std::string, std::string>& canonical_headers,
absl::string_view signature) const {
const auto signed_headers = Utility::joinCanonicalHeaderNames(canonical_headers);
return fmt::format(SignatureConstants::get().AuthorizationHeaderFormat, access_key_id,
credential_scope, signed_headers, signature);
return fmt::format(fmt::runtime(SignatureConstants::get().AuthorizationHeaderFormat),
access_key_id, credential_scope, signed_headers, signature);
}

} // namespace Aws
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/common/aws/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ constexpr absl::string_view QUERY_SEPERATOR = "&";
constexpr absl::string_view QUERY_SPLITTER = "?";
constexpr absl::string_view RESERVED_CHARS = "-._~";
constexpr absl::string_view S3_SERVICE_NAME = "s3";
const std::string URI_ENCODE = "%{:02X}";
const std::string URI_DOUBLE_ENCODE = "%25{:02X}";
constexpr absl::string_view URI_ENCODE = "%{:02X}";
constexpr absl::string_view URI_DOUBLE_ENCODE = "%25{:02X}";

std::map<std::string, std::string>
Utility::canonicalizeHeaders(const Http::RequestHeaderMap& headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ bool UpstreamIpPortMatcher::matches(const Network::Connection&,
if (port_) {
const auto port = address_obj->address_->ip()->port();
if (port >= port_->start() && port <= port_->end()) {
ENVOY_LOG(debug, "UpstreamIpPort matcher for port range: {{}, {}} evaluated to: true",
ENVOY_LOG(debug, "UpstreamIpPort matcher for port range: [{}, {}] evaluated to: true",
port_->start(), port_->end());
} else {
ENVOY_LOG(debug, "UpstreamIpPort matcher for port range: {{}, {}} evaluated to: false",
ENVOY_LOG(debug, "UpstreamIpPort matcher for port range: [{}, {}] evaluated to: false",
port_->start(), port_->end());
return false;
}
Expand Down
21 changes: 21 additions & 0 deletions source/extensions/filters/network/mongo_proxy/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class GetMoreMessageImpl : public MessageImpl,

// Mongo::GetMoreMessage
bool operator==(const GetMoreMessage& rhs) const override;
bool operator==(const GetMoreMessageImpl& rhs) const {
return operator==(static_cast<const GetMoreMessage&>(rhs));
}
const std::string& fullCollectionName() const override { return full_collection_name_; }
void fullCollectionName(const std::string& name) override { full_collection_name_ = name; }
int32_t numberToReturn() const override { return number_to_return_; }
Expand Down Expand Up @@ -72,6 +75,9 @@ class InsertMessageImpl : public MessageImpl,

// Mongo::InsertMessage
bool operator==(const InsertMessage& rhs) const override;
bool operator==(const InsertMessageImpl& rhs) const {
return operator==(static_cast<const InsertMessage&>(rhs));
}
int32_t flags() const override { return flags_; }
void flags(int32_t flags) override { flags_ = flags; }
const std::string& fullCollectionName() const override { return full_collection_name_; }
Expand Down Expand Up @@ -99,6 +105,9 @@ class KillCursorsMessageImpl : public MessageImpl,

// Mongo::KillCursorsMessage
bool operator==(const KillCursorsMessage& rhs) const override;
bool operator==(const KillCursorsMessageImpl& rhs) const {
return operator==(static_cast<const KillCursorsMessage&>(rhs));
}
int32_t numberOfCursorIds() const override { return number_of_cursor_ids_; }
void numberOfCursorIds(int32_t number_of_cursor_ids) override {
number_of_cursor_ids_ = number_of_cursor_ids;
Expand Down Expand Up @@ -127,6 +136,9 @@ class QueryMessageImpl : public MessageImpl,

// Mongo::QueryMessage
bool operator==(const QueryMessage& rhs) const override;
bool operator==(const QueryMessageImpl& rhs) const {
return operator==(static_cast<const QueryMessage&>(rhs));
}
int32_t flags() const override { return flags_; }
void flags(int32_t flags) override { flags_ = flags; }
const std::string& fullCollectionName() const override { return full_collection_name_; }
Expand Down Expand Up @@ -167,6 +179,9 @@ class ReplyMessageImpl : public MessageImpl,

// Mongo::ReplyMessage
bool operator==(const ReplyMessage& rhs) const override;
bool operator==(const ReplyMessageImpl& rhs) const {
return operator==(static_cast<const ReplyMessage&>(rhs));
}
int32_t flags() const override { return flags_; }
void flags(int32_t flags) override { flags_ = flags; }
int64_t cursorId() const override { return cursor_id_; }
Expand Down Expand Up @@ -199,6 +214,9 @@ class CommandMessageImpl : public MessageImpl,

// CommandMessageImpl accessors.
bool operator==(const CommandMessage& rhs) const override;
bool operator==(const CommandMessageImpl& rhs) const {
return operator==(static_cast<const CommandMessage&>(rhs));
}
std::string database() const override { return database_; }
void database(std::string database) override { database_ = database; }
std::string commandName() const override { return command_name_; }
Expand Down Expand Up @@ -233,6 +251,9 @@ class CommandReplyMessageImpl : public MessageImpl,

// CommandMessageReplyImpl accessors.
bool operator==(const CommandReplyMessage& rhs) const override;
bool operator==(const CommandReplyMessageImpl& rhs) const {
return operator==(static_cast<const CommandReplyMessage&>(rhs));
}
const Bson::Document* metadata() const override { return metadata_.get(); }
void metadata(Bson::DocumentSharedPtr&& metadata) override { metadata_ = std::move(metadata); }
const Bson::Document* commandReply() const override { return command_reply_.get(); }
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/network/mongo_proxy/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ AccessLog::AccessLog(const std::string& file_name, Envoy::AccessLog::AccessLogMa

void AccessLog::logMessage(const Message& message, bool full,
const Upstream::HostDescription* upstream_host) {
static const std::string log_format =
static constexpr absl::string_view log_format =
"{{\"time\": \"{}\", \"message\": {}, \"upstream_host\": \"{}\"}}\n";

SystemTime now = time_source_.systemTime();
Expand Down
4 changes: 2 additions & 2 deletions source/server/hot_restarting_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ sockaddr_un HotRestartingBase::createDomainSocketAddress(uint64_t id, const std:
id = id % MaxConcurrentProcesses;
sockaddr_un address;
initDomainSocketAddress(&address);
Network::Address::PipeInstance addr(fmt::format(socket_path + "_{}_{}", role, base_id_ + id),
socket_mode, nullptr);
Network::Address::PipeInstance addr(
fmt::format(fmt::runtime(socket_path + "_{}_{}"), role, base_id_ + id), socket_mode, nullptr);
safeMemcpy(&address, &(addr.getSockAddr()));
fchmod(my_domain_socket_, socket_mode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AwsLambdaFilterIntegrationTest : public testing::TestWithParam<Network::Ad
void TearDown() override { fake_upstream_connection_.reset(); }

void setupLambdaFilter(bool passthrough) {
const std::string filter =
constexpr absl::string_view filter =
R"EOF(
name: envoy.filters.http.aws_lambda
typed_config:
Expand Down
12 changes: 6 additions & 6 deletions test/extensions/filters/http/bandwidth_limit/filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FilterTest : public testing::Test {
};

TEST_F(FilterTest, Disabled) {
const std::string config_yaml = R"(
constexpr absl::string_view config_yaml = R"(
stat_prefix: test
runtime_enabled:
default_value: false
Expand Down Expand Up @@ -92,7 +92,7 @@ TEST_F(FilterTest, Disabled) {
}

TEST_F(FilterTest, LimitOnDecode) {
const std::string config_yaml = R"(
constexpr absl::string_view config_yaml = R"(
stat_prefix: test
runtime_enabled:
default_value: true
Expand Down Expand Up @@ -215,7 +215,7 @@ TEST_F(FilterTest, LimitOnDecode) {
}

TEST_F(FilterTest, LimitOnEncode) {
const std::string config_yaml = R"(
constexpr absl::string_view config_yaml = R"(
stat_prefix: test
runtime_enabled:
default_value: true
Expand Down Expand Up @@ -339,7 +339,7 @@ TEST_F(FilterTest, LimitOnEncode) {
}

TEST_F(FilterTest, LimitOnDecodeAndEncode) {
const std::string config_yaml = R"(
constexpr absl::string_view config_yaml = R"(
stat_prefix: test
runtime_enabled:
default_value: true
Expand Down Expand Up @@ -477,7 +477,7 @@ TEST_F(FilterTest, LimitOnDecodeAndEncode) {
}

TEST_F(FilterTest, WithTrailers) {
const std::string config_yaml = R"(
constexpr absl::string_view config_yaml = R"(
stat_prefix: test
runtime_enabled:
default_value: true
Expand Down Expand Up @@ -553,7 +553,7 @@ TEST_F(FilterTest, WithTrailers) {
}

TEST_F(FilterTest, WithTrailersNoEndStream) {
const std::string config_yaml = R"(
constexpr absl::string_view config_yaml = R"(
stat_prefix: test
runtime_enabled:
default_value: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ name: rbac
- any: true
)EOF";

const std::string RBAC_CONFIG_HEADER_MATCH_CONDITION = R"EOF(
constexpr absl::string_view RBAC_CONFIG_HEADER_MATCH_CONDITION = R"EOF(
name: rbac
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.rbac.v3.RBAC
Expand Down
4 changes: 2 additions & 2 deletions test/extensions/filters/http/rbac/rbac_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RoleBasedAccessControlFilterTest : public testing::Test {
void setupMatcher(std::string action, std::string on_no_match_action) {
envoy::extensions::filters::http::rbac::v3::RBAC config;

const std::string matcher_yaml = R"EOF(
constexpr absl::string_view matcher_yaml = R"EOF(
matcher_list:
matchers:
- predicate:
Expand Down Expand Up @@ -112,7 +112,7 @@ class RoleBasedAccessControlFilterTest : public testing::Test {
name: none
action: {}
)EOF";
const std::string shadow_matcher_yaml = R"EOF(
constexpr absl::string_view shadow_matcher_yaml = R"EOF(
matcher_list:
matchers:
- predicate:
Expand Down
Loading

0 comments on commit 1a344a3

Please sign in to comment.