Skip to content

Commit c91572c

Browse files
jckingcopybara-github
authored andcommitted
Expose minimal descriptor set as google::protobuf::DescriptorDatabase
PiperOrigin-RevId: 736835441
1 parent 34dec22 commit c91572c

File tree

7 files changed

+274
-6
lines changed

7 files changed

+274
-6
lines changed

common/BUILD

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ cc_library(
820820
srcs = ["minimal_descriptor_pool.cc"],
821821
hdrs = ["minimal_descriptor_pool.h"],
822822
deps = [
823-
"//internal:minimal_descriptor_pool",
823+
"//internal:minimal_descriptors",
824824
"@com_google_absl//absl/base:nullability",
825825
"@com_google_protobuf//:protobuf",
826826
],
@@ -836,6 +836,27 @@ cc_test(
836836
],
837837
)
838838

839+
cc_library(
840+
name = "minimal_descriptor_database",
841+
srcs = ["minimal_descriptor_database.cc"],
842+
hdrs = ["minimal_descriptor_database.h"],
843+
deps = [
844+
"//internal:minimal_descriptors",
845+
"@com_google_absl//absl/base:nullability",
846+
"@com_google_protobuf//:protobuf",
847+
],
848+
)
849+
850+
cc_test(
851+
name = "minimal_descriptor_database_test",
852+
srcs = ["minimal_descriptor_database_test.cc"],
853+
deps = [
854+
":minimal_descriptor_database",
855+
"//internal:testing",
856+
"@com_google_protobuf//:protobuf",
857+
],
858+
)
859+
839860
cc_library(
840861
name = "function_descriptor",
841862
srcs = [
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "common/minimal_descriptor_database.h"
16+
17+
#include "absl/base/nullability.h"
18+
#include "internal/minimal_descriptor_database.h"
19+
#include "google/protobuf/descriptor_database.h"
20+
21+
namespace cel {
22+
23+
absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase() {
24+
return internal::GetMinimalDescriptorDatabase();
25+
}
26+
27+
} // namespace cel
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_DATABASE_H_
16+
#define THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_DATABASE_H_
17+
18+
#include "absl/base/nullability.h"
19+
#include "google/protobuf/descriptor_database.h"
20+
21+
namespace cel {
22+
23+
// GetMinimalDescriptorDatabase returns a pointer to a
24+
// `google::protobuf::DescriptorDatabase` which includes has the minimally necessary
25+
// descriptors required by the Common Expression Language. The returned
26+
// `google::protobuf::DescriptorDatabase` is valid for the lifetime of the process and
27+
// should not be deleted.
28+
absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase();
29+
30+
} // namespace cel
31+
32+
#endif // THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_DATABASE_H_
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "common/minimal_descriptor_database.h"
16+
17+
#include "google/protobuf/descriptor.pb.h"
18+
#include "internal/testing.h"
19+
#include "google/protobuf/descriptor.h"
20+
21+
namespace cel {
22+
namespace {
23+
24+
using ::testing::IsTrue;
25+
26+
TEST(GetMinimalDescriptorDatabase, NullValue) {
27+
google::protobuf::FileDescriptorProto fd;
28+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
29+
"google.protobuf.NullValue", &fd),
30+
IsTrue());
31+
}
32+
33+
TEST(GetMinimalDescriptorDatabase, BoolValue) {
34+
google::protobuf::FileDescriptorProto fd;
35+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
36+
"google.protobuf.BoolValue", &fd),
37+
IsTrue());
38+
}
39+
40+
TEST(GetMinimalDescriptorDatabase, Int32Value) {
41+
google::protobuf::FileDescriptorProto fd;
42+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
43+
"google.protobuf.Int32Value", &fd),
44+
IsTrue());
45+
}
46+
47+
TEST(GetMinimalDescriptorDatabase, Int64Value) {
48+
google::protobuf::FileDescriptorProto fd;
49+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
50+
"google.protobuf.Int64Value", &fd),
51+
IsTrue());
52+
}
53+
54+
TEST(GetMinimalDescriptorDatabase, UInt32Value) {
55+
google::protobuf::FileDescriptorProto fd;
56+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
57+
"google.protobuf.UInt32Value", &fd),
58+
IsTrue());
59+
}
60+
61+
TEST(GetMinimalDescriptorDatabase, UInt64Value) {
62+
google::protobuf::FileDescriptorProto fd;
63+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
64+
"google.protobuf.UInt64Value", &fd),
65+
IsTrue());
66+
}
67+
68+
TEST(GetMinimalDescriptorDatabase, FloatValue) {
69+
google::protobuf::FileDescriptorProto fd;
70+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
71+
"google.protobuf.FloatValue", &fd),
72+
IsTrue());
73+
}
74+
75+
TEST(GetMinimalDescriptorDatabase, DoubleValue) {
76+
google::protobuf::FileDescriptorProto fd;
77+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
78+
"google.protobuf.DoubleValue", &fd),
79+
IsTrue());
80+
}
81+
82+
TEST(GetMinimalDescriptorDatabase, BytesValue) {
83+
google::protobuf::FileDescriptorProto fd;
84+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
85+
"google.protobuf.BytesValue", &fd),
86+
IsTrue());
87+
}
88+
89+
TEST(GetMinimalDescriptorDatabase, StringValue) {
90+
google::protobuf::FileDescriptorProto fd;
91+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
92+
"google.protobuf.StringValue", &fd),
93+
IsTrue());
94+
}
95+
96+
TEST(GetMinimalDescriptorDatabase, Any) {
97+
google::protobuf::FileDescriptorProto fd;
98+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
99+
"google.protobuf.Any", &fd),
100+
IsTrue());
101+
}
102+
103+
TEST(GetMinimalDescriptorDatabase, Duration) {
104+
google::protobuf::FileDescriptorProto fd;
105+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
106+
"google.protobuf.Duration", &fd),
107+
IsTrue());
108+
}
109+
110+
TEST(GetMinimalDescriptorDatabase, Timestamp) {
111+
google::protobuf::FileDescriptorProto fd;
112+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
113+
"google.protobuf.Timestamp", &fd),
114+
IsTrue());
115+
}
116+
117+
TEST(GetMinimalDescriptorDatabase, Value) {
118+
google::protobuf::FileDescriptorProto fd;
119+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
120+
"google.protobuf.Value", &fd),
121+
IsTrue());
122+
}
123+
124+
TEST(GetMinimalDescriptorDatabase, ListValue) {
125+
google::protobuf::FileDescriptorProto fd;
126+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
127+
"google.protobuf.ListValue", &fd),
128+
IsTrue());
129+
}
130+
131+
TEST(GetMinimalDescriptorDatabase, Struct) {
132+
google::protobuf::FileDescriptorProto fd;
133+
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
134+
"google.protobuf.Struct", &fd),
135+
IsTrue());
136+
}
137+
138+
} // namespace
139+
} // namespace cel

