Skip to content

Commit 279199a

Browse files
committed
ci: Build and run examples.
1 parent 2fe904d commit 279199a

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,20 @@ jobs:
7474
- name: Configure CMake
7575
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
7676
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
77-
run: >
78-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
79-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
80-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
81-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
82-
-DAGENT_CPP_BUILD_TESTS=ON
83-
-S ${{ github.workspace }}
77+
# Examples use POSIX headers (unistd.h) and are only built on non-Windows platforms.
78+
shell: bash
79+
run: |
80+
BUILD_EXAMPLES="OFF"
81+
if [ "${{ matrix.os }}" != "windows-latest" ]; then
82+
BUILD_EXAMPLES="ON"
83+
fi
84+
cmake -B ${{ steps.strings.outputs.build-output-dir }} \
85+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
86+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
87+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
88+
-DAGENT_CPP_BUILD_TESTS=ON \
89+
-DAGENT_CPP_BUILD_EXAMPLES=$BUILD_EXAMPLES \
90+
-S ${{ github.workspace }}
8491
8592
- name: Build
8693
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
@@ -91,3 +98,16 @@ jobs:
9198
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
9299
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
93100
run: ctest --build-config ${{ matrix.build_type }}
101+
102+
- name: Verify examples run
103+
# Examples use POSIX headers (unistd.h) and are not available on Windows
104+
if: matrix.os != 'windows-latest'
105+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
106+
shell: bash
107+
run: |
108+
# Verify each example runs (they exit with code 1 when no model is provided, which is expected)
109+
for example in shell-example memory-example multi-agent-example context-engineering-example; do
110+
echo "Testing $example..."
111+
./$example || test $? -eq 1
112+
echo "$example executed successfully (printed usage as expected)"
113+
done

CMakeLists.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
77

88
option(AGENT_CPP_BUILD_TESTS "Build agent.cpp tests" OFF)
9+
option(AGENT_CPP_BUILD_EXAMPLES "Build agent.cpp examples" OFF)
910
option(AGENT_CPP_BUNDLED_LLAMA "Bundle llama.cpp (vs. find installed)" ON)
1011

1112
set(LLAMA_CPP_DIR "" CACHE PATH "Path to existing llama.cpp directory (leave empty to use submodule)")
@@ -108,6 +109,66 @@ if(AGENT_CPP_BUILD_TESTS)
108109
message(STATUS "Tests enabled. Run with: ctest or ./test_tool")
109110
endif()
110111

112+
if(AGENT_CPP_BUILD_EXAMPLES)
113+
# Shell example
114+
add_executable(shell-example examples/shell/shell.cpp)
115+
target_include_directories(shell-example PRIVATE
116+
${CMAKE_CURRENT_SOURCE_DIR}/src
117+
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
118+
${LLAMA_SOURCE_DIR}/common
119+
${LLAMA_SOURCE_DIR}/ggml/include
120+
${LLAMA_SOURCE_DIR}/include
121+
${LLAMA_SOURCE_DIR}/vendor
122+
)
123+
target_link_libraries(shell-example PRIVATE agent model common llama)
124+
target_compile_features(shell-example PRIVATE cxx_std_17)
125+
126+
# Memory example
127+
add_executable(memory-example examples/memory/memory.cpp)
128+
target_include_directories(memory-example PRIVATE
129+
${CMAKE_CURRENT_SOURCE_DIR}/src
130+
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
131+
${LLAMA_SOURCE_DIR}/common
132+
${LLAMA_SOURCE_DIR}/ggml/include
133+
${LLAMA_SOURCE_DIR}/include
134+
${LLAMA_SOURCE_DIR}/vendor
135+
)
136+
target_link_libraries(memory-example PRIVATE agent model common llama)
137+
target_compile_features(memory-example PRIVATE cxx_std_17)
138+
139+
# Multi-agent example
140+
add_executable(multi-agent-example examples/multi-agent/multi-agent.cpp)
141+
target_include_directories(multi-agent-example PRIVATE
142+
${CMAKE_CURRENT_SOURCE_DIR}/src
143+
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
144+
${LLAMA_SOURCE_DIR}/common
145+
${LLAMA_SOURCE_DIR}/ggml/include
146+
${LLAMA_SOURCE_DIR}/include
147+
${LLAMA_SOURCE_DIR}/vendor
148+
)
149+
target_link_libraries(multi-agent-example PRIVATE agent model common llama)
150+
target_compile_features(multi-agent-example PRIVATE cxx_std_17)
151+
152+
# Context engineering example
153+
add_executable(context-engineering-example examples/context-engineering/context-engineering.cpp)
154+
target_include_directories(context-engineering-example PRIVATE
155+
${CMAKE_CURRENT_SOURCE_DIR}/src
156+
${CMAKE_CURRENT_SOURCE_DIR}/examples/shared
157+
${LLAMA_SOURCE_DIR}/common
158+
${LLAMA_SOURCE_DIR}/ggml/include
159+
${LLAMA_SOURCE_DIR}/include
160+
${LLAMA_SOURCE_DIR}/vendor
161+
)
162+
target_link_libraries(context-engineering-example PRIVATE agent model common llama)
163+
target_compile_features(context-engineering-example PRIVATE cxx_std_17)
164+
165+
# Note: tracing-example is not included here as it requires additional
166+
# dependencies (OpenTelemetry, protobuf, curl). Build it separately from
167+
# examples/tracing/
168+
169+
message(STATUS "Examples enabled.")
170+
endif()
171+
111172
option(AGENT_CPP_INSTALL "Generate install target" OFF)
112173

113174
if(AGENT_CPP_INSTALL)

0 commit comments

Comments
 (0)