Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup CMakePresets.json #1840

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[CMakePresets.json]
indent_style = space
indent_size = 2

[*.sh]
indent_style = space
indent_size = 4
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,17 @@ jobs:
fail-fast: false
matrix:
config-args:
- -DADDRESS_SANITIZER=ON
- -DUSE_VALGRIND=ON
- --preset=sanitizers
- --preset=valgrind
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Build collector
run: |
cmake -S . -B cmake-build \
${{ matrix.config-args }} \
-DCMAKE_BUILD_TYPE=Debug
make -C cmake-build "-j$(nproc)"
cmake ${{ matrix.config-args }} -DCOLLECTOR_VERSION="0.0.0"
cmake --build cmake-build "-j$(nproc)"

- name: Run unit tests
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cmake-build-*/
.vscode/
.devcontainer/
.devcontainer.json
cmake-build/
out/

# IBM Cloud dynamic inventory files
Expand All @@ -36,3 +35,6 @@ ansible/ci/inventory_ibmcloud.yml

# Snyk
.dccache

# CMake presets
CMakeUserPresets.json
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ repos:
rev: "v1.0.0-rc.1"
hooks:
- id: go-fmt

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.29.2"
hooks:
- id: check-jsonschema
files: "^CMakePresets.json$"
args:
- "--schemafile"
- "https://cmake.org/cmake/help/v3.26/_downloads/3e2d73bff478d88a7de0de736ba5e361/schema.json"
50 changes: 50 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"version": 1,
"cmakeMinimumRequired": {
"major": 3,
"minor": 15,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default configuration",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/cmake-build"
},
{
"name": "release",
"displayName": "Compile in Release mode",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "debug",
"displayName": "Compile in Debug mode",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "sanitizers",
"displayName": "Compile with sanitizers",
"inherits": "default",
"cacheVariables": {
"ADDRESS_SANITIZER": "ON",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "valgrind",
"displayName": "Have the tests targets run under valgrind",
"inherits": "default",
"cacheVariables": {
"USE_VALGRIND": "ON",
"CMAKE_BUILD_TYPE": "Debug"
}
}
]
}
20 changes: 18 additions & 2 deletions collector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ project(collector-bin)
find_package(Threads)
find_package(CURL REQUIRED)

option(ADDRESS_SANITIZER "Compile collector with asan and ubsan" OFF)
option(USE_VALGRIND "Compile unit tests to run under valgrind" OFF)
option(DISABLE_PROFILING "Compile with standard malloc implementation" OFF)
option(TRACE_SINSP_EVENTS "Log all processed events" OFF)
option(BPF_DEBUG_MODE "Enable bpf_printk for the BPF probe" OFF)
option(COLLECTOR_VERSION "The collector version being built" "")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall --std=c++17 -pthread -Wno-deprecated-declarations -fno-omit-frame-pointer -rdynamic")

Expand Down Expand Up @@ -31,10 +38,19 @@ if(NOT BPF_DEBUG_MODE)
set(BPF_DEBUG_MODE OFF)
endif()

if (NOT COLLECTOR_VERSION)
set(COLLECTOR_VERSION "0.0.0")
if(NOT COLLECTOR_VERSION)
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/../.git)
# This is the same command used for make tag, we could run that one
# instead, but we should make our best effort to not have build
# systems depend on each other, since it ends up getting quite messy.
execute_process(COMMAND git describe --tags --abbrev=10 --dirty OUTPUT_VARIABLE COLLECTOR_VERSION)
string(STRIP ${COLLECTOR_VERSION} COLLECTOR_VERSION)
else()
set(COLLECTOR_VERSION "0.0.0")
endif()
endif()

message(STATUS "Collector version: ${COLLECTOR_VERSION}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/CollectorVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CollectorVersion.h)

set(FALCO_DIR ${PROJECT_SOURCE_DIR}/../falcosecurity-libs)
Expand Down
2 changes: 1 addition & 1 deletion collector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ COLLECTOR_BUILD_DEPS := $(HDRS) $(SRCS) $(shell find $(BASE_PATH)/falcosecurity-

cmake-configure/collector:
docker exec $(COLLECTOR_BUILDER_NAME) \
cmake -S $(BASE_PATH) -B $(CMAKE_DIR) \
cmake --preset=default \
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
-DDISABLE_PROFILING=$(DISABLE_PROFILING) \
-DUSE_VALGRIND=$(USE_VALGRIND) \
Expand Down
18 changes: 5 additions & 13 deletions collector/container/konflux.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN /tmp/.konflux/scripts/subscription-manager-bro.sh register /mnt && \
unzip \
clang \
bpftool \
cmake-3.18.2-9.el8 \
cmake \
gcc-c++ \
openssl-devel \
ncurses-devel \
Expand Down Expand Up @@ -54,11 +54,6 @@ ARG SRC_ROOT_DIR=${BUILD_DIR}
ARG CMAKE_BUILD_DIR
# TODO(ROX-20240): CMAKE_BUILD_TYPE should probably not be Release for PR, normal branch builds
ARG CMAKE_BUILD_TYPE=Release
# Appends an argument to the driver download URL that is used for filtering alerts on missing kernels.
# TODO(ROX-20240): This needs to be true on PRs only.
ARG USE_VALGRIND=false
ARG ADDRESS_SANITIZER=false
ARG TRACE_SINSP_EVENTS=false

WORKDIR ${BUILD_DIR}

Expand All @@ -67,6 +62,7 @@ RUN mkdir kernel-modules \
&& ln -s builder/third_party third_party \
&& cp -a ${SOURCES_DIR}/collector collector \
&& cp -a ${SOURCES_DIR}/falcosecurity-libs falcosecurity-libs \
&& cp -a ${SOURCES_DIR}/CMakePresets.json CMakePresets.json \
&& cp -a ${SOURCES_DIR}/CMakeLists.txt CMakeLists.txt

# WITH_RHEL_RPMS controls for dependency installation, ie if they were already installed as RPMs.
Expand All @@ -79,13 +75,9 @@ RUN ./builder/install/install-dependencies.sh && \
then DISABLE_PROFILING="OFF"; \
else DISABLE_PROFILING="ON"; \
fi ; \
cmake -S ${SRC_ROOT_DIR} -B ${CMAKE_BUILD_DIR} \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DDISABLE_PROFILING=${DISABLE_PROFILING} \
-DUSE_VALGRIND=${USE_VALGRIND} \
-DADDRESS_SANITIZER=${ADDRESS_SANITIZER} \
-DCOLLECTOR_VERSION=${COLLECTOR_TAG} \
-DTRACE_SINSP_EVENTS=${TRACE_SINSP_EVENTS} && \
cmake --preset=release \
-DDISABLE_PROFILING=${DISABLE_PROFILING} \
-DCOLLECTOR_VERSION=${COLLECTOR_TAG} && \
cmake --build ${CMAKE_BUILD_DIR} --target all -- -j "${NPROCS:-4}" && \
ctest -V --test-dir ${CMAKE_BUILD_DIR} && \
strip -v --strip-unneeded "${CMAKE_BUILD_DIR}/collector/collector"
Expand Down
Loading