Building from Source
Relevant source files
The following files were used as context for generating this wiki page:
FluentDo Agent provides several methods for building the agent from source code, catering to different environments and use cases. These methods include a container-based build script for specific Linux distributions, native compilation using CMake for development, and building Docker images directly. The build system is designed to be flexible, incorporating numerous dependencies which are included within the source/lib directory.
This document outlines the primary build methods, the underlying CMake configuration, and how dependencies are managed and configured during the build process.
Sources: README.md:100-123
Build Methods
There are three main approaches to building the FluentDo Agent from its source code.
1. Container-Based Build (Recommended for Packaging)
This method uses a shell script to build the agent inside a Docker container for a specific target Linux distribution. It is the recommended approach for creating distributable packages.
The primary script for this process is source/packaging/build.sh. The main argument is -d which specifies the target distribution.
Example:
git clone https://github.com/FluentDo/agent.git
cd agent
./source/packaging/build.sh -d rockylinux/9
Sources: README.md:100-105, source/packaging/build.sh
The following diagram illustrates the container-based build flow.
Sources: README.md:100-105
2. Native Compilation (CMake)
For development or custom builds on a host with all dependencies installed, the agent can be compiled natively using CMake. This provides more control over the compilation process.
The standard procedure is:
git clone https://github.com/FluentDo/agent.git
cd agent/source/build
cmake ..
make
This process involves CMake configuring the project, locating dependencies, generating Makefiles, and then make compiling the source code into the final executable.
Sources: README.md:113-119, source/CMakeLists.txt
The native compilation process is visualized below.
Sources: README.md:113-119, source/CMakeLists.txt
3. Docker Image Build
You can build the UBI or Debian-based Docker images directly from the provided Dockerfiles. This is ideal for containerized deployments.
UBI Image:
docker build -f Dockerfile.ubi .
Debian Image:
docker build -f Dockerfile.debian .
Sources: README.md:107-111
Core Dependencies & Build Configuration
The FluentDo Agent relies on several key open-source libraries, which are included in the source/lib directory. The build system, orchestrated by CMake, configures and compiles these dependencies as part of the main build process.
Sources: source/CMakeLists.txt, source/lib/jansson-e23f558/CMakeLists.txt, source/lib/monkey/CMakeLists.txt, source/lib/yyjson-0.12.0/doc/doxygen/html/building-and-testing.html
Dependency Build Options
Each dependency has its own set of CMake options, allowing for a highly customized build. These options can be passed during the cmake step. Below are examples from the yyjson and jansson libraries.
yyjson Build Options
The yyjson library offers several options to disable features and reduce binary size.
| CMake Option | Description |
|---|---|
YYJSON_DISABLE_READER | Disable the JSON reader functions. |
YYJSON_DISABLE_WRITER | Disable the JSON writer functions. |
YYJSON_DISABLE_INCR_READER | Disable the incremental JSON reader. |
YYJSON_DISABLE_UTILS | Disable JSON Pointer, JSON Patch, and JSON Merge Patch support. |
YYJSON_DISABLE_FAST_FP_CONV | Disable built-in fast floating-point conversion, using strtod/snprintf instead. |
YYJSON_DISABLE_NON_STANDARD | Disable support for non-standard JSON (e.g., comments, trailing commas). |
YYJSON_BUILD_TESTS | Build all tests for the yyjson library. |
YYJSON_BUILD_DOC | Build documentation with Doxygen. |
Sources: source/lib/yyjson-0.12.0/doc/doxygen/html/building-and-testing.html:105-121
jansson Build Options
The jansson library also provides build-time configurations.
| CMake Option | Description |
|---|---|
JANSSON_BUILD_SHARED_LIBS | Build jansson as a shared library. Default is OFF. |
JANSSON_EXAMPLES | Compile example applications. Default is ON. |
JANSSON_WITHOUT_TESTS | Disable building the test suite. Default is OFF. |
JANSSON_TEST_WITH_VALGRIND | Enable Valgrind tests. Default is OFF. |
Sources: source/lib/jansson-e23f558/CMakeLists.txt:5-20, source/lib/jansson-e23f558/CMakeLists.txt:298-300
Documentation Generation
The build system for some dependencies also includes targets for generating documentation.
| Library | Tool | CMake Command | Output |
|---|---|---|---|
yyjson | Doxygen | cmake .. -DYYJSON_BUILD_DOC=ON && cmake --build . | HTML files in build/doxygen/html. |
nghttp2 | Sphinx | cmake .. && make html | HTML pages in manual/html. |
Sources: source/lib/yyjson-0.12.0/doc/doxygen/html/building-and-testing.html:184-189, source/lib/nghttp2-1.65.0/doc/CMakeLists.txt:282-285
Testing Integration
Tests for dependencies can be enabled and run as part of the build process, ensuring the integrity of the components. The yyjson library provides a comprehensive example of this integration.
The general testing workflow using CMake and CTest is as follows:
This diagram shows the testing flow for the yyjson dependency.
Sources: source/lib/yyjson-0.12.0/doc/doxygen/html/building-and-testing.html:194-198
Advanced testing, such as memory checking with Valgrind or using sanitizers, can also be enabled with specific CMake flags.
- Valgrind:
-DYYJSON_ENABLE_VALGRIND=ON - Sanitizers (GCC/Clang):
-DYYJSON_ENABLE_SANITIZE=ON
Sources: source/lib/yyjson-0.12.0/doc/doxygen/html/building-and-testing.html:201-211