Skip to content

Commit c655fd3

Browse files
jnthntatumcopybara-github
authored andcommitted
Add brief intro on adding cel-cpp as a bazel dependency.
Closes #2111 PiperOrigin-RevId: 947709618
1 parent 8818be6 commit c655fd3

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

codelab/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Buffers as the input into CEL, they may be harder to understand. Consider
3131
working through one of these tutorials, first. See the devsite for
3232
[Protocol Buffers](https://protobuf.dev).
3333

34+
If you're not familiar with Bazel, Bazel is an open-source build and test tool
35+
that supports multi-language projects and manages dependencies. This codelab and
36+
`cel-cpp` are built using Bazel. To learn more about building C++ projects with
37+
Bazel, see the official [Bazel C++ Tutorial](https://bazel.build/tutorials/cpp)
38+
and the [Bazel Documentation](https://bazel.build/docs).
39+
3440
Notes on portability: Protocol Buffers are not required to use CEL generally,
3541
but the C++ implementation has a hard dependency on the library and some APIs
3642
reference protobuf types directly. Automated builds test against gcc10 and
@@ -68,6 +74,62 @@ Make sure everything is working by building the codelab:
6874
bazel build //codelab:all
6975
```
7076

77+
## Setting up a Bazel Project with cel-cpp
78+
79+
If you want to integrate `cel-cpp` into your own standalone C++ project using
80+
[Bazel](https://bazel.build/docs), you can manage it as an external dependency
81+
with [Bzlmod](https://bazel.build/external/overview#bzlmod).
82+
83+
### MODULE.bazel
84+
85+
In your project's root `MODULE.bazel` file, declare a dependency on `cel-cpp`
86+
from the
87+
[Bazel Central Registry (BCR)](https://registry.bazel.build/modules/cel-cpp):
88+
89+
```python
90+
bazel_dep(name = "cel-cpp", version = "<version>")
91+
```
92+
93+
Alternatively, if you want to depend directly on a specific commit from the
94+
GitHub repository, you can use `git_override`:
95+
96+
```python
97+
bazel_dep(name = "cel-cpp", version = "0.0.0")
98+
git_override(
99+
module_name = "cel-cpp",
100+
remote = "https://github.com/google/cel-cpp.git",
101+
commit = "<commit_hash>",
102+
)
103+
```
104+
105+
### BUILD
106+
107+
In your project's `BUILD` (or `BUILD.bazel`) file, reference `cel-cpp` targets
108+
using `@cel-cpp//...`. For example, to compile a C++ binary that compiles and
109+
evaluates CEL expressions using the modern `Compiler` and `Runtime` APIs shown
110+
in this codelab:
111+
112+
```python
113+
cc_binary(
114+
name = "my_cel_app",
115+
srcs = ["main.cc"],
116+
deps = [
117+
"@cel-cpp//checker:validation_result",
118+
"@cel-cpp//common:ast",
119+
"@cel-cpp//common:minimal_descriptor_pool",
120+
"@cel-cpp//common:value",
121+
"@cel-cpp//compiler",
122+
"@cel-cpp//compiler:compiler_factory",
123+
"@cel-cpp//compiler:standard_library",
124+
"@cel-cpp//runtime",
125+
"@cel-cpp//runtime:activation",
126+
"@cel-cpp//runtime:runtime_builder",
127+
"@cel-cpp//runtime:runtime_options",
128+
"@cel-cpp//runtime:standard_runtime_builder_factory",
129+
],
130+
)
131+
```
132+
71133
## Hello, World
72134

73135
In the tried and true tradition of all programming languages, let's start with

0 commit comments

Comments
 (0)