Skip to content
Merged
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
31 changes: 4 additions & 27 deletions .github/workflows/cpp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,17 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Install Protobuf
uses: mamba-org/setup-micromamba@v2
with:
environment-name: calf-ci
create-args: libprotobuf=6.31.1
cache-environment: true

- name: Install build tools
- name: Install dependencies
run: |
apt-get update
apt-get install -y cmake git ninja-build
apt-get install -y cmake git ninja-build libprotobuf-dev protobuf-compiler

- name: Configure
shell: bash -el {0}
run: |
export LDFLAGS="-L${CONDA_PREFIX}/lib"
cmake -S "${GITHUB_WORKSPACE}" \
-B "${GITHUB_WORKSPACE}/build" \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_BUILD_RPATH="${CONDA_PREFIX}/lib" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCALF_TESTS=ON \
-DCALF_PYTHON_TESTS=OFF \
-DCALF_PROTOBUF_FETCH=OFF
Expand All @@ -68,7 +57,6 @@ jobs:
run: test ! -d "${GITHUB_WORKSPACE}/build/_deps/protobuf-src"

- name: Build
shell: bash -el {0}
run: cmake --build "${GITHUB_WORKSPACE}/build" --parallel

- name: Run tests
Expand All @@ -87,25 +75,15 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Install Protobuf
uses: mamba-org/setup-micromamba@v2
with:
environment-name: calf-ci
create-args: libprotobuf=6.31.1
cache-environment: true

- name: Install build tools
run: brew install cmake ninja
- name: Install dependencies
run: brew install cmake ninja protobuf

- name: Configure
shell: bash -el {0}
run: |
cmake -S "${GITHUB_WORKSPACE}" \
-B "${GITHUB_WORKSPACE}/build" \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_BUILD_RPATH="${CONDA_PREFIX}/lib" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCALF_TESTS=ON \
-DCALF_PYTHON_TESTS=OFF \
-DCALF_PROTOBUF_FETCH=OFF
Expand All @@ -115,7 +93,6 @@ jobs:
run: test ! -d "${GITHUB_WORKSPACE}/build/_deps/protobuf-src"

- name: Build
shell: bash -el {0}
run: cmake --build "${GITHUB_WORKSPACE}/build" --parallel

- name: Run tests
Expand Down
54 changes: 37 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ option(CALF_TESTS "Enable CALF unit tests" OFF)
option(CALF_PYTHON_TESTS "Enable CALF Python binding tests" ${CALF_TESTS})
option(CALF_BUILD_PYTHON_BINDINGS "Build Python bindings for CALF" OFF)
option(CALF_PROTOBUF "Build the Google Protobuf C++ logging component. Fallback to JSON logging when turned OFF" ON)
option(CALF_PROTOBUF_FETCH "Fetch Protobuf when a compatible installation is unavailable" ON)
option(CALF_PROTOBUF_REGENERATE "Build protoc and add the calf_regenerate_protobuf target" OFF)
option(CALF_PROTOBUF_FETCH "Fetch Protobuf when an installation is unavailable" ON)
option(CALF_PROTOBUF_FORCE_FETCH "Fetch Protobuf even when it is installed" OFF)
option(CALF_PROTOBUF_REGENERATE "Add the calf_regenerate_protobuf target" OFF)

