Skip to content

[DRAFT] Test out protobuf v30.0-rc1 presubmit.yml with Bazel 8 #3779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions modules/protobuf/30.0-rc1.bcr.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/protocolbuffers/protobuf/issues/14313

module(
name = "protobuf",
version = "30.0-rc1.bcr.1", # Automatically updated on release
compatibility_level = 1,
repo_name = "com_google_protobuf",
)

# LOWER BOUND dependency versions.
# Bzlmod follows MVS:
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
# Thus the highest version in their module graph is resolved.
bazel_dep(name = "abseil-cpp", version = "20240722.0", repo_name = "com_google_absl")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "jsoncpp", version = "1.9.6")
bazel_dep(name = "rules_apple", version = "3.13.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "apple_support", version = "1.15.1", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_jvm_external", version = "6.3")
bazel_dep(name = "rules_kotlin", version = "1.9.6")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "1.0.0")
bazel_dep(name = "rules_rust", version = "0.51.0")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
bazel_dep(name = "bazel_features", version = "1.23.0", repo_name = "proto_bazel_features")
bazel_dep(
name = "rules_shell",
version = "0.2.0",
)

# Proto toolchains
register_toolchains("//bazel/private/toolchains:all")

SUPPORTED_PYTHON_VERSIONS = [
"3.9",
"3.10",
"3.11",
"3.12",
]

# TODO: Support hermetic / system python in bzlmod.
python = use_extension("@rules_python//python/extensions:python.bzl", "python")

[
python.toolchain(
# Disable root warning for .pyc cache misses since CI runs as root.
# See https://github.com/bazelbuild/rules_python/pull/713
ignore_root_user_error = True,
is_default = python_version == SUPPORTED_PYTHON_VERSIONS[-1],
python_version = python_version,
)
for python_version in SUPPORTED_PYTHON_VERSIONS
]

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True)

[
pip.parse(
hub_name = "protobuf_pip_deps",
python_version = python_version,
requirements_lock = "//python:requirements.txt",
)
for python_version in SUPPORTED_PYTHON_VERSIONS
]

use_repo(pip, "protobuf_pip_deps")

crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate", dev_dependency = True)
crate.spec(
package = "googletest",
version = ">0.0.0",
)
crate.spec(
package = "paste",
version = ">=1",
)
crate.from_specs()
use_repo(crate, crate_index = "crates")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven", dev_dependency = True)
maven.install(
name = "protobuf_maven",
artifacts = [
"com.google.caliper:caliper:1.0-beta-3",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.5.1",
"com.google.j2objc:j2objc-annotations:2.8",
"com.google.guava:guava:32.0.1-jre",
"com.google.guava:guava-testlib:32.0.1-jre",
"com.google.testparameterinjector:test-parameter-injector:1.18",
"com.google.truth:truth:1.1.2",
"junit:junit:4.13.2",
"org.mockito:mockito-core:4.3.1",
"biz.aQute.bnd:biz.aQute.bndlib:6.4.0",
"info.picocli:picocli:4.6.3",
],
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
],
)
use_repo(maven, "protobuf_maven")

# Development dependencies
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "rules_buf", version = "0.3.0", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
bazel_dep(
name = "abseil-py",
version = "2.1.0",
dev_dependency = True,
repo_name = "com_google_absl_py",
)

# For clang-cl configuration
cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc")

# rules_proto are needed for @com_google_protobuf_v25.0 used in //compatibility/... tests
bazel_dep(name = "rules_proto", version = "4.0.0", dev_dependency = True)
121 changes: 121 additions & 0 deletions modules/protobuf/30.0-rc1.bcr.1/patches/patch-ef309f0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h
index 806337e32..f52182de6 100644
--- a/src/google/protobuf/descriptor.h
+++ b/src/google/protobuf/descriptor.h
@@ -31,7 +31,6 @@
#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__
#define GOOGLE_PROTOBUF_DESCRIPTOR_H__

