runtime 1.0.0
Checked CEL programs, owned values, and reusable execution stacks
Loading...
Searching...
No Matches
Build and link the runtime with CPM

Note: This project is a temporary solution for using the CEL language from cel-rs in C++. This library will be deprecated when using the Rust implementations from C++ becomes viable.

This tutorial builds cel-runtime from source as a static library inside your application's CMake build. No installation or package prefix is needed.

Before you begin

Use CMake 3.24 or later, Ninja, Git, and a C++20 compiler. The first configuration downloads the pinned sources and build infrastructure. You need Git read access to the dependency repositories. The runtime requires an IEEE binary64 double; its headers check the representation. The shell commands below use a POSIX shell.

Add CPM to your application

  1. Create an application directory:

    mkdir runtime-client
    cd runtime-client
  2. Create a directory for the CPM bootstrap:

    mkdir -p cmake
  3. Save this bootstrap as cmake/CPM.cmake:

    file(DOWNLOAD
    https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.43.2/CPM.cmake
    "${CMAKE_BINARY_DIR}/cmake/CPM_0.43.2.cmake"
    EXPECTED_HASH
    SHA256=49a3bef91ceb65bb66d57255e12d1ffd22abc2f6408fa9fe4534c544a2f232aa
    TLS_VERIFY ON
    )
    include("${CMAKE_BINARY_DIR}/cmake/CPM_0.43.2.cmake")

    CMake downloads and verifies CPM before executing it. A checksum mismatch stops configuration. Keep the version and checksum together when updating.

Build the runtime with your application

Create main.cpp in your application directory:

#include <cel/runtime.hpp>
int main() {
builder.just(cel::value::from(5.0));
auto program = std::move(builder).finish().prepare<double>();
return program.call(stack) == 5.0 ? 0 : 1;
}
Checks stack effects while constructing a move-only ordinary operation sequence. Operations consume o...
Definition dyn_segment.hpp:227
void just(value literal)
Retains a literal owner and emits an independent clone on every execution. Callable components share ...
Owns reusable canonical operand bytes and complete live-slot metadata. The owner outlives every borro...
Definition raw_stack.hpp:33
static value from(const T &source)
Copies a concrete leaf or recursively nested owning vector/tuple into a runtime value....
Definition value.hpp:138
Provides values, program builders, and reusable execution for C++20 runtime clients....

Create CMakeLists.txt beside it:

cmake_minimum_required(VERSION 3.24)
project(runtime_client LANGUAGES CXX)
set(CPM_USE_LOCAL_PACKAGES OFF)
include(cmake/CPM.cmake)
CPMAddPackage("gh:stlab/cel-runtime@1.0.0")
add_executable(client main.cpp)
target_link_libraries(client PRIVATE cel::runtime)
enable_testing()
add_test(NAME client COMMAND client)

Configure, build, and run the test from your application directory:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build --output-on-failure

Confirm that client passes. CPM fetches the pinned runtime source and builds it as a static library by default. Dependency builds omit the runtime's tests and package installation rules. CPM_USE_LOCAL_PACKAGES OFF keeps CPM from preferring an installed package.

The cel::runtime target supplies the headers, static library, and C++20 requirement. Do not add dependency include or library directories manually. Select a reviewed release after @ when updating the dependency.

Continue with Compile and reuse a program to pass arguments, reserve stack storage, and evaluate the same program more than once.