diff --git a/.bazelrc b/.bazelrc index fb29fe1..1d38585 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,4 @@ -build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 +build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 build:dbg --compilation_mode=dbg @@ -26,3 +26,5 @@ build:ubsan --copt=-DUNDEFINED_SANITIZER=1 # Workaround for the fact that Bazel links with $CC, not $CXX # https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748 build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr + +common --enable_bzlmod diff --git a/.bazelversion b/.bazelversion index dfda3e0..e8be684 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.1.0 +7.6.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f69f3a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bazel-* +MODULE.bazel.lock diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..7ff75d7 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,13 @@ +module( + name = "proto-converter", + repo_name = "proto_converter", +) + +bazel_dep(name = "abseil-cpp", version = "20240116.2", repo_name = "com_google_absl") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf") +bazel_dep(name = "rules_cc", version = "0.0.16") +bazel_dep(name = "rules_pkg", version = "1.0.1") + +bazel_dep(name = "googletest", version = "1.15.0", dev_dependency = True, repo_name = "com_google_googletest") diff --git a/WORKSPACE b/WORKSPACE index 78ef765..e5febbe 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,36 +3,34 @@ workspace(name = "proto_converter") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "com_google_googletest", - sha256 = "730215d76eace9dd49bf74ce044e8daa065d175f1ac891cc1d6bb184ef94e565", - strip_prefix = "googletest-f53219cdcb7b084ef57414efea92ee5b71989558", - urls = [ - "https://github.com/google/googletest/archive/f53219cdcb7b084ef57414efea92ee5b71989558.tar.gz", # 2023-03-16 - ], + name = "com_google_protobuf", + sha256 = "55912546338433f465a552e9ef09930c63b9eb697053937416890cff83a8622d", + strip_prefix = "protobuf-b407e8416e3893036aee5af9a12bd9b6a0e2b2e6", + urls = ["https://github.com/protocolbuffers/protobuf/archive/b407e8416e3893036aee5af9a12bd9b6a0e2b2e6.tar.gz"], # v29.3 ) -load("@com_google_googletest//:googletest_deps.bzl", "googletest_deps") +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") -googletest_deps() +protobuf_deps() -http_archive( - name = "com_google_protobuf", - sha256 = "aa61db6ff113a1c76eac9408144c6e996c5e2d6b2410818fd7f1b0d222a50bf8", - strip_prefix = "protobuf-315ffb5be89460f2857387d20aefc59b76b8bdc3", # 5.31.2023 - urls = ["https://github.com/protocolbuffers/protobuf/archive/315ffb5be89460f2857387d20aefc59b76b8bdc3.tar.gz"], -) +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies") + +pip_install_dependencies() http_archive( - name = "upb", - patches = ["@com_google_protobuf//build_defs:upb.patch"], - sha256 = "8c4f3a4fca45da3c7d808a48cb730ae12af6d97462a9ad60e529d29da24cca03", - strip_prefix = "upb-7a04b4027d737828c9c5b8be56c838d5db0db80f", + name = "com_google_googletest", + sha256 = "7315acb6bf10e99f332c8a43f00d5fbb1ee6ca48c52f6b936991b216c586aaad", + strip_prefix = "googletest-1.15.0", urls = [ - "https://github.com/protocolbuffers/upb/archive/7a04b4027d737828c9c5b8be56c838d5db0db80f.tar.gz", + "https://github.com/google/googletest/releases/download/v1.15.0/googletest-1.15.0.tar.gz", # 2024-07-15 ], ) -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") +load("@com_google_googletest//:googletest_deps.bzl", "googletest_deps") -protobuf_deps() +googletest_deps() diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000..7bc6f4b --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1 @@ +workspace(name = "proto_converter") diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel index 732514d..faaa5f7 100644 --- a/build_defs/BUILD.bazel +++ b/build_defs/BUILD.bazel @@ -1,7 +1,6 @@ # Internal Starlark definitions for Protobuf. load("@bazel_skylib//lib:selects.bzl", "selects") -load("@rules_cc//cc:defs.bzl", starlark_cc_proto_library = "cc_proto_library") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load(":compiler_config_setting.bzl", "create_compiler_config_setting") diff --git a/src/google/protobuf/stubs/BUILD.bazel b/src/google/protobuf/stubs/BUILD.bazel index a7b8c82..238b05b 100644 --- a/src/google/protobuf/stubs/BUILD.bazel +++ b/src/google/protobuf/stubs/BUILD.bazel @@ -20,7 +20,7 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") package( - default_visibility = ["//:__subpackages__"], + default_visibility = ["//:__subpackages__"], ) cc_library( diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 94fe003..bf9ab40 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -48,7 +48,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 4022003 +#define GOOGLE_PROTOBUF_VERSION 5029003 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/util/converter/BUILD.bazel b/src/google/protobuf/util/converter/BUILD.bazel index bff9574..58a80a3 100644 --- a/src/google/protobuf/util/converter/BUILD.bazel +++ b/src/google/protobuf/util/converter/BUILD.bazel @@ -11,10 +11,10 @@ # 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. - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_proto//proto:defs.bzl", "proto_library") load("//build_defs:cpp_opts.bzl", "COPTS") package( @@ -79,6 +79,7 @@ cc_library( ":utility", "//src/google/protobuf/stubs", "//src/google/protobuf/util/converter:port_def", + "@com_google_absl//absl/container:flat_hash_set", ], ) @@ -137,6 +138,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", + "@com_google_protobuf//third_party/utf8_range:utf8_validity", ], ) @@ -194,6 +196,8 @@ cc_library( deps = [ ":utility", "//src/google/protobuf/stubs", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_protobuf//:protobuf", ], ) @@ -238,6 +242,9 @@ cc_library( ":type_info", ":utility", "//src/google/protobuf/stubs", + "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", ], @@ -295,6 +302,7 @@ cc_library( deps = [ ":constants", "//src/google/protobuf/stubs", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", ], @@ -360,6 +368,7 @@ proto_library( testonly = 1, srcs = ["testdata/default_value_test.proto"], strip_import_prefix = "/src", + deps = ["@com_google_protobuf//:struct_proto"], ) cc_proto_library( @@ -419,6 +428,11 @@ proto_library( testonly = 1, srcs = ["testdata/proto3.proto"], strip_import_prefix = "/src", + deps = [ + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:struct_proto", + "@com_google_protobuf//:wrappers_proto", + ], ) cc_proto_library( diff --git a/src/google/protobuf/util/converter/default_value_objectwriter.cc b/src/google/protobuf/util/converter/default_value_objectwriter.cc index cb6a0ad..bf595cb 100644 --- a/src/google/protobuf/util/converter/default_value_objectwriter.cc +++ b/src/google/protobuf/util/converter/default_value_objectwriter.cc @@ -298,7 +298,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren( absl::flat_hash_map orig_children_map; // Creates a map of child nodes to speed up lookup. - for (int i = 0; i < children_.size(); ++i) { + for (size_t i = 0; i < children_.size(); ++i) { orig_children_map.try_emplace(children_[i]->name_, i); } @@ -375,7 +375,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren( new_children.push_back(child.release()); } // Adds all leftover nodes in children_ to the beginning of new_child. - for (int i = 0; i < children_.size(); ++i) { + for (size_t i = 0; i < children_.size(); ++i) { if (children_[i] == nullptr) { continue; } diff --git a/src/google/protobuf/util/converter/default_value_objectwriter.h b/src/google/protobuf/util/converter/default_value_objectwriter.h index 0b253c8..95816e9 100644 --- a/src/google/protobuf/util/converter/default_value_objectwriter.h +++ b/src/google/protobuf/util/converter/default_value_objectwriter.h @@ -144,7 +144,7 @@ class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { Node(const Node&) = delete; Node& operator=(const Node&) = delete; virtual ~Node() { - for (int i = 0; i < children_.size(); ++i) { + for (size_t i = 0; i < children_.size(); ++i) { delete children_[i]; } } diff --git a/src/google/protobuf/util/converter/port_def.inc b/src/google/protobuf/util/converter/port_def.inc index 41af5b7..03331a8 100644 --- a/src/google/protobuf/util/converter/port_def.inc +++ b/src/google/protobuf/util/converter/port_def.inc @@ -221,25 +221,9 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #endif -#ifdef PROTOBUF_VERSION -#error PROTOBUF_VERSION was previously defined -#endif -#define PROTOBUF_VERSION 4023000 - -#ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC -#error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined -#endif -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4023000 - -#ifdef PROTOBUF_MIN_PROTOC_VERSION -#error PROTOBUF_MIN_PROTOC_VERSION was previously defined -#endif -#define PROTOBUF_MIN_PROTOC_VERSION 4023000 - -#ifdef PROTOBUF_VERSION_SUFFIX -#error PROTOBUF_VERSION_SUFFIX was previously defined -#endif -#define PROTOBUF_VERSION_SUFFIX "" +// Note: PROTOBUF_VERSION and related macros are now defined by the external +// protobuf library's runtime_version.h. We don't redefine them here to avoid +// conflicts with the protobuf library's version checking. #ifdef PROTOBUF_ALWAYS_INLINE #error PROTOBUF_ALWAYS_INLINE was previously defined @@ -447,9 +431,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), // which the offsets of the direct fields of a class are non-constant. // Fields inherited from superclasses *can* have non-constant offsets, // but that's not what this macro will be used for. -#ifdef PROTOBUF_FIELD_OFFSET -#error PROTOBUF_FIELD_OFFSET was previously defined -#endif +#ifndef PROTOBUF_FIELD_OFFSET #if defined(__clang__) // For Clang we use __builtin_offsetof() and suppress the warning, // to avoid Control Flow Integrity and UBSan vptr sanitizers from @@ -471,6 +453,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), &reinterpret_cast(16)->FIELD) - \ reinterpret_cast(16)) #endif +#endif // PROTOBUF_FIELD_OFFSET #ifdef PROTOBUF_EXPORT #error PROTOBUF_EXPORT was previously defined diff --git a/src/google/protobuf/util/converter/port_undef.inc b/src/google/protobuf/util/converter/port_undef.inc index 1756b1a..a40f4c6 100644 --- a/src/google/protobuf/util/converter/port_undef.inc +++ b/src/google/protobuf/util/converter/port_undef.inc @@ -32,11 +32,9 @@ #undef PROTOBUF_RETURNS_NONNULL #undef PROTOBUF_ATTRIBUTE_REINITIALIZES #undef PROTOBUF_RTTI -#undef PROTOBUF_VERSION -#undef PROTOBUF_VERSION_SUFFIX +// Note: PROTOBUF_VERSION and related macros are not undefined here because +// they are now managed by the external protobuf library, not by our port_def.inc #undef PROTOBUF_FIELD_OFFSET -#undef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC -#undef PROTOBUF_MIN_PROTOC_VERSION #undef PROTOBUF_PREDICT_TRUE #undef PROTOBUF_PREDICT_FALSE #undef PROTOBUF_FALLTHROUGH_INTENDED diff --git a/src/google/protobuf/util/converter/protostream_objectwriter.cc b/src/google/protobuf/util/converter/protostream_objectwriter.cc index 5489063..bb7b192 100644 --- a/src/google/protobuf/util/converter/protostream_objectwriter.cc +++ b/src/google/protobuf/util/converter/protostream_objectwriter.cc @@ -384,7 +384,7 @@ void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) { // Now we know the proto type and can interpret all data fields we gathered // before the "@type" field. - for (int i = 0; i < uninterpreted_events_.size(); ++i) { + for (size_t i = 0; i < uninterpreted_events_.size(); ++i) { uninterpreted_events_[i].Replay(this); } } diff --git a/src/google/protobuf/util/converter/type_info_test_helper.cc b/src/google/protobuf/util/converter/type_info_test_helper.cc index 82011ca..cc89f39 100644 --- a/src/google/protobuf/util/converter/type_info_test_helper.cc +++ b/src/google/protobuf/util/converter/type_info_test_helper.cc @@ -40,7 +40,7 @@ void TypeInfoTestHelper::ResetTypeInfo( switch (type_) { case USE_TYPE_RESOLVER: { const DescriptorPool* pool = descriptors[0]->file()->pool(); - for (int i = 1; i < descriptors.size(); ++i) { + for (size_t i = 1; i < descriptors.size(); ++i) { ABSL_QCHECK(pool == descriptors[i]->file()->pool()) << "Descriptors from different pools are not supported."; } diff --git a/src/google/protobuf/util/converter/utility.cc b/src/google/protobuf/util/converter/utility.cc index 0770b0a..65362b5 100644 --- a/src/google/protobuf/util/converter/utility.cc +++ b/src/google/protobuf/util/converter/utility.cc @@ -132,7 +132,7 @@ std::string GetFullTypeWithUrl(absl::string_view simple_type) { const google::protobuf::Option* FindOptionOrNull( const RepeatedPtrField& options, absl::string_view option_name) { - for (int i = 0; i < options.size(); ++i) { + for (size_t i = 0; i < options.size(); ++i) { const google::protobuf::Option& opt = options.Get(i); if (opt.name() == option_name) { return &opt;