Skip to content

Commit 535c29f

Browse files
Update cel-cpp to v0.11.0 (#86)
This is a bit complicated because cel-cpp v0.11.0 breaks `WORKSPACE` support a little bit, but thankfully the API we're using has remained relatively stable. Patches have been rebased, I'm pretty confident that I'll need to loop around to the MSVC patch to make sure it still works but the field access patch seems to be working first-try so knock-on-wood. The CMakeLists will need to be audited because I'm sure there's now stuff in it that should be removed, but let's focus on getting a working build first. We can focus on making the CMakeLists as accurate as possible when we're closer to being able to upstream it. Although cel-cpp now compiles with bzlmod, it has yet to be added to the BCR, so we might not be able to use it with bzlmod ourselves yet. (I'll be sure to double-check this, but I want to keep this PR clean.) Another follow-up item would be to use the `strings.format` implementation provided by cel-cpp v0.11.0, but it will probably be according to the new spec, so that is pending on a `protovalidate` release with the updated tests. Draft until we're passing in CI. I anticipate problems across platforms.
1 parent 70ab4a3 commit 535c29f

16 files changed

+611
-246
lines changed

.bazelignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
.build*
2-
cmake-build-*
31
.cache

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
44

55
project(protovalidate-cc)
66

7+
if(MSVC)
8+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
9+
endif()
10+
711
option(PROTOVALIDATE_CC_ENABLE_VENDORING "Fall back to vendored libraries when possible" ON)
812

913
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)

REPO.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2023-2025 Buf Technologies, Inc.
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+
# http://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+
ignore_directories([
16+
".build*",
17+
"cmake-build-*",
18+
])

WORKSPACE

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ rules_buf_dependencies()
3434

3535
rules_buf_toolchains(version = "v1.19.0")
3636

37-
load("@com_google_cel_cpp//bazel:deps.bzl", "base_deps", "parser_deps")
37+
load("@com_google_cel_cpp//bazel:deps.bzl", "cel_cpp_deps")
3838

39-
base_deps()
40-
41-
parser_deps()
39+
cel_cpp_deps()
4240

4341
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
4442

@@ -51,8 +49,14 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
5149

5250
protobuf_deps()
5351

54-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
52+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
5553

5654
rules_proto_dependencies()
5755

56+
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
57+
5858
rules_proto_toolchains()
59+
60+
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
61+
62+
go_rules_dependencies()

bazel/deps.bzl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ _dependencies = {
6161
name="protobuf",
6262
),
6363
"rules_proto": dict(
64-
sha256="dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",
65-
strip_prefix="rules_proto-5.3.0-21.7",
64+
sha256="14a225870ab4e91869652cfd69ef2028277fc1dc4910d65d353b62d6e0ae21f4",
65+
strip_prefix="rules_proto-7.1.0",
6666
urls=[
67-
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz",
67+
"https://github.com/bazelbuild/rules_proto/releases/download/7.1.0/rules_proto-7.1.0.tar.gz",
6868
],
6969
),
7070
"rules_buf": dict(
@@ -74,12 +74,35 @@ _dependencies = {
7474
"https://github.com/bufbuild/rules_buf/archive/refs/tags/v0.1.1.zip",
7575
],
7676
),
77+
# cel-cpp v0.11.0 doesn't build correctly in WORKSPACE mode, this is a quick
78+
# workaround.
79+
"antlr4-cpp-runtime": dict(
80+
build_file_content="""
81+
package(default_visibility = ["//visibility:public"])
82+
cc_library(
83+
name = "antlr4-cpp-runtime",
84+
srcs = glob(["runtime/Cpp/runtime/src/**/*.cpp"]),
85+
hdrs = glob(["runtime/Cpp/runtime/src/**/*.h"]),
86+
defines = ["ANTLR4CPP_USING_ABSEIL"],
87+
includes = ["runtime/Cpp/runtime/src"],
88+
deps = [
89+
"@com_google_absl//absl/base",
90+
"@com_google_absl//absl/base:core_headers",
91+
"@com_google_absl//absl/container:flat_hash_map",
92+
"@com_google_absl//absl/container:flat_hash_set",
93+
"@com_google_absl//absl/synchronization",
94+
],
95+
)
96+
""",
97+
sha256="42d1268524a9c972f5ca1ad1633372ea02a812ff66c1e992925edea5e5cf9c81",
98+
strip_prefix="antlr4-4.13.2",
99+
urls=["https://github.com/antlr/antlr4/archive/refs/tags/4.13.2.zip"],
100+
),
77101
"com_google_cel_cpp": shared_dep(
78102
name="cel_cpp",
79103
patches=[
80104
"@com_github_bufbuild_protovalidate_cc//deps:patches/cel_cpp/0001-Allow-message-field-access-using-index-operator.patch",
81105
"@com_github_bufbuild_protovalidate_cc//deps:patches/cel_cpp/0002-Add-missing-include-for-absl-StrCat.patch",
82-
"@com_github_bufbuild_protovalidate_cc//deps:patches/cel_cpp/0003-Remove-unnecessary-dependency-on-cel_proto_wrap_util.patch",
83106
],
84107
patch_args=["-p1"],
85108
),

