Skip to content
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

Enable build with CMake #59

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
*.out
*.app

# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json

# Additional exclusions
/.tmp/
*.pprof
Expand Down
15 changes: 15 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/protocolbuffers/protobuf
[submodule "third_party/protovalidate"]
path = third_party/protovalidate
url = https://github.com/bufbuild/protovalidate
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://github.com/abseil/abseil-cpp
[submodule "third_party/cel-cpp"]
path = third_party/cel-cpp
url = https://github.com/google/cel-cpp
[submodule "third_party/re2"]
path = third_party/re2
url = https://github.com/google/re2
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.26)

project(protovalidate-cc)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")

if(APPLE)
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
elseif(UNIX)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
endif()

set(ABSL_PROPAGATE_CXX_STD ON)
set(protobuf_ABSL_PROVIDER "module")
set(protobuf_BUILD_PROTOC_BINARIES OFF)
set(protobuf_BUILD_TESTS OFF)

add_subdirectory(buf/validate)
add_subdirectory(third_party/protobuf)
add_subdirectory(third_party/re2)
61 changes: 0 additions & 61 deletions bazel/cel_cpp.patch
Original file line number Diff line number Diff line change
@@ -1,62 +1 @@
diff --git a/eval/eval/container_access_step.cc b/eval/eval/container_access_step.cc
index 39c2507..d7962a2 100644
--- a/eval/eval/container_access_step.cc
+++ b/eval/eval/container_access_step.cc
@@ -11,6 +11,8 @@
#include "eval/public/cel_number.h"
#include "eval/public/cel_value.h"
#include "eval/public/unknown_attribute_set.h"
+#include "eval/public/structs/legacy_type_adapter.h"
+#include "eval/public/structs/legacy_type_info_apis.h"

namespace google::api::expr::runtime {

@@ -34,6 +36,8 @@ class ContainerAccessStep : public ExpressionStepBase {
ExecutionFrame* frame) const;
CelValue LookupInList(const CelList* cel_list, const CelValue& key,
ExecutionFrame* frame) const;
+ CelValue LookupInMessage(const CelValue::MessageWrapper& msg, const CelValue& key,
+ ExecutionFrame* frame) const;
};

inline CelValue ContainerAccessStep::LookupInMap(const CelMap* cel_map,
@@ -109,6 +113,26 @@ inline CelValue ContainerAccessStep::LookupInList(const CelList* cel_list,
CelValue::TypeName(key.type())));
}

