Skip to content
Merged
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
23 changes: 22 additions & 1 deletion common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ cc_library(
srcs = ["minimal_descriptor_pool.cc"],
hdrs = ["minimal_descriptor_pool.h"],
deps = [
"//internal:minimal_descriptor_pool",
"//internal:minimal_descriptors",
"@com_google_absl//absl/base:nullability",
"@com_google_protobuf//:protobuf",
],
Expand All @@ -836,6 +836,27 @@ cc_test(
],
)

cc_library(
name = "minimal_descriptor_database",
srcs = ["minimal_descriptor_database.cc"],
hdrs = ["minimal_descriptor_database.h"],
deps = [
"//internal:minimal_descriptors",
"@com_google_absl//absl/base:nullability",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
name = "minimal_descriptor_database_test",
srcs = ["minimal_descriptor_database_test.cc"],
deps = [
":minimal_descriptor_database",
"//internal:testing",
"@com_google_protobuf//:protobuf",
],
)

cc_library(
name = "function_descriptor",
srcs = [
Expand Down
27 changes: 27 additions & 0 deletions common/minimal_descriptor_database.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2025 Google LLC
//
// 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
//
// https://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.

#include "common/minimal_descriptor_database.h"

#include "absl/base/nullability.h"
#include "internal/minimal_descriptor_database.h"
#include "google/protobuf/descriptor_database.h"

namespace cel {

absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase() {
return internal::GetMinimalDescriptorDatabase();
}

} // namespace cel
32 changes: 32 additions & 0 deletions common/minimal_descriptor_database.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 Google LLC
//
// 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
//
// https://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 THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_DATABASE_H_
#define THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_DATABASE_H_

#include "absl/base/nullability.h"
#include "google/protobuf/descriptor_database.h"

namespace cel {

// GetMinimalDescriptorDatabase returns a pointer to a
// `google::protobuf::DescriptorDatabase` which includes has the minimally necessary
// descriptors required by the Common Expression Language. The returned
// `google::protobuf::DescriptorDatabase` is valid for the lifetime of the process and
// should not be deleted.
absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase();

} // namespace cel

#endif // THIRD_PARTY_CEL_CPP_COMMON_MINIMAL_DESCRIPTOR_DATABASE_H_
139 changes: 139 additions & 0 deletions common/minimal_descriptor_database_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright 2025 Google LLC
//
// 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
//
// https://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.

#include "common/minimal_descriptor_database.h"

#include "google/protobuf/descriptor.pb.h"
#include "internal/testing.h"
#include "google/protobuf/descriptor.h"

namespace cel {
namespace {

using ::testing::IsTrue;

TEST(GetMinimalDescriptorDatabase, NullValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.NullValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, BoolValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.BoolValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Int32Value) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Int32Value", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Int64Value) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Int64Value", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, UInt32Value) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.UInt32Value", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, UInt64Value) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.UInt64Value", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, FloatValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.FloatValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, DoubleValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.DoubleValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, BytesValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.BytesValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, StringValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.StringValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Any) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Any", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Duration) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Duration", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Timestamp) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Timestamp", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Value) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Value", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, ListValue) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.ListValue", &fd),
IsTrue());
}

TEST(GetMinimalDescriptorDatabase, Struct) {
google::protobuf::FileDescriptorProto fd;
EXPECT_THAT(GetMinimalDescriptorDatabase()->FindFileContainingSymbol(
"google.protobuf.Struct", &fd),
IsTrue());
}

} // namespace
} // namespace cel
15 changes: 12 additions & 3 deletions internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,22 @@ cel_cc_embed(
src = ":minimal_descriptor_set",
)

cc_library(
alias(
name = "minimal_descriptor_pool",
srcs = ["minimal_descriptor_pool.cc"],
hdrs = ["minimal_descriptor_pool.h"],
actual = ":minimal_descriptors",
)

cc_library(
name = "minimal_descriptors",
srcs = ["minimal_descriptors.cc"],
hdrs = [
"minimal_descriptor_database.h",
"minimal_descriptor_pool.h",
],
textual_hdrs = [":minimal_descriptor_set_embed"],
deps = [
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/log:absl_check",
"@com_google_protobuf//:protobuf",
Expand Down
32 changes: 32 additions & 0 deletions internal/minimal_descriptor_database.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 Google LLC
//
// 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
//
// https://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 THIRD_PARTY_CEL_CPP_INTERNAL_MINIMAL_DESCRIPTOR_DATABASE_H_
#define THIRD_PARTY_CEL_CPP_INTERNAL_MINIMAL_DESCRIPTOR_DATABASE_H_

#include "absl/base/nullability.h"
#include "google/protobuf/descriptor_database.h"

namespace cel::internal {

// GetMinimalDescriptorDatabase returns a pointer to a
// `google::protobuf::DescriptorDatabase` which includes has the minimally necessary
// descriptors required by the Common Expression Language. The returning
// `google::protobuf::DescripDescriptorDatabasetorPool` is valid for the lifetime of the
// process.
absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase();

} // namespace cel::internal

#endif // THIRD_PARTY_CEL_CPP_INTERNAL_MINIMAL_DESCRIPTOR_DATABASE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "internal/minimal_descriptor_pool.h"

#include <cstdint>

#include "google/protobuf/descriptor.pb.h"
#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/base/no_destructor.h"
#include "absl/base/nullability.h"
#include "absl/log/absl_check.h"
#include "internal/minimal_descriptor_database.h"
#include "internal/minimal_descriptor_pool.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor_database.h"

namespace cel::internal {

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

absl::Nonnull<google::protobuf::DescriptorDatabase*> GetMinimalDescriptorDatabase() {
static absl::NoDestructor<google::protobuf::DescriptorPoolDatabase> database(
*GetMinimalDescriptorPool());
return &*database;
}

} // namespace cel::internal