buf/validate/internal/cel_constraint_rules.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ absl::Status CelConstraintRules::Add(
9696
if (!pexpr_or.ok()) {
9797
return pexpr_or.status();
9898
}
99-
cel::v1alpha1::ParsedExpr pexpr = std::move(pexpr_or).value();
100-
auto expr_or = builder.CreateExpression(pexpr.mutable_expr(), pexpr.mutable_source_info());
99+
::cel::expr::ParsedExpr pexpr = std::move(pexpr_or).value();
100+
auto expr_or = builder.CreateExpression(&pexpr.expr(), &pexpr.source_info());
101101
if (!expr_or.ok()) {
102102
return expr_or.status();
103103
}

buf/validate/internal/extra_func.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ cel::CelValue endsWith(
139139
}
140140

141141
bool IsHostname(std::string_view toValidate) {
142-
if (toValidate.length() > 253) {
142+
if (toValidate.empty() || toValidate.length() > 253) {
143143
return false;
144144
}
145145
toValidate = absl::StripSuffix(toValidate, ".");

buf/validate/validator_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ TEST(ValidatorTest, ParseAndEval) {
4545
std::string input = "1 + 2";
4646
auto pexpr_or = cel::parser::Parse(input);
4747
EXPECT_TRUE(pexpr_or.ok());
48-
cel::v1alpha1::ParsedExpr pexpr = std::move(pexpr_or).value();
48+
::cel::expr::ParsedExpr pexpr = std::move(pexpr_or).value();
4949
cel::runtime::Activation activation;
5050

5151
cel::runtime::InterpreterOptions options;

cmake/Deps.cmake

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ if(CEL_CPP_ENABLE_TESTS)
8484
endif()
8585
endif()
8686
endif()
87-
88-
# Fetch CEL spec repository (needed for test protos)
89-
# When building in a hermetic environment, use the
90-
# FETCHCONTENT_SOURCE_DIR_CEL_SPEC option to avoid the external fetch.
91-
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_SOURCE_DIR_%3CuppercaseName%3E
92-
FetchContent_Declare(
93-
cel_spec
94-
GIT_REPOSITORY https://github.com/google/cel-spec.git
95-
GIT_TAG f027a86d2e5bf18f796be0c4373f637a61041cde
96-
)
97-
FetchContent_MakeAvailable(cel_spec)
9887
endif()
9988

10089
# Abseil
@@ -268,6 +257,17 @@ FetchContent_Declare(
268257
)
269258
FetchContent_MakeAvailable(googleapis)
270259

260+
# Fetch CEL spec repository
261+
# When building in a hermetic environment, use the
262+
# FETCHCONTENT_SOURCE_DIR_CEL_SPEC option to avoid the external fetch.
263+
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_SOURCE_DIR_%3CuppercaseName%3E
264+
FetchContent_Declare(
265+
cel_spec
266+
GIT_REPOSITORY https://github.com/google/cel-spec.git
267+
GIT_TAG f027a86d2e5bf18f796be0c4373f637a61041cde
268+
)
269+
FetchContent_MakeAvailable(cel_spec)
270+
271271
# Cel-cpp; Note that cel-cpp has no CMake build and is not packaged anywhere,
272272
# so it is always vendored. When building in a hermetic environment, use the
273273
# FETCHCONTENT_SOURCE_DIR_CEL_CPP option to avoid the external fetch.
@@ -277,8 +277,7 @@ SharedDeps_GetSourceValue(PROTOVALIDATE_CC_CEL_CPP_SHA256 "cel_cpp" "sha256" "${
277277
set(CEL_CPP_PATCHES
278278
${CMAKE_CURRENT_SOURCE_DIR}/deps/patches/cel_cpp/0001-Allow-message-field-access-using-index-operator.patch
279279
${CMAKE_CURRENT_SOURCE_DIR}/deps/patches/cel_cpp/0002-Add-missing-include-for-absl-StrCat.patch
280-
${CMAKE_CURRENT_SOURCE_DIR}/deps/patches/cel_cpp/0003-Remove-unnecessary-dependency-on-cel_proto_wrap_util.patch
281-
${CMAKE_CURRENT_SOURCE_DIR}/deps/patches/cel_cpp/0004-Fix-build-on-Windows-MSVC.patch
280+
${CMAKE_CURRENT_SOURCE_DIR}/deps/patches/cel_cpp/0003-Fix-build-on-Windows-MSVC.patch
282281
)
283282
MakePatchCommand(CEL_CPP_PATCH_COMMAND "${CEL_CPP_PATCHES}")
284283
message(STATUS "protovalidate-cc: Fetching cel-cpp")

cmake/cel-cpp/CMakeLists.txt

Lines changed: 70 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,72 @@ protobuf_generate(
6767
)
6868
add_library(cel_cpp::googleapis_proto ALIAS cel_googleapis_proto)
6969

70+
# Generate C++ code for cel spec protos
71+
set(CEL_SPEC_PROTO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen/proto_cc_cel_spec)
72+
file(MAKE_DIRECTORY ${CEL_SPEC_PROTO_GEN_DIR}/proto)
73+
set(CEL_SPEC_PROTO
74+
test/v1/proto2/test_all_types.proto
75+
test/v1/proto3/test_all_types.proto
76+
cel/expr/checked.proto
77+
cel/expr/eval.proto
78+
cel/expr/explain.proto
79+
cel/expr/syntax.proto
80+
cel/expr/value.proto
81+
)
82+
set(CEL_SPEC_PROTO_DIR ${cel_spec_SOURCE_DIR}/proto)
83+
list(TRANSFORM CEL_SPEC_PROTO PREPEND ${CEL_SPEC_PROTO_DIR}/)
84+
add_library(cel_cpp_spec_proto OBJECT ${CEL_SPEC_PROTO})
85+
target_include_directories(cel_cpp_spec_proto
86+
PUBLIC ${CEL_SPEC_PROTO_GEN_DIR}/proto
87+
)
88+
target_link_libraries(cel_cpp_spec_proto PUBLIC protobuf::libprotobuf cel_cpp::googleapis_proto)
89+
protobuf_generate(
90+
TARGET cel_cpp_spec_proto
91+
LANGUAGE cpp
92+
PROTOC_OUT_DIR ${CEL_SPEC_PROTO_GEN_DIR}/proto
93+
IMPORT_DIRS ${CEL_SPEC_PROTO_DIR}
94+
${PROTOBUF_IMPORT_PATH}
95+
${CEL_CPP_GOOGLEAPIS_PROTO_DIR}
96+
DEPENDENCIES cel_cpp::googleapis_proto
97+
)
98+
add_library(cel_cpp::spec_proto ALIAS cel_cpp_spec_proto)
99+
100+
# Generate empty descriptor set
101+
set(CEL_CPP_EMPTY_DESCRIPTOR_SET_PATH ${CMAKE_CURRENT_BINARY_DIR}/empty_descriptor_set.pb)
102+
set(CEL_CPP_EMPTY_DESCRIPTOR_SET_PROTO google/protobuf/empty.proto)
103+
list(TRANSFORM CEL_CPP_EMPTY_DESCRIPTOR_SET_PROTO PREPEND ${PROTOBUF_IMPORT_PATH}/)
104+
add_custom_command(
105+
OUTPUT ${CEL_CPP_EMPTY_DESCRIPTOR_SET_PATH}
106+
COMMAND ${PROTOC_EXECUTABLE}
107+
--include_imports
108+
--descriptor_set_out=${CEL_CPP_EMPTY_DESCRIPTOR_SET_PATH}
109+
-I${PROTOBUF_IMPORT_PATH}
110+
${CEL_CPP_EMPTY_DESCRIPTOR_SET_PROTO}
111+
DEPENDS ${CEL_CPP_EMPTY_DESCRIPTOR_SET_PROTO}
112+
COMMENT "Generating empty descriptor set"
113+
VERBATIM
114+
)
115+
set(CEL_CPP_EMPTY_DESCRIPTOR_SET_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen/empty_descriptor_set)
116+
file(MAKE_DIRECTORY ${CEL_CPP_EMPTY_DESCRIPTOR_SET_GEN_DIR}/internal)
117+
set(CEL_CPP_EMPTY_DESCRIPTOR_SET_EMBED_PATH ${CEL_CPP_EMPTY_DESCRIPTOR_SET_GEN_DIR}/internal/empty_descriptor_set_embed.inc)
118+
add_custom_command(
119+
OUTPUT ${CEL_CPP_EMPTY_DESCRIPTOR_SET_EMBED_PATH}
120+
COMMAND $<TARGET_FILE:cel_cpp::embed>
121+
--in=${CEL_CPP_EMPTY_DESCRIPTOR_SET_PATH}
122+
--out=${CEL_CPP_EMPTY_DESCRIPTOR_SET_EMBED_PATH}
123+
DEPENDS ${CEL_CPP_EMPTY_DESCRIPTOR_SET_PATH}
124+
cel_cpp::embed
125+
COMMENT "Embedding empty descriptor set"
126+
VERBATIM
127+
)
128+
add_custom_target(cel_cpp_empty_descriptor_set_gen DEPENDS ${CEL_CPP_EMPTY_DESCRIPTOR_SET_EMBED_PATH})
129+
add_library(cel_cpp_empty_descriptor_set INTERFACE)
130+
add_dependencies(cel_cpp_empty_descriptor_set cel_cpp_empty_descriptor_set_gen)
131+
target_include_directories(cel_cpp_empty_descriptor_set INTERFACE
132+
$<BUILD_INTERFACE:${CEL_CPP_EMPTY_DESCRIPTOR_SET_GEN_DIR}>
133+
)
134+
add_library(cel_cpp::empty_descriptor_set ALIAS cel_cpp_empty_descriptor_set)
135+
70136
# Generate embedded descriptor set
71137
set(CEL_CPP_MINIMAL_DESCRIPTOR_SET_PATH ${CMAKE_CURRENT_BINARY_DIR}/minimal_descriptor_set.pb)
72138
set(CEL_CPP_MINIMAL_DESCRIPTOR_SET_PROTO
@@ -117,6 +183,7 @@ file(GLOB CEL_CPP_CORE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
117183
checker/*.cc
118184
checker/internal/*.cc
119185
common/*.cc
186+
common/ast/*.cc
120187
common/internal/*.cc
121188
common/types/*.cc
122189
common/values/*.cc
@@ -159,6 +226,7 @@ list(REMOVE_ITEM CEL_CPP_CORE_SOURCES ${CEL_CPP_TESTING_SOURCES})
159226
set(CEL_CPP_TEST_SOURCES ${CEL_CPP_CORE_SOURCES})
160227
list(FILTER CEL_CPP_TEST_SOURCES INCLUDE REGEX ".*_test\\.cc$")
161228
list(FILTER CEL_CPP_CORE_SOURCES EXCLUDE REGEX ".*_test\\.cc$")
229+
list(FILTER CEL_CPP_CORE_SOURCES EXCLUDE REGEX ".*_benchmarks\\.cc$")
162230

163231
# Remove some tests that don't seem to work right.
164232
list(REMOVE_ITEM CEL_CPP_TEST_SOURCES
@@ -208,8 +276,10 @@ list(REMOVE_ITEM CEL_CPP_TEST_SOURCES
208276
add_library(cel_cpp STATIC ${CEL_CPP_CORE_SOURCES} ${CEL_CPP_MINIMAL_DESCRIPTOR_SET_EMBED_PATH})
209277
target_link_libraries(cel_cpp PUBLIC
210278
cel_cpp::parser
279+
cel_cpp::empty_descriptor_set
211280
cel_cpp::minimal_descriptor_set
212281
cel_cpp::googleapis_proto
282+
cel_cpp::spec_proto
213283
absl::base
214284
protobuf::libprotobuf
215285
re2::re2
@@ -224,37 +294,6 @@ add_library(cel_cpp::cel_cpp ALIAS cel_cpp)
224294
if(CEL_CPP_ENABLE_TESTS)
225295
enable_testing()
226296

227-
# Generate C++ code for cel spec protos
228-
set(CEL_SPEC_PROTO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen/proto_cc_cel_spec)
229-
file(MAKE_DIRECTORY ${CEL_SPEC_PROTO_GEN_DIR}/proto)
230-
set(CEL_SPEC_PROTO
231-
test/v1/proto2/test_all_types.proto
232-
test/v1/proto3/test_all_types.proto
233-
cel/expr/checked.proto
234-
cel/expr/eval.proto
235-
cel/expr/explain.proto
236-
cel/expr/syntax.proto
237-
cel/expr/value.proto
238-
)
239-
set(CEL_SPEC_PROTO_DIR ${cel_spec_SOURCE_DIR}/proto)
240-
list(TRANSFORM CEL_SPEC_PROTO PREPEND ${CEL_SPEC_PROTO_DIR}/)
241-
add_library(cel_cpp_spec_proto OBJECT ${CEL_SPEC_PROTO})
242-
target_include_directories(cel_cpp_spec_proto
243-
PUBLIC ${CEL_SPEC_PROTO_GEN_DIR}
244-
PRIVATE ${CEL_SPEC_PROTO_GEN_DIR}/proto
245-
)
246-
target_link_libraries(cel_cpp_spec_proto PUBLIC protobuf::libprotobuf cel_cpp::googleapis_proto)
247-
protobuf_generate(
248-
TARGET cel_cpp_spec_proto
249-
LANGUAGE cpp
250-
PROTOC_OUT_DIR ${CEL_SPEC_PROTO_GEN_DIR}/proto
251-
IMPORT_DIRS ${CEL_SPEC_PROTO_DIR}
252-
${PROTOBUF_IMPORT_PATH}
253-
${CEL_CPP_GOOGLEAPIS_PROTO_DIR}
254-
DEPENDENCIES cel_cpp::googleapis_proto
255-
)
256-
add_library(cel_cpp::spec_proto ALIAS cel_cpp_spec_proto)
257-
258297
# Generate C++ code for cel-cpp test protos
259298
set(CEL_CPP_TEST_PROTO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen/proto_cc_cel_cpp_test)
260299
file(MAKE_DIRECTORY ${CEL_CPP_TEST_PROTO_GEN_DIR})

0 commit comments

Comments
 (0)