diff --git a/.github/workflows/collector-builder.yml b/.github/workflows/collector-builder.yml index 4da23532ec..37d21d29c5 100644 --- a/.github/workflows/collector-builder.yml +++ b/.github/workflows/collector-builder.yml @@ -17,6 +17,7 @@ env: COLLECTOR_TAG: ${{ inputs.collector-tag }} DEFAULT_BUILDER_TAG: master ANSIBLE_CONFIG: ${{ github.workspace }}/ansible/ansible.cfg + USE_CCACHE: ${{ !contains(github.event.pull_request.labels.*.name, 'no-ccache') }} jobs: builder-needs-rebuilding: @@ -74,6 +75,24 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Set up builder ccache + if: env.USE_CCACHE + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/builder/.ccache + key: builder-ccache-${{ matrix.arch }}-${{ github.sha }} + restore-keys: | + builder-ccache-${{ matrix.arch }}- + + - name: Set up builder ccache in docker cache + if: env.USE_CCACHE && matrix.arch != 's390x' + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 + with: + cache-map: | + { + "${{ github.workspace }}/builder/.ccache": "/root/.ccache" + } + - uses: actions/setup-python@v5 with: python-version: "3.10" @@ -128,6 +147,7 @@ jobs: echo "rhacs_eng_password: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}" echo "collector_git_ref: ${{ github.ref }}" echo "collector_builder_tag: ${{ env.COLLECTOR_BUILDER_TAG }}" + echo "use_ccache: ${{ env.USE_CCACHE }}" } > ${{ github.workspace }}/ansible/secrets.yml - name: Build images @@ -156,6 +176,7 @@ jobs: -i ansible/ci \ -e build_hosts='job_id_${{ env.JOB_ID }}' \ -e arch='${{ matrix.arch }}' \ + -e github_workspace='${{ github.workspace }}' \ -e @'${{ github.workspace }}/ansible/secrets.yml' \ ansible/ci-build-builder.yml diff --git a/.github/workflows/collector.yml b/.github/workflows/collector.yml index 3c2f8e4288..1be7dc8d3e 100644 --- a/.github/workflows/collector.yml +++ b/.github/workflows/collector.yml @@ -26,6 +26,7 @@ env: ANSIBLE_CONFIG: ${{ github.workspace }}/ansible/ansible.cfg TRACE_SINSP_EVENTS: ${{ github.event_name == 'pull_request' }} ADDRESS_SANITIZER: ${{ contains(github.event.pull_request.labels.*.name, 'address-sanitizer') }} + USE_CCACHE: ${{ !contains(github.event.pull_request.labels.*.name, 'no-ccache') }} jobs: build-collector-image: @@ -45,6 +46,12 @@ jobs: with: submodules: true + - name: Set up ccache + if: env.USE_CCACHE + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ matrix.arch }} + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -67,6 +74,7 @@ jobs: collector_tag: ${{ inputs.collector-tag }} debug_mode: ${{ github.event_name == 'pull_request' }} driver_version: ${DRIVER_VERSION} + use_ccache: ${{ env.USE_CCACHE }} EOF - name: Build images @@ -123,6 +131,15 @@ jobs: vm-type: rhel-${{ matrix.arch }} job-tag: builder + - name: Set up ccache + if: env.USE_CCACHE + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/.ccache + key: ccache-${{ matrix.arch }}-${{ github.sha }} + restore-keys: | + ccache-${{ matrix.arch }}- + - name: Create Build VMs run: | make -C "${{ github.workspace }}/ansible" create-build-vms @@ -143,6 +160,7 @@ jobs: collector_image: ${{ inputs.collector-image }} collector_tag: ${{ inputs.collector-tag }} debug_mode: ${{ github.event_name == 'pull_request' }} + use_ccache: ${{ env.USE_CCACHE }} EOF - name: Build ${{ matrix.arch }} image @@ -152,6 +170,7 @@ jobs: -i ansible/ci \ -e arch='${{ matrix.arch }}' \ -e build_hosts='job_id_${{ env.JOB_ID }}' \ + -e github_workspace='${{ github.workspace }}' \ -e @'${{ github.workspace }}/ansible/secrets.yml' \ ansible/ci-build-collector.yml diff --git a/.gitignore b/.gitignore index 2287cee635..c6e4b82c24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea/ .rox/ +.ccache/ +builder/.ccache/ integration-tests/container-logs/ integration-tests/*.log diff --git a/Makefile b/Makefile index 51dbd0c731..94c61a50a6 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ NPROCS ?= $(shell nproc) DEV_SSH_SERVER_KEY ?= $(CURDIR)/.collector_dev_ssh_host_ed25519_key BUILD_BUILDER_IMAGE ?= false +CCACHE_DIR?=$(CURDIR)/.ccache + export COLLECTOR_VERSION := $(COLLECTOR_TAG) .PHONY: tag @@ -25,6 +27,7 @@ container-dockerfile-dev: builder: ifneq ($(BUILD_BUILDER_IMAGE), false) docker buildx build --load --platform ${PLATFORM} \ + --build-arg USE_CCACHE="$(USE_CCACHE)" \ -t quay.io/stackrox-io/collector-builder:$(COLLECTOR_BUILDER_TAG) \ -f "$(CURDIR)/builder/Dockerfile" \ "$(CURDIR)/builder" @@ -84,6 +87,7 @@ start-builder: builder teardown-builder --name $(COLLECTOR_BUILDER_NAME) \ --pull missing \ --platform ${PLATFORM} \ + -v $(CCACHE_DIR):/root/.ccache \ -v $(CURDIR):$(CURDIR) \ $(if $(LOCAL_SSH_PORT),-p $(LOCAL_SSH_PORT):22 )\ -w $(CURDIR) \ diff --git a/Makefile-constants.mk b/Makefile-constants.mk index b4b4ebd83a..bc61d5f7be 100644 --- a/Makefile-constants.mk +++ b/Makefile-constants.mk @@ -10,6 +10,7 @@ HOST_ARCH := $(shell uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') PLATFORM ?= "linux/$(HOST_ARCH)" USE_VALGRIND ?= false +USE_CCACHE ?= false ADDRESS_SANITIZER ?= false CMAKE_BUILD_TYPE ?= Release CMAKE_BASE_DIR = cmake-build-$(shell echo $(CMAKE_BUILD_TYPE) | tr A-Z a-z)-$(HOST_ARCH) diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg index b8cbc14868..39d0c5fbca 100644 --- a/ansible/ansible.cfg +++ b/ansible/ansible.cfg @@ -5,6 +5,7 @@ display_skipped_hosts = false host_key_checking = false remote_tmp = /tmp/ansible forks = 20 +callbacks_enabled = profile_tasks [ssh_connection] ssh_args = -o StrictHostKeyChecking=no -C -o ControlMaster=auto -o ControlPersist=60s -o ServerAliveInterval=30 -o ServerAliveCountMax=10 diff --git a/ansible/ci-build-builder.yml b/ansible/ci-build-builder.yml index d91284aaee..443feb018a 100644 --- a/ansible/ci-build-builder.yml +++ b/ansible/ci-build-builder.yml @@ -1,15 +1,20 @@ --- -- name: Build and push collector image +- name: Build and push builder image hosts: "{{ build_hosts | default('all') }}" environment: BUILD_BUILDER_IMAGE: "true" COLLECTOR_BUILDER_TAG: "{{ collector_builder_tag }}" PLATFORM: "linux/{{ arch }}" + USE_CCACHE: "{{ use_ccache|bool|lower }}" vars: collector_root: "{{ ansible_env.HOME }}/collector" local_branch: local + ccache_dir: "builder/.ccache" + ccache_archive: "docker.tar.gz" + ccache_path: "{{ ccache_dir }}/{{ ccache_archive }}" + container_ccache_dir: "/root/.ccache" tasks: - name: Clone repository @@ -21,14 +26,54 @@ # than with commit hashes, prevents "reference is not a tree" errors version: "{{ local_branch }}" refspec: "+{{ collector_git_ref | replace('refs/', '') }}:{{ local_branch }}" - recursive: true + depth: 1 + recursive: false when: arch == "s390x" + - name: Clone submodules + ansible.builtin.shell: | + git submodule update --init --depth 1 + args: + chdir: "{{ collector_root }}" + when: arch == "s390x" + + - name: Check if ccache exists + delegate_to: localhost + ansible.builtin.stat: + path: "{{ github_workspace }}/{{ ccache_path }}" + register: ccache_check + when: use_ccache and arch == "s390x" + + - name: Copy ccache + ansible.builtin.copy: + src: "{{ github_workspace }}/{{ ccache_path }}" + dest: "{{ collector_root }}/{{ ccache_dir }}/" + when: use_ccache and arch == "s390x" and ccache_check.stat.exists + + - name: Inject docker cache with ccache + ansible.builtin.shell: + cmd: ansible/scripts/inject_docker_cache.sh "{{ collector_root }}/{{ ccache_dir }}" "{{ container_ccache_dir }}" + chdir: "{{ collector_root }}" + when: use_ccache and arch == "s390x" and ccache_check.stat.exists + - name: Build the collector builder image community.general.make: chdir: "{{ ansible_env.GITHUB_WORKSPACE | default(collector_root) }}" target: builder + - name: Extract ccache from docker cache + ansible.builtin.shell: + cmd: ansible/scripts/extract_docker_cache.sh "{{ collector_root }}/{{ ccache_dir }}" "{{ container_ccache_dir }}" + chdir: "{{ collector_root }}" + when: use_ccache and arch == "s390x" + + - name: Fetch ccache + ansible.builtin.fetch: + src: "{{ collector_root }}/{{ ccache_path }}" + dest: "{{ github_workspace }}/{{ ccache_dir }}/" + flat: yes + when: use_ccache and arch == "s390x" + - name: Retag collector builder image to arch specific community.docker.docker_image: name: "quay.io/stackrox-io/collector-builder:{{ ansible_env.COLLECTOR_BUILDER_TAG }}" diff --git a/ansible/ci-build-collector.yml b/ansible/ci-build-collector.yml index 960eb4d8f2..5be8d5ea34 100644 --- a/ansible/ci-build-collector.yml +++ b/ansible/ci-build-collector.yml @@ -8,10 +8,14 @@ COLLECTOR_TAG: "{{ collector_tag }}" DISABLE_PROFILING: "{{ disable_profiling }}" CMAKE_BUILD_TYPE: "{{ 'Debug' if debug_mode else 'Release' }}" + USE_CCACHE: "{{ use_ccache|bool|lower }}" + CCACHE_DIR: "{{ ansible_env.GITHUB_WORKSPACE | default(collector_root) }}/.ccache" vars: collector_root: "{{ ansible_env.HOME }}/collector" local_branch: local + ccache_dir: ".ccache" + ccache_archive: "docker.tar.gz" tasks: - debug: var=collector_root @@ -24,9 +28,43 @@ # than with commit hashes, prevents "reference is not a tree" errors version: "{{ local_branch }}" refspec: "+{{ collector_git_ref | replace('refs/', '') }}:{{ local_branch }}" - recursive: true + depth: 1 + recursive: false when: arch == "s390x" + - name: Clone submodules + ansible.builtin.shell: | + git submodule update --init --depth 1 + args: + chdir: "{{ collector_root }}" + when: arch == "s390x" + + - name: Check if ccache exists + delegate_to: localhost + ansible.builtin.stat: + path: "{{ github_workspace }}/{{ ccache_dir }}/{{ ccache_archive }}" + register: ccache_check + when: use_ccache and arch == "s390x" + + - name: Create cccache directory + ansible.builtin.file: + path: "{{ collector_root }}/{{ ccache_dir }}" + state: directory + when: use_ccache and arch == "s390x" and ccache_check.stat.exists + + - name: Copy ccache + ansible.builtin.copy: + src: "{{ github_workspace }}/{{ ccache_dir }}/{{ ccache_archive }}" + dest: "{{ collector_root }}/" + when: use_ccache and arch == "s390x" and ccache_check.stat.exists + + - name: Unarchive ccache + ansible.builtin.unarchive: + src: "{{ collector_root }}/{{ ccache_archive }}" + dest: "{{ collector_root }}/{{ ccache_dir }}" + remote_src: true + when: use_ccache and arch == "s390x" and ccache_check.stat.exists + - name: Run the builder image community.general.make: chdir: "{{ ansible_env.GITHUB_WORKSPACE | default(collector_root) }}" @@ -40,6 +78,20 @@ # ensure this action is printed tags: [print_action] + - name: Create ccache archive + ansible.builtin.shell: | + rm -f "{{ collector_root }}/{{ ccache_archive }}" + cd "{{ collector_root }}/{{ ccache_dir }}" + tar czf "{{ collector_root }}/{{ ccache_archive }}" . + when: use_ccache and arch == "s390x" + + - name: Fetch ccache + ansible.builtin.fetch: + src: "{{ collector_root }}/{{ ccache_archive }}" + dest: "{{ github_workspace }}/{{ ccache_dir }}/" + flat: yes + when: use_ccache and arch == "s390x" + - name: Retag collector image to arch specific community.docker.docker_image: name: "{{ collector_image }}" diff --git a/ansible/scripts/extract_docker_cache.sh b/ansible/scripts/extract_docker_cache.sh new file mode 100755 index 0000000000..d7c27ca536 --- /dev/null +++ b/ansible/scripts/extract_docker_cache.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# based on https://github.com/reproducible-containers/buildkit-cache-dance + +set -e + +usage() { + echo "Usage: $0 " + exit 1 +} + +if [ "$#" -ne 2 ]; then + usage +fi + +CACHE_DEST="$1" +TARGET_PATH="$2" + +CCACHE_ARCHIVE="docker.tar.gz" + +SCRATCH_DIR=$(mktemp -d) +SCRATCH_ARCHIVE=$(mktemp) +# shellcheck disable=SC2064 +trap "rm -rf ${SCRATCH_DIR}; rm -f ${SCRATCH_ARCHIVE}" EXIT + +# Timestamp to bust cache +date -Iseconds > "${SCRATCH_DIR}/buildstamp" + +cat << EOF > "${SCRATCH_DIR}/Dockerfile.extract" +FROM busybox:1 +COPY buildstamp buildstamp +RUN --mount=type=cache,target=${TARGET_PATH} \\ + mkdir -p /var/docker-cache/ \\ + && cp -p -R ${TARGET_PATH}/. /var/docker-cache/ || true +EOF + +echo "Generated Dockerfile.extract" +cat "${SCRATCH_DIR}/Dockerfile.extract" + +# Build the image and load it into Docker +docker buildx build -f "${SCRATCH_DIR}/Dockerfile.extract" --tag cache:extract --load "${SCRATCH_DIR}" +docker images + +# Remove any existing cache-container +docker rm -f cache-container || true + +# Create a container from cache:extract +docker create --name cache-container cache:extract +docker ps + +# Extract the cache from the container +docker cp -L cache-container:/var/docker-cache - | tar -H posix -x -C "${SCRATCH_DIR}" +ls "${SCRATCH_DIR}" + +# Compress the cache from the container +(cd "${SCRATCH_DIR}/docker-cache" && chmod -R 777 . && tar czf "${SCRATCH_ARCHIVE}" .) + +# Move the cache into its dest +rm -f "${CACHE_DEST}/${CCACHE_ARCHIVE}" +mv "${SCRATCH_ARCHIVE}" "${CACHE_DEST}/${CCACHE_ARCHIVE}" +chmod 666 "${CACHE_DEST}/${CCACHE_ARCHIVE}" + +echo "Docker cache extraction completed successfully." diff --git a/ansible/scripts/inject_docker_cache.sh b/ansible/scripts/inject_docker_cache.sh new file mode 100755 index 0000000000..2b74bbca85 --- /dev/null +++ b/ansible/scripts/inject_docker_cache.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# based on https://github.com/reproducible-containers/buildkit-cache-dance + +set -e + +usage() { + echo "Usage: $0 " + exit 1 +} + +if [ "$#" -ne 2 ]; then + usage +fi + +CACHE_SOURCE="$1" +TARGET_PATH="$2" + +if [ ! -d "$CACHE_SOURCE" ]; then + echo "Error: Cache source directory '$CACHE_SOURCE' does not exist." + exit 1 +fi + +CCACHE_ARCHIVE="docker.tar.gz" + +SCRATCH_DIR=$(mktemp -d) +# shellcheck disable=SC2064 +trap "rm -rf ${SCRATCH_DIR}" EXIT + +# Timestamp to bust cache +date -Iseconds > "${CACHE_SOURCE}/buildstamp" + +cat << EOF > "${SCRATCH_DIR}/Dockerfile.inject" +FROM busybox:1 +COPY buildstamp buildstamp +RUN --mount=type=cache,target=${TARGET_PATH} \\ + --mount=type=bind,source=.,target=/var/docker-cache \\ + tar -xzf /var/docker-cache/${CCACHE_ARCHIVE} -C ${TARGET_PATH} || true +EOF + +echo "Generated Dockerfile.inject" +cat "${SCRATCH_DIR}/Dockerfile.inject" + +# Inject ccache into Docker cache +cd "$CACHE_SOURCE" +docker buildx build -f "${SCRATCH_DIR}/Dockerfile.inject" --tag cache:inject . + +echo "Cache injection completed successfully." diff --git a/builder/Dockerfile b/builder/Dockerfile index 4aee6a0c9c..68d6306d7b 100644 --- a/builder/Dockerfile +++ b/builder/Dockerfile @@ -1,6 +1,9 @@ FROM quay.io/centos/centos:stream9 ARG BUILD_DIR=/install-tmp +ARG USE_CCACHE=false + +ENV USE_CCACHE=${USE_CCACHE} USER root @@ -53,7 +56,7 @@ WORKDIR ${BUILD_DIR} COPY install builder/install COPY third_party third_party -RUN "builder/install/install-dependencies.sh" && \ +RUN --mount=type=cache,target=/root/.ccache/ "builder/install/install-dependencies.sh" && \ rm -rf ${BUILD_DIR} && \ echo -e '/usr/local/lib\n/usr/local/lib64' > /etc/ld.so.conf.d/usrlocallib.conf && ldconfig diff --git a/builder/install/10-gperftools.sh b/builder/install/10-gperftools.sh index 3a6ead8934..032d54f5d9 100755 --- a/builder/install/10-gperftools.sh +++ b/builder/install/10-gperftools.sh @@ -2,6 +2,11 @@ set -e +if [ "${USE_CCACHE}" = "true" ]; then + export CC="ccache gcc" + export CXX="ccache g++" +fi + cd third_party/gperftools cp COPYING "${LICENSE_DIR}/gperftools-${GPERFTOOLS_VERSION}" diff --git a/builder/install/50-jq.sh b/builder/install/50-jq.sh index b5b27f46e8..6d0fab0e6a 100755 --- a/builder/install/50-jq.sh +++ b/builder/install/50-jq.sh @@ -7,6 +7,11 @@ if [ -n "${WITH_RHEL_RPMS}" ]; then exit 0 fi +if [ "${USE_CCACHE}" = "true" ]; then + export CC="ccache gcc" + export CXX="ccache g++" +fi + wget "https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-${JQ_VERSION}.tar.gz" tar -zxf "jq-${JQ_VERSION}.tar.gz" cd "jq-${JQ_VERSION}" diff --git a/builder/install/50-libb64.sh b/builder/install/50-libb64.sh index f731db8534..f2932127c7 100755 --- a/builder/install/50-libb64.sh +++ b/builder/install/50-libb64.sh @@ -8,5 +8,10 @@ cat AUTHORS LICENSE > "${LICENSE_DIR}/libb64-${B64_VERSION}" CFLAGS=-fPIC make all_base64 +if [ "${USE_CCACHE}" = "true" ]; then + export CC="ccache gcc" + export CXX="ccache g++" +fi + cp src/libb64.a /usr/local/lib/ cp -r include/b64 /usr/local/include/ diff --git a/builder/install/60-tbb.sh b/builder/install/60-tbb.sh index 2bb8288c2a..185f7efbb6 100755 --- a/builder/install/60-tbb.sh +++ b/builder/install/60-tbb.sh @@ -7,6 +7,11 @@ if [ -n "${WITH_RHEL_RPMS}" ]; then exit 0 fi +if [ "${USE_CCACHE}" = "true" ]; then + export CC="ccache gcc" + export CXX="ccache g++" +fi + git clone --branch "$TBB_VERSION" --depth 1 https://github.com/intel/tbb cd tbb cp LICENSE "${LICENSE_DIR}/tbb-${TBB_VERSION}" diff --git a/builder/install/80-libbpf.sh b/builder/install/80-libbpf.sh index 29a3202cc1..acbab402d0 100755 --- a/builder/install/80-libbpf.sh +++ b/builder/install/80-libbpf.sh @@ -2,6 +2,11 @@ set -e +if [ "${USE_CCACHE}" = "true" ]; then + export CC="ccache gcc" + export CXX="ccache g++" +fi + cd third_party/libbpf cp LICENSE "${LICENSE_DIR}/libbpf-${LIBBPF_VERSION}" diff --git a/builder/install/ccache.sh b/builder/install/ccache.sh new file mode 100755 index 0000000000..6720f0860c --- /dev/null +++ b/builder/install/ccache.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +## TODO: update builder image to fedora and use builtin ccache + +if [ "$USE_CCACHE" = "true" ]; then + + git clone https://github.com/ccache/ccache.git third_party/ccache + + cd third_party/ccache + git fetch --tags + git checkout "${CCACHE_VERSION}" + + mkdir cmake-build && cd cmake-build + cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF -DENABLE_DOCUMENTATION=OFF -DREDIS_STORAGE_BACKEND=OFF .. + + make -j "${NPROCS}" + make install + ccache --version +fi diff --git a/builder/install/install-dependencies.sh b/builder/install/install-dependencies.sh index 082f62ec88..50b64aa6dc 100755 --- a/builder/install/install-dependencies.sh +++ b/builder/install/install-dependencies.sh @@ -6,13 +6,35 @@ export LICENSE_DIR="/THIRD_PARTY_NOTICES" mkdir -p "${LICENSE_DIR}" -export NPROCS NPROCS="$(nproc)" +export NPROCS # shellcheck source=SCRIPTDIR/versions.sh source builder/install/versions.sh + +if [ "${USE_CCACHE}" = "true" ]; then + # build and install ccache + ./builder/install/ccache.sh + + # create a wrapper utility for clang-17 used by modern bpf builds in falco + printf '#!/bin/sh\nexec ccache /usr/bin/clang-17 "$@"\n' > /usr/local/bin/ccache-clang + chmod +x /usr/local/bin/ccache-clang + echo /usr/local/bin/ccache-clang + + # Use ccache in cmake builds + export CMAKE_C_COMPILER_LAUNCHER=ccache + export CMAKE_CXX_COMPILER_LAUNCHER=ccache + + # print stats and zero them + ccache -z -d /root/.ccache +fi + for f in builder/install/[0-9][0-9]-*.sh; do echo "=== $f ===" ./"$f" ldconfig done + +if [ "${USE_CCACHE}" = "true" ]; then + ccache -s -d /root/.ccache +fi diff --git a/builder/install/versions.sh b/builder/install/versions.sh index 075f8bd3f0..93dcd87808 100644 --- a/builder/install/versions.sh +++ b/builder/install/versions.sh @@ -2,6 +2,7 @@ export B64_VERSION=1.2.1 export CARES_VERSION=1.16.0 +export CCACHE_VERSION=v4.10.2 export CMAKE_VERSION=3.15.2 export GOOGLETEST_REVISION=release-1.10.0 export GRPC_REVISION=v1.28.1 diff --git a/collector/CMakeLists.txt b/collector/CMakeLists.txt index bb35c5dc0b..44533ce138 100644 --- a/collector/CMakeLists.txt +++ b/collector/CMakeLists.txt @@ -35,6 +35,11 @@ if (NOT COLLECTOR_VERSION) set(COLLECTOR_VERSION "0.0.0") endif() +if(USE_CCACHE) + set(CMAKE_C_COMPILER_LAUNCHER ccache) + set(CMAKE_CXX_COMPILER_LAUNCHER ccache) +endif() + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/CollectorVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CollectorVersion.h) set(FALCO_DIR ${PROJECT_SOURCE_DIR}/../falcosecurity-libs) @@ -85,6 +90,9 @@ add_executable(self-checks self-checks.cpp) add_subdirectory(test) # Falco Wrapper Library +if(USE_CCACHE) + set(MODERN_CLANG_EXE "/usr/local/bin/ccache-clang" CACHE STRING "USE CCACHE" FORCE) +endif() set(BUILD_DRIVER OFF CACHE BOOL "Build the driver on Linux" FORCE) set(USE_BUNDLED_DEPS OFF CACHE BOOL "Enable bundled dependencies instead of using the system ones" FORCE) set(USE_BUNDLED_CARES OFF CACHE BOOL "Enable bundled dependencies instead of using the system ones" FORCE) diff --git a/collector/Makefile b/collector/Makefile index 0295a8d26d..6985b4d72f 100644 --- a/collector/Makefile +++ b/collector/Makefile @@ -20,6 +20,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) \ + -DUSE_CCACHE=$(USE_CCACHE) -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \ -DDISABLE_PROFILING=$(DISABLE_PROFILING) \ -DUSE_VALGRIND=$(USE_VALGRIND) \