internal/BUILD

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,22 @@ cel_cc_embed(
434434
src = ":minimal_descriptor_set",
435435
)
436436

437-
cc_library(
437+
alias(
438438
name = "minimal_descriptor_pool",
439-
srcs = ["minimal_descriptor_pool.cc"],
440-
hdrs = ["minimal_descriptor_pool.h"],
439+
actual = ":minimal_descriptors",
440+
)
441+
442+
cc_library(
443+
name = "minimal_descriptors",
444+
srcs = ["minimal_descriptors.cc"],
445+
hdrs = [
446+
"minimal_descriptor_database.h",
447+
"minimal_descriptor_pool.h",
448+
],
441449
textual_hdrs = [":minimal_descriptor_set_embed"],
442450
deps = [
443451
"@com_google_absl//absl/base:core_headers",
452+
"@com_google_absl//absl/base:no_destructor",
444453
"@com_google_absl//absl/base:nullability",
445454
"@com_google_absl//absl/log:absl_check",
446455
"@com_google_protobuf//:protobuf",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_MINIMAL_DESCRIPTOR_DATABASE_H_
16+
#define THIRD_PARTY_CEL_CPP_INTERNAL_MINIMAL_DESCRIPTOR_DATABASE_H_
17+
18+
#include "absl/base/nullability.h"
19+
#include "google/protobuf/descriptor_database.h"
20+
21+
namespace cel::internal {
22+
23+
// GetMinimalDescriptorDatabase returns a pointer to a
24+
// `google::protobuf::DescriptorDatabase` which includes has the minimally necessary
25+
// descriptors required by the Common Expression Language. The returning
26+
// `google::protobuf::DescripDescriptorDatabasetorPool` is valid for the lifetime of the
27+
// process.
28+
absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase();
29+
30+
} // namespace cel::internal
31+
32+
#endif // THIRD_PARTY_CEL_CPP_INTERNAL_MINIMAL_DESCRIPTOR_DATABASE_H_

internal/minimal_descriptor_pool.cc renamed to internal/minimal_descriptors.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "internal/minimal_descriptor_pool.h"
16-
1715
#include <cstdint>
1816

1917
#include "google/protobuf/descriptor.pb.h"
2018
#include "absl/base/attributes.h"
2119
#include "absl/base/macros.h"
20+
#include "absl/base/no_destructor.h"
2221
#include "absl/base/nullability.h"
2322
#include "absl/log/absl_check.h"
23+
#include "internal/minimal_descriptor_database.h"
24+
#include "internal/minimal_descriptor_pool.h"
2425
#include "google/protobuf/descriptor.h"
26+
#include "google/protobuf/descriptor_database.h"
2527

2628
namespace cel::internal {
2729

@@ -47,4 +49,10 @@ absl::Nonnull<const google::protobuf::DescriptorPool*> GetMinimalDescriptorPool(
4749
return pool;
4850
}
4951

52+
absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase() {
53+
static absl::NoDestructor<google::protobuf::DescriptorPoolDatabase> database(
54+
*GetMinimalDescriptorPool());
55+
return &*database;
56+
}
57+
5058
} // namespace cel::internal

0 commit comments

Comments
 (0)