-#include <any>
#include <atomic>
#include <cstdint>
#include <iterator>
@@ -2455,11 +2454,20 @@ class PROTOBUF_EXPORT DescriptorPool {
friend class google::protobuf::descriptor_unittest::ValidationErrorTest;
friend class ::google::protobuf::compiler::CommandLineInterface;
friend class TextFormat;
+
+ struct MemoBase {
+ virtual ~MemoBase() = default;
+ };
+ template <typename T>
+ struct MemoData : MemoBase {
+ T value;
+ };
+
// Memoize a projection of a field. This is used to cache the results of
// calling a function on a field, used for expensive descriptor calculations.
template <typename Func>
- auto MemoizeProjection(const FieldDescriptor* field, Func func) const {
- using ResultT = decltype(func(field));
+ const auto& MemoizeProjection(const FieldDescriptor* field, Func func) const {
+ using ResultT = std::decay_t<decltype(func(field))>;
ABSL_DCHECK(field->file()->pool() == this);
static_assert(std::is_empty_v<Func>);
// This static bool is unique per-Func, so its address can be used as a key.
@@ -2469,15 +2477,21 @@ class PROTOBUF_EXPORT DescriptorPool {
absl::ReaderMutexLock lock(&field_memo_table_mutex_);
auto it = field_memo_table_.find(key);
if (it != field_memo_table_.end()) {
- return std::any_cast<ResultT>(it->second);
+ return internal::DownCast<const MemoData<ResultT>&>(*it->second).value;
}
}
- ResultT result = func(field);
+ auto result = std::make_unique<MemoData<ResultT>>();
+ result->value = func(field);
{
absl::MutexLock lock(&field_memo_table_mutex_);
- field_memo_table_[key] = result;
+ auto& res = field_memo_table_[key];
+ // Only initialize the first time. We don't want to invalidate old
+ // references.
+ if (res == nullptr) {
+ res = std::move(result);
+ }
+ return internal::DownCast<const MemoData<ResultT>&>(*res).value;
}
- return result;
}
// Return true if the given name is a sub-symbol of any non-package
// descriptor that already exists in the descriptor pool. (The full
@@ -2537,9 +2551,12 @@ class PROTOBUF_EXPORT DescriptorPool {
Symbol NewPlaceholderWithMutexHeld(absl::string_view name,
PlaceholderType placeholder_type) const;

+#ifndef SWIG
mutable absl::Mutex field_memo_table_mutex_;
- mutable absl::flat_hash_map<std::pair<const void*, const void*>, std::any>
+ mutable absl::flat_hash_map<std::pair<const void*, const void*>,
+ std::unique_ptr<MemoBase>>
field_memo_table_ ABSL_GUARDED_BY(field_memo_table_mutex_);
+#endif // SWIG

// If fallback_database_ is nullptr, this is nullptr. Otherwise, this is a
// mutex which must be locked while accessing tables_.
diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc
index 8650815ac..240fe223b 100644
--- a/src/google/protobuf/descriptor_unittest.cc
+++ b/src/google/protobuf/descriptor_unittest.cc
@@ -27,6 +27,7 @@
#include <string>
#include <thread> // NOLINT
#include <tuple>
+#include <type_traits>
#include <utility>
#include <vector>

@@ -11819,8 +11820,8 @@ TEST_F(DescriptorPoolFeaturesTest, ResolvesFeaturesFor) {
class DescriptorPoolMemoizationTest : public ::testing::Test {
protected:
template <typename Func>
- auto MemoizeProjection(const DescriptorPool* pool,
- const FieldDescriptor* field, Func func) {
+ const auto& MemoizeProjection(const DescriptorPool* pool,
+ const FieldDescriptor* field, Func func) {
return pool->MemoizeProjection(field, func);
};
};
@@ -11834,15 +11835,20 @@ TEST_F(DescriptorPoolMemoizationTest, MemoizeProjectionBasic) {
proto2_unittest::TestAllTypes message;
const Descriptor* descriptor = message.GetDescriptor();

- auto name = DescriptorPoolMemoizationTest::MemoizeProjection(
+ const auto& name = DescriptorPoolMemoizationTest::MemoizeProjection(
descriptor->file()->pool(), descriptor->field(0), name_lambda);
- auto dupe_name = DescriptorPoolMemoizationTest::MemoizeProjection(
+ const auto& dupe_name = DescriptorPoolMemoizationTest::MemoizeProjection(
descriptor->file()->pool(), descriptor->field(0), name_lambda);

ASSERT_EQ(counter, 1);
ASSERT_EQ(name, "proto2_unittest.TestAllTypes.optional_int32");
ASSERT_EQ(dupe_name, "proto2_unittest.TestAllTypes.optional_int32");

+ // Check that they are references aliasing the same object.
+ EXPECT_TRUE(
+ (std::is_same_v<decltype(name), const decltype(descriptor->name()) &>));
+ EXPECT_EQ(&name, &dupe_name);
+
auto other_name = DescriptorPoolMemoizationTest::MemoizeProjection(
descriptor->file()->pool(), descriptor->field(1), name_lambda);

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/MODULE.bazel b/MODULE.bazel
index b4385e038..27fa3b1b2 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -3,7 +3,7 @@

module(
name = "protobuf",
- version = "30.0-rc1", # Automatically updated on release
+ version = "30.0-rc1.bcr.1", # Automatically updated on release
compatibility_level = 1,
repo_name = "com_google_protobuf",
)
diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel
index 268ecbb65..394078305 100644
--- a/build_defs/BUILD.bazel
+++ b/build_defs/BUILD.bazel
@@ -28,7 +28,6 @@ platform(
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
- "@bazel_tools//tools/cpp:clang-cl",
# This is necessary for Bazel 7 compatibility with a MODULE.bazel file that still works in
# Bazel 8. Using cc_configure_extension from rules_cc produces a @local_config_cc
# repository that's not compatible with @bazel_tools//tools/cpp:clang-cl from before
@@ -42,7 +41,6 @@ platform(
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
- "@bazel_tools//tools/cpp:msvc",
# This may be necessary in case cc_configure_extension from rules_cc produces a
# @local_config_cc repository that's not compatible with @bazel_tools//tools/cpp:msvc from
# before Bazel 8, as with clang-cl above, to avoid silently falling back to clang-cl.
20 changes: 20 additions & 0 deletions modules/protobuf/30.0-rc1.bcr.1/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bcr_test_module:
module_path: examples
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel: [7.x, 8.x]

tasks:
verify_targets:
name: "Verify build targets"
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- '//...'
- '@com_google_protobuf//:protobuf'
- '@com_google_protobuf//:protobuf_lite'
- '@com_google_protobuf//:protobuf_python'
- '@com_google_protobuf//:protobuf_java'
- '@com_google_protobuf//:protoc'
- '@com_google_protobuf//:test_messages_proto2_cc_proto'
- '@com_google_protobuf//:test_messages_proto3_cc_proto'
10 changes: 10 additions & 0 deletions modules/protobuf/30.0-rc1.bcr.1/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"integrity": "sha256-p0wGf/NH7knNqhLEz3bbmNIsvL6iOrOBPX1TwGAToWA=",
"patch_strip": 1,
"patches": {
"remove-redundant-clang-cl-msvc-constraint.patch": "sha256-czCEk8K2PJtWhv5GfsMBX1vTsWU7AHA3bBRpwPSjkhs=",
"patch-ef309f0.patch": "sha256-d0sQMqZg3Wg/gStMoV+0u9Z6KO0PF2ThuUwF7JGNCkY="
},
"strip_prefix": "protobuf-30.0-rc1",
"url": "https://github.com/protocolbuffers/protobuf/releases/download/v30.0-rc1/protobuf-30.0-rc1.zip"
}
Loading
Loading