set(CALF_DEFAULT_COMPONENT_NAME "calf" CACHE STRING "Fallback component name")
set(CALF_DEFAULT_LOG_DIR_NAME "./calf_logs" CACHE STRING "Fallback default log dir name")
Expand All @@ -27,12 +28,18 @@ endif()
# Protobuf component
# ---------------------------------------------------------------------------
if(CALF_PROTOBUF)
# Protobuf 6.31.1 is built from upstream release 31.1, whose CMake package
# reports the project version as 31.1.0.
find_package(Protobuf 31.1.0 EXACT CONFIG QUIET)
if(NOT Protobuf_FOUND)
if(NOT CALF_PROTOBUF_FETCH)
message(FATAL_ERROR "Protobuf 6.31.1 is required when CALF_PROTOBUF_FETCH=OFF")
if(NOT CALF_PROTOBUF_FORCE_FETCH)
find_package(Protobuf CONFIG QUIET)
if(NOT Protobuf_FOUND)
find_package(Protobuf QUIET)
endif()
if(Protobuf_FOUND AND NOT TARGET protobuf::protoc)
set(Protobuf_FOUND FALSE)
endif()
endif()
if(CALF_PROTOBUF_FORCE_FETCH OR NOT Protobuf_FOUND)
if(NOT CALF_PROTOBUF_FETCH AND NOT CALF_PROTOBUF_FORCE_FETCH)
message(FATAL_ERROR "Protobuf with protoc is not installed and CALF_PROTOBUF_FETCH=OFF")
endif()
include(FetchContent)
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -47,9 +54,9 @@ if(CALF_PROTOBUF)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_CONFORMANCE OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_PROTOC_BINARIES ${CALF_PROTOBUF_REGENERATE} CACHE BOOL "" FORCE)
set(protobuf_BUILD_LIBPROTOC ${CALF_PROTOBUF_REGENERATE} CACHE BOOL "" FORCE)
set(protobuf_BUILD_LIBUPB ${CALF_PROTOBUF_REGENERATE} CACHE BOOL "" FORCE)
set(protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "" FORCE)
set(protobuf_BUILD_LIBPROTOC ON CACHE BOOL "" FORCE)
set(protobuf_BUILD_LIBUPB ON CACHE BOOL "" FORCE)
set(protobuf_INSTALL OFF CACHE BOOL "" FORCE)
set(protobuf_WITH_ZLIB OFF CACHE BOOL "" FORCE)
set(utf8_range_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
Expand All @@ -63,6 +70,7 @@ if(CALF_PROTOBUF)
FetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
# ponytail: keep one known-good download fallback; installed versions are unrestricted.
GIT_TAG v31.1
GIT_SHALLOW TRUE
${_CALF_PROTOBUF_SYSTEM}
Expand All @@ -88,9 +96,24 @@ if(CALF_PROTOBUF)
message(STATUS "CALF using installed Protobuf ${Protobuf_VERSION}: ${Protobuf_LIBRARIES}")
endif()

if(NOT TARGET protobuf::protoc)
message(FATAL_ERROR "The selected Protobuf installation does not provide protoc")
endif()
set(_CALF_PROTOBUF_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/calf/protobuf")
add_custom_command(
OUTPUT "${_CALF_PROTOBUF_GENERATED_DIR}/calf_trace.pb.cc"
"${_CALF_PROTOBUF_GENERATED_DIR}/calf_trace.pb.h"
COMMAND ${CMAKE_COMMAND} -E make_directory "${_CALF_PROTOBUF_GENERATED_DIR}"
COMMAND protobuf::protoc
--cpp_out=${CMAKE_CURRENT_BINARY_DIR}
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/calf/protobuf/calf_trace.proto
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/calf/protobuf/calf_trace.proto protobuf::protoc
VERBATIM
)
add_library(calf_protobuf_schema STATIC
calf/protobuf/calf_trace.pb.cc
calf/protobuf/calf_trace.pb.h
"${_CALF_PROTOBUF_GENERATED_DIR}/calf_trace.pb.cc"
"${_CALF_PROTOBUF_GENERATED_DIR}/calf_trace.pb.h"
)
add_library(calf_protobuf INTERFACE)
add_library(calf::protobuf ALIAS calf_protobuf)
Expand All @@ -100,7 +123,7 @@ if(CALF_PROTOBUF)
target_compile_options(calf_protobuf_schema PRIVATE -Wno-error)
endif()
target_include_directories(calf_protobuf_schema
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(calf_protobuf_schema PUBLIC protobuf::libprotobuf)
target_compile_definitions(calf_protobuf INTERFACE CALF_LOG_FORMAT_PROTOBUF)
target_link_libraries(calf_protobuf INTERFACE calf_headers calf_protobuf_schema)
Expand All @@ -111,9 +134,6 @@ if(CALF_PROTOBUF)
endforeach()

if(CALF_PROTOBUF_REGENERATE)
if(NOT TARGET protobuf::protoc)
message(FATAL_ERROR "CALF_PROTOBUF_REGENERATE requires the protobuf::protoc target")
endif()
add_custom_target(calf_regenerate_protobuf
COMMAND protobuf::protoc
--cpp_out=${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ The trace is streamed as logging occurs; CALF does not build the complete trace
in memory. `StlLogger` uses generated protobuf support for the schema, while
`SyscallLogger` writes compatible protobuf bytes through raw syscalls.

CMake uses any installed Google Protobuf package that provides `protoc` and
generates the schema with it. Otherwise, it downloads Protobuf through
`FetchContent`.

### JSON fallback

JSON is selected automatically by `calf_enable_log(target ON)` when
Expand Down Expand Up @@ -273,7 +277,9 @@ void internal_operation() {
|---|---:|---|
| `CALF_LOG` | `ON` | Enables logging macros globally; when disabled, they are no-ops. |
| `CALF_PROTOBUF` | `ON` | Builds Perfetto support and the `calf::protobuf` target. |
| `CALF_PROTOBUF_FETCH` | `ON` | Fetches the required protobuf version when it is not installed. |
| `CALF_PROTOBUF_FETCH` | `ON` | Downloads Protobuf when an installation with `protoc` is unavailable. |
| `CALF_PROTOBUF_FORCE_FETCH` | `OFF` | Downloads and uses Protobuf even when it is installed. |
| `CALF_PROTOBUF_REGENERATE` | `OFF` | Adds the `calf_regenerate_protobuf` source regeneration target. |
| `CALF_TESTS` | `OFF` | Builds and registers the C++ test suites. |
| `CALF_PYTHON_TESTS` | Value of `CALF_TESTS` | Builds the Python extension and registers binding tests. |
| `CALF_BUILD_PYTHON_BINDINGS` | `OFF` | Builds and installs the private `calf._py_calf` extension. |
Expand Down
Loading
Loading