From 2e4e6dca5168d686b42524d4c1b89d7e2c9b761f Mon Sep 17 00:00:00 2001 From: Lev1ty Date: Fri, 2 Aug 2024 22:33:54 -0400 Subject: [PATCH] Enable build with CMake import descriptor from top-level remove unused patch add protobuf submodule add protovalidate submodule add abseil submodule set protobuf version to latest release add cel submodule green cmake build and install add CMake .gitignore --- .gitignore | 14 +++++++ .gitmodules | 12 ++++++ CMakeLists.txt | 24 ++++++++++++ bazel/cel_cpp.patch | 61 ----------------------------- buf/validate/CMakeLists.txt | 42 ++++++++++++++++++++ buf/validate/internal/constraints.h | 2 +- third_party/abseil-cpp | 1 + third_party/buf.gen.yaml | 10 +++++ third_party/cel-cpp | 1 + third_party/proto/buf.lock | 6 +++ third_party/proto/buf.yaml | 11 ++++++ third_party/proto/google.proto | 4 ++ third_party/protobuf | 1 + third_party/protovalidate | 1 + 14 files changed, 128 insertions(+), 62 deletions(-) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 buf/validate/CMakeLists.txt create mode 160000 third_party/abseil-cpp create mode 100644 third_party/buf.gen.yaml create mode 160000 third_party/cel-cpp create mode 100644 third_party/proto/buf.lock create mode 100644 third_party/proto/buf.yaml create mode 100644 third_party/proto/google.proto create mode 160000 third_party/protobuf create mode 160000 third_party/protovalidate diff --git a/.gitignore b/.gitignore index 2e40d3b..975e11a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..74159bb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..458c51f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +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) diff --git a/bazel/cel_cpp.patch b/bazel/cel_cpp.patch index 1803fc1..8b13789 100644 --- a/bazel/cel_cpp.patch +++ b/bazel/cel_cpp.patch @@ -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(), diff --git a/buf/validate/CMakeLists.txt b/buf/validate/CMakeLists.txt new file mode 100644 index 0000000..415073a --- /dev/null +++ b/buf/validate/CMakeLists.txt @@ -0,0 +1,42 @@ +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/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 + ${CMAKE_BINARY_DIR}/include/buf/validate/expression.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 protobuf) +target_include_directories(validator PUBLIC + $ + $ + $ + $ + $ + $ +) + +install(TARGETS validator DESTINATION lib) +install(FILES validator.h DESTINATION include/buf/validate) +install(FILES ${CMAKE_BINARY_DIR}/include/buf/validate/expression.pb.h DESTINATION include/buf/validate) diff --git a/buf/validate/internal/constraints.h b/buf/validate/internal/constraints.h index b68cc77..0b37a61 100644 --- a/buf/validate/internal/constraints.h +++ b/buf/validate/internal/constraints.h @@ -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 { diff --git a/third_party/abseil-cpp b/third_party/abseil-cpp new file mode 160000 index 0000000..372124e --- /dev/null +++ b/third_party/abseil-cpp @@ -0,0 +1 @@ +Subproject commit 372124e6af36a540e74a2ec31d79d7297a831f98 diff --git a/third_party/buf.gen.yaml b/third_party/buf.gen.yaml new file mode 100644 index 0000000..18dc281 --- /dev/null +++ b/third_party/buf.gen.yaml @@ -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 diff --git a/third_party/cel-cpp b/third_party/cel-cpp new file mode 160000 index 0000000..2d38ae8 --- /dev/null +++ b/third_party/cel-cpp @@ -0,0 +1 @@ +Subproject commit 2d38ae8de83c27f33be71f0377bcb479e55d24fb diff --git a/third_party/proto/buf.lock b/third_party/proto/buf.lock new file mode 100644 index 0000000..5888dc0 --- /dev/null +++ b/third_party/proto/buf.lock @@ -0,0 +1,6 @@ +# Generated by buf. DO NOT EDIT. +version: v2 +deps: + - name: buf.build/googleapis/googleapis + commit: 8bc2c51e08c447cd8886cdea48a73e14 + digest: b5:b7e0ac9d192bd0eae88160101269550281448c51f25121cd0d51957661a350aab07001bc145fe9029a8da10b99ff000ae5b284ecaca9c75f2a99604a04d9b4ab diff --git a/third_party/proto/buf.yaml b/third_party/proto/buf.yaml new file mode 100644 index 0000000..f560079 --- /dev/null +++ b/third_party/proto/buf.yaml @@ -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 diff --git a/third_party/proto/google.proto b/third_party/proto/google.proto new file mode 100644 index 0000000..100a168 --- /dev/null +++ b/third_party/proto/google.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; + +import "google/api/expr/v1alpha1/checked.proto"; +import "google/api/expr/v1alpha1/syntax.proto"; diff --git a/third_party/protobuf b/third_party/protobuf new file mode 160000 index 0000000..7cc670c --- /dev/null +++ b/third_party/protobuf @@ -0,0 +1 @@ +Subproject commit 7cc670c1809e704ebeba90fb430d50e009f36727 diff --git a/third_party/protovalidate b/third_party/protovalidate new file mode 160000 index 0000000..40f7ac7 --- /dev/null +++ b/third_party/protovalidate @@ -0,0 +1 @@ +Subproject commit 40f7ac7f5c7ff68524e8acbf32f9ad7e44d9c1dc