From f15635287bb564831b5c5b140b613972182f0017 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 12 Oct 2023 10:31:40 -0700 Subject: [PATCH] [xxhash] add a wrapper header to avoid clang-format breakage (#34658) --- Package.swift | 1 + build_autogenerated.yaml | 1 + gRPC-C++.podspec | 2 ++ gRPC-Core.podspec | 2 ++ grpc.gemspec | 1 + package.xml | 1 + src/core/BUILD | 12 ++++++-- .../lb_policy/ring_hash/ring_hash.cc | 4 +-- .../resolver/xds/xds_resolver.cc | 11 +++---- src/core/lib/gprpp/xxhash_inline.h | 29 +++++++++++++++++++ .../lb_policy/ring_hash_test.cc | 7 ++--- tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core.internal | 1 + 13 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 src/core/lib/gprpp/xxhash_inline.h diff --git a/Package.swift b/Package.swift index a51129dac56..d146bea100d 100644 --- a/Package.swift +++ b/Package.swift @@ -1273,6 +1273,7 @@ let package = Package( "src/core/lib/gprpp/windows/thd.cc", "src/core/lib/gprpp/work_serializer.cc", "src/core/lib/gprpp/work_serializer.h", + "src/core/lib/gprpp/xxhash_inline.h", "src/core/lib/handshaker/proxy_mapper.h", "src/core/lib/handshaker/proxy_mapper_registry.cc", "src/core/lib/handshaker/proxy_mapper_registry.h", diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index c0680f25ad7..339266f876d 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -770,6 +770,7 @@ libs: - src/core/lib/gprpp/unique_type_name.h - src/core/lib/gprpp/validation_errors.h - src/core/lib/gprpp/work_serializer.h + - src/core/lib/gprpp/xxhash_inline.h - src/core/lib/handshaker/proxy_mapper.h - src/core/lib/handshaker/proxy_mapper_registry.h - src/core/lib/http/format_request.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 4dd7f6d1561..c1abd44655f 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -867,6 +867,7 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/unique_type_name.h', 'src/core/lib/gprpp/validation_errors.h', 'src/core/lib/gprpp/work_serializer.h', + 'src/core/lib/gprpp/xxhash_inline.h', 'src/core/lib/handshaker/proxy_mapper.h', 'src/core/lib/handshaker/proxy_mapper_registry.h', 'src/core/lib/http/format_request.h', @@ -1937,6 +1938,7 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/unique_type_name.h', 'src/core/lib/gprpp/validation_errors.h', 'src/core/lib/gprpp/work_serializer.h', + 'src/core/lib/gprpp/xxhash_inline.h', 'src/core/lib/handshaker/proxy_mapper.h', 'src/core/lib/handshaker/proxy_mapper_registry.h', 'src/core/lib/http/format_request.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 23f155a7a35..0b1a2f6192c 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1376,6 +1376,7 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/windows/thd.cc', 'src/core/lib/gprpp/work_serializer.cc', 'src/core/lib/gprpp/work_serializer.h', + 'src/core/lib/gprpp/xxhash_inline.h', 'src/core/lib/handshaker/proxy_mapper.h', 'src/core/lib/handshaker/proxy_mapper_registry.cc', 'src/core/lib/handshaker/proxy_mapper_registry.h', @@ -2692,6 +2693,7 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/unique_type_name.h', 'src/core/lib/gprpp/validation_errors.h', 'src/core/lib/gprpp/work_serializer.h', + 'src/core/lib/gprpp/xxhash_inline.h', 'src/core/lib/handshaker/proxy_mapper.h', 'src/core/lib/handshaker/proxy_mapper_registry.h', 'src/core/lib/http/format_request.h', diff --git a/grpc.gemspec b/grpc.gemspec index 4a11b8603cd..4a3d069323b 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1279,6 +1279,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gprpp/windows/thd.cc ) s.files += %w( src/core/lib/gprpp/work_serializer.cc ) s.files += %w( src/core/lib/gprpp/work_serializer.h ) + s.files += %w( src/core/lib/gprpp/xxhash_inline.h ) s.files += %w( src/core/lib/handshaker/proxy_mapper.h ) s.files += %w( src/core/lib/handshaker/proxy_mapper_registry.cc ) s.files += %w( src/core/lib/handshaker/proxy_mapper_registry.h ) diff --git a/package.xml b/package.xml index afcc8667389..fcba71fbb01 100644 --- a/package.xml +++ b/package.xml @@ -1261,6 +1261,7 @@ + diff --git a/src/core/BUILD b/src/core/BUILD index ad5c3cd18e8..ceba70e75b9 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -4864,6 +4864,14 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "xxhash_inline", + hdrs = ["lib/gprpp/xxhash_inline.h"], + external_deps = ["xxhash"], + language = "c++", + deps = ["//:gpr_platform"], +) + grpc_cc_library( name = "grpc_lb_policy_ring_hash", srcs = [ @@ -4879,7 +4887,6 @@ grpc_cc_library( "absl/status:statusor", "absl/strings", "absl/types:optional", - "xxhash", ], language = "c++", deps = [ @@ -4900,6 +4907,7 @@ grpc_cc_library( "resolved_address", "unique_type_name", "validation_errors", + "xxhash_inline", "//:channel_arg_names", "//:config", "//:debug_location", @@ -5536,7 +5544,6 @@ grpc_cc_library( "absl/types:optional", "absl/types:variant", "re2", - "xxhash", ], language = "c++", deps = [ @@ -5557,6 +5564,7 @@ grpc_cc_library( "ref_counted", "slice", "time", + "xxhash_inline", "//:channel_arg_names", "//:config", "//:debug_location", diff --git a/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc b/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc index 25bc10f5033..5881f168c86 100644 --- a/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +++ b/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc @@ -37,9 +37,6 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" -#define XXH_INLINE_ALL -#include "xxhash.h" - #include #include #include @@ -58,6 +55,7 @@ #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/unique_type_name.h" #include "src/core/lib/gprpp/work_serializer.h" +#include "src/core/lib/gprpp/xxhash_inline.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/exec_ctx.h" diff --git a/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc b/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc index 58b932b8055..5cc800a1fd0 100644 --- a/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc @@ -16,6 +16,8 @@ #include +#include "src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h" + #include #include @@ -44,12 +46,6 @@ #include "re2/re2.h" #include - -#include "src/core/lib/slice/slice.h" - -#define XXH_INLINE_ALL -#include "xxhash.h" - #include #include #include @@ -57,7 +53,6 @@ #include "src/core/ext/filters/client_channel/client_channel_internal.h" #include "src/core/ext/filters/client_channel/config_selector.h" #include "src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h" -#include "src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h" #include "src/core/ext/xds/xds_bootstrap.h" #include "src/core/ext/xds/xds_bootstrap_grpc.h" #include "src/core/ext/xds/xds_client_grpc.h" @@ -82,6 +77,7 @@ #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/work_serializer.h" +#include "src/core/lib/gprpp/xxhash_inline.h" #include "src/core/lib/iomgr/iomgr_fwd.h" #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/promise/arena_promise.h" @@ -92,6 +88,7 @@ #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/service_config/service_config.h" #include "src/core/lib/service_config/service_config_impl.h" +#include "src/core/lib/slice/slice.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/transport.h" #include "src/core/lib/uri/uri_parser.h" diff --git a/src/core/lib/gprpp/xxhash_inline.h b/src/core/lib/gprpp/xxhash_inline.h new file mode 100644 index 00000000000..6b12c711216 --- /dev/null +++ b/src/core/lib/gprpp/xxhash_inline.h @@ -0,0 +1,29 @@ +// +// Copyright 2023 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef GRPC_SRC_CORE_LIB_GPRPP_XXHASH_INLINE_H +#define GRPC_SRC_CORE_LIB_GPRPP_XXHASH_INLINE_H + +#include + +// This header is a simple wrapper around the third-party xxhash +// library, so that we don't need to define XXH_INLINE_ALL in every file +// that includes xxhash.h. That definition confuses clang-format's +// ordering of includes. +#define XXH_INLINE_ALL +#include "xxhash.h" + +#endif // GRPC_SRC_CORE_LIB_GPRPP_XXHASH_INLINE_H diff --git a/test/core/client_channel/lb_policy/ring_hash_test.cc b/test/core/client_channel/lb_policy/ring_hash_test.cc index c01a50ed65d..b911f98c3f7 100644 --- a/test/core/client_channel/lb_policy/ring_hash_test.cc +++ b/test/core/client_channel/lb_policy/ring_hash_test.cc @@ -14,6 +14,8 @@ // limitations under the License. // +#include "src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h" + #include #include @@ -29,14 +31,11 @@ #include "absl/types/optional.h" #include "gtest/gtest.h" -#define XXH_INLINE_ALL -#include "xxhash.h" - #include #include -#include "src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/lib/gprpp/xxhash_inline.h" #include "src/core/lib/json/json.h" #include "src/core/lib/load_balancing/lb_policy.h" #include "src/core/lib/resolver/endpoint_addresses.h" diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 793e0ffa6ce..1478fb19a99 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -2277,6 +2277,7 @@ src/core/lib/gprpp/windows/stat.cc \ src/core/lib/gprpp/windows/thd.cc \ src/core/lib/gprpp/work_serializer.cc \ src/core/lib/gprpp/work_serializer.h \ +src/core/lib/gprpp/xxhash_inline.h \ src/core/lib/handshaker/proxy_mapper.h \ src/core/lib/handshaker/proxy_mapper_registry.cc \ src/core/lib/handshaker/proxy_mapper_registry.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 5f4a723fb43..dc13e11119c 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -2056,6 +2056,7 @@ src/core/lib/gprpp/windows/stat.cc \ src/core/lib/gprpp/windows/thd.cc \ src/core/lib/gprpp/work_serializer.cc \ src/core/lib/gprpp/work_serializer.h \ +src/core/lib/gprpp/xxhash_inline.h \ src/core/lib/handshaker/proxy_mapper.h \ src/core/lib/handshaker/proxy_mapper_registry.cc \ src/core/lib/handshaker/proxy_mapper_registry.h \