Skip to content

Commit

Permalink
Enable build with CMake
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Lev1ty committed Aug 3, 2024
1 parent 5ba3f45 commit 2e4e6dc
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 62 deletions.
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
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
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(),
42 changes: 42 additions & 0 deletions buf/validate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<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_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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)
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

0 comments on commit 2e4e6dc

Please sign in to comment.