+CelValue ContainerAccessStep::LookupInMessage(const CelValue::MessageWrapper& msg, const CelValue& key,
+ ExecutionFrame* frame) const {
+ if (!key.IsString()) {
+ return CreateErrorValue(
+ frame->memory_manager(),
+ absl::StrCat("Field name error: expected string type, got ",
+ CelValue::TypeName(key.type())));
+ }
+ const LegacyTypeAccessApis* accessor =
+ msg.legacy_type_info()->GetAccessApis(msg);
+ if (accessor == nullptr) {
+ return CreateNoSuchFieldError(frame->memory_manager());
+ }
+ auto result_or = accessor->GetField(key.StringOrDie().value(), msg, ProtoWrapperTypeOptions::kUnsetNull, frame->memory_manager());
+ if (!result_or.ok()) {
+ return CreateErrorValue(frame->memory_manager(), result_or.status());
+ }
+ return std::move(result_or).value();
+}
+
ContainerAccessStep::ValueAttributePair ContainerAccessStep::PerformLookup(
ExecutionFrame* frame) const {
auto input_args = frame->value_stack().GetSpan(kNumContainerAccessArguments);
@@ -158,6 +182,12 @@ ContainerAccessStep::ValueAttributePair ContainerAccessStep::PerformLookup(
const CelList* cel_list = container.ListOrDie();
return {LookupInList(cel_list, key, frame), trail};
}
+ case CelValue::Type::kMessage: {
+ CelValue::MessageWrapper wrapper;
+ bool success = container.GetValue(&wrapper);
+ ABSL_ASSERT(success);
+ return {LookupInMessage(wrapper, key, frame), trail};
+ }
default: {
auto error =
CreateErrorValue(frame->memory_manager(),
80 changes: 80 additions & 0 deletions buf/validate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.h
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.cc
${CMAKE_BINARY_DIR}/include/buf/validate/priv/private.pb.h
${CMAKE_BINARY_DIR}/include/buf/validate/priv/private.pb.cc
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.h
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.cc
COMMAND buf generate ${CMAKE_SOURCE_DIR}/third_party/protovalidate/proto/protovalidate --template ${CMAKE_SOURCE_DIR}/third_party/buf.gen.yaml --output ${CMAKE_BINARY_DIR}
VERBATIM
)

add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.h
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.cc
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.h
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.cc
COMMAND buf generate ${CMAKE_SOURCE_DIR}/third_party/proto --include-imports --template ${CMAKE_SOURCE_DIR}/third_party/buf.gen.yaml --output ${CMAKE_BINARY_DIR}
VERBATIM
)

add_library(
validator
validator.cc
internal/cel_constraint_rules.cc
internal/constraints.cc
internal/extra_func.cc
internal/field_rules.cc
internal/message_rules.cc
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.cc
${CMAKE_BINARY_DIR}/include/buf/validate/priv/private.pb.cc
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.cc
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.cc
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.cc
)

target_link_libraries(validator PUBLIC abseil protobuf re2)
target_include_directories(validator PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/protobuf/src>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/abseil-cpp>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/cel-cpp>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/re2>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

install(TARGETS validator DESTINATION lib)
install(
FILES
validator.h
${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.h
${CMAKE_BINARY_DIR}/include/buf/validate/validate.pb.h
DESTINATION include/buf/validate
)
install(
FILES
${CMAKE_BINARY_DIR}/include/buf/validate/priv/private.pb.h
${CMAKE_BINARY_DIR}/include/buf/validate/priv/private.pb.cc
DESTINATION include/buf/validate/priv
)
install(
FILES
internal/cel_constraint_rules.h
internal/cel_rules.h
internal/constraint_rules.h
internal/constraints.h
internal/extra_func.h
internal/field_rules.h
internal/message_rules.h
internal/string_format.h
DESTINATION include/buf/validate/internal
)
install(
FILES
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/checked.pb.h
${CMAKE_BINARY_DIR}/include/google/api/expr/v1alpha1/syntax.pb.h
DESTINATION include/google/api/expr/v1alpha1
)
2 changes: 1 addition & 1 deletion buf/validate/internal/constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "buf/validate/internal/cel_constraint_rules.h"
#include "buf/validate/validate.pb.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/message.h"
#include "src/google/protobuf/descriptor.h"

namespace buf::validate::internal {

Expand Down
1 change: 1 addition & 0 deletions third_party/abseil-cpp
Submodule abseil-cpp added at 372124
10 changes: 10 additions & 0 deletions third_party/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/bufbuild/protovalidate/tools/internal/gen
except:
- buf.build/envoyproxy/protoc-gen-validate
plugins:
- plugin: buf.build/protocolbuffers/cpp:v27.3
out: include
1 change: 1 addition & 0 deletions third_party/cel-cpp
Submodule cel-cpp added at 2d38ae
6 changes: 6 additions & 0 deletions third_party/proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/googleapis/googleapis
commit: 8bc2c51e08c447cd8886cdea48a73e14
digest: b5:b7e0ac9d192bd0eae88160101269550281448c51f25121cd0d51957661a350aab07001bc145fe9029a8da10b99ff000ae5b284ecaca9c75f2a99604a04d9b4ab
11 changes: 11 additions & 0 deletions third_party/proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: v2
deps:
- buf.build/googleapis/googleapis
lint:
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
breaking:
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
4 changes: 4 additions & 0 deletions third_party/proto/google.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
syntax = "proto3";

import "google/api/expr/v1alpha1/checked.proto";
import "google/api/expr/v1alpha1/syntax.proto";
1 change: 1 addition & 0 deletions third_party/protobuf
Submodule protobuf added at 7cc670
1 change: 1 addition & 0 deletions third_party/protovalidate
Submodule protovalidate added at 40f7ac
1 change: 1 addition & 0 deletions third_party/re2
Submodule re2 added at 6dcd83