Skip to content

Commit 02cbb35

Browse files
jckingcopybara-github
authored andcommitted
Ensure mandatory messages are linked with the generated descriptor pool
PiperOrigin-RevId: 691010654
1 parent feaecdb commit 02cbb35

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

internal/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ cc_library(
683683
"//common:json",
684684
"//common:memory",
685685
"//extensions/protobuf/internal:map_reflection",
686+
"@com_google_absl//absl/base",
686687
"@com_google_absl//absl/base:core_headers",
687688
"@com_google_absl//absl/base:no_destructor",
688689
"@com_google_absl//absl/base:nullability",

internal/well_known_types.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
#include "google/protobuf/any.pb.h"
2525
#include "google/protobuf/duration.pb.h"
26+
#include "google/protobuf/field_mask.pb.h"
2627
#include "google/protobuf/struct.pb.h"
2728
#include "google/protobuf/timestamp.pb.h"
2829
#include "google/protobuf/wrappers.pb.h"
2930
#include "google/protobuf/descriptor.pb.h"
3031
#include "absl/base/attributes.h"
32+
#include "absl/base/call_once.h"
3133
#include "absl/base/no_destructor.h"
3234
#include "absl/base/nullability.h"
3335
#include "absl/base/optimization.h"
@@ -1735,7 +1737,36 @@ absl::StatusOr<FieldMaskReflection> GetFieldMaskReflection(
17351737
return reflection;
17361738
}
17371739

1740+
namespace {
1741+
1742+
ABSL_CONST_INIT absl::once_flag link_well_known_message_reflection;
1743+
1744+
void LinkWellKnownMessageReflection() {
1745+
google::protobuf::LinkMessageReflection<google::protobuf::BoolValue>();
1746+
google::protobuf::LinkMessageReflection<google::protobuf::Int32Value>();
1747+
google::protobuf::LinkMessageReflection<google::protobuf::Int64Value>();
1748+
google::protobuf::LinkMessageReflection<google::protobuf::UInt32Value>();
1749+
google::protobuf::LinkMessageReflection<google::protobuf::UInt64Value>();
1750+
google::protobuf::LinkMessageReflection<google::protobuf::FloatValue>();
1751+
google::protobuf::LinkMessageReflection<google::protobuf::DoubleValue>();
1752+
google::protobuf::LinkMessageReflection<google::protobuf::BytesValue>();
1753+
google::protobuf::LinkMessageReflection<google::protobuf::StringValue>();
1754+
google::protobuf::LinkMessageReflection<google::protobuf::Any>();
1755+
google::protobuf::LinkMessageReflection<google::protobuf::Duration>();
1756+
google::protobuf::LinkMessageReflection<google::protobuf::Timestamp>();
1757+
google::protobuf::LinkMessageReflection<google::protobuf::Value>();
1758+
google::protobuf::LinkMessageReflection<google::protobuf::ListValue>();
1759+
google::protobuf::LinkMessageReflection<google::protobuf::Struct>();
1760+
google::protobuf::LinkMessageReflection<google::protobuf::FieldMask>();
1761+
}
1762+
1763+
} // namespace
1764+
17381765
absl::Status Reflection::Initialize(absl::Nonnull<const DescriptorPool*> pool) {
1766+
if (pool == DescriptorPool::generated_pool()) {
1767+
absl::call_once(link_well_known_message_reflection,
1768+
&LinkWellKnownMessageReflection);
1769+
}
17391770
CEL_RETURN_IF_ERROR(NullValue().Initialize(pool));
17401771
CEL_RETURN_IF_ERROR(BoolValue().Initialize(pool));
17411772
CEL_RETURN_IF_ERROR(Int32Value().Initialize(pool));

0 commit comments

Comments
 (0)