Skip to content

refactor: build bundled zlib via CMake instead of CONFIGURE_COMMAND - #3020

Open
mvanhorn wants to merge 4 commits into
falcosecurity:masterfrom
mvanhorn:refactor/2584-zlib-cmake
Open

refactor: build bundled zlib via CMake instead of CONFIGURE_COMMAND#3020
mvanhorn wants to merge 4 commits into
falcosecurity:masterfrom
mvanhorn:refactor/2584-zlib-cmake

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Build the bundled zlib dependency on non-Windows via zlib's own CMake build instead of
invoking its hand-written ./configure script through ExternalProject_Add's
CONFIGURE_COMMAND. zlib v1.3.1 ships a first-class CMakeLists.txt, so the bundled dep is now
configured and built with CMake (mirroring the existing Windows branch and the
jsoncpp/re2/tbb modules), with build settings passed via CMAKE_ARGS and the toolchain
forwarded through the shared falcosecurity_external_project_cache_args mechanism.

Why this matters

Issue #2584 tracks this as a build-system maintainability cleanup. Using zlib's own CMake build
drops the bespoke ./configure + make + CFLAGS plumbing (-O3/-g, -fPIC, and toolchain
flag accumulation) in favor of standard CMake cache vars (CMAKE_BUILD_TYPE,
CMAKE_POSITION_INDEPENDENT_CODE, CMAKE_C_FLAGS), and unifies how the bundled dependency
toolchain is propagated with the rest of the bundled deps.

Changes

  • cmake/modules/zlib.cmake (non-Windows branch): replace CONFIGURE_COMMAND ./configure /
    BUILD_COMMAND make / BUILD_IN_SOURCE 1 with a CMake configure+build via CMAKE_ARGS and
    CMAKE_CACHE_ARGS ${ZLIB_EXTERNAL_PROJECT_CACHE_ARGS}.
  • Build only the library type that is actually consumed (zlibstatic for static builds, zlib
    for shared) so the unused target is never compiled — preserving the old ./configure --static
    behavior and keeping static-only / cross toolchains working.
  • -DZLIB_BUILD_EXAMPLES=OFF so the bundled sub-build skips zlib's example/test executables.
  • ZLIB_INCLUDE / ZLIB_LIB / ZLIB_HEADERS continue to point at the produced library and
    headers, so downstream consumers (libscap, libsinsp, libpman, libbpf) see no interface
    change.

Testing

The cmake/modules/zlib.cmake module is syntactically valid and the ExternalProject_Add
arguments are internally consistent (verified by configuring the module in isolation and by
building the bundled zlib sub-project directly for static and shared, single- and multi-config
generators). A full falcosecurity/libs build was not run locally as it requires the complete
dependency set; CI exercises the end-to-end bundled build.

Fixes #2584


AI was used for assistance.

Does this PR introduce a user-facing change?:

NONE

@poiana

poiana commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Welcome @mvanhorn! It looks like this is your first PR to falcosecurity/libs 🎉

@poiana poiana added the size/L label Jun 9, 2026
@poiana
poiana requested review from hbrueckner and terror96 June 9, 2026 11:02
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.56%. Comparing base (1a1d1e7) to head (f5ddc15).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3020   +/-   ##
=======================================
  Coverage   76.56%   76.56%           
=======================================
  Files         301      301           
  Lines       33693    33693           
  Branches     5038     5038           
=======================================
  Hits        25797    25797           
  Misses       7896     7896           
Flag Coverage Δ
libsinsp 76.56% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

Perf diff from master - unit tests

    18.88%     -9.36%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
    14.25%     +6.17%  [.] std::__shared_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__weak_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
    10.72%     +5.38%  [.] sinsp_thread_manager::create_thread_dependencies(std::shared_ptr<sinsp_threadinfo> const&)
     4.58%     +3.82%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
    19.81%     -3.77%  [.] sinsp_threadinfo::get_main_thread()
     7.23%     -1.57%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
     9.25%     -0.66%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
     3.63%     +0.18%  [.] sinsp_threadinfo::get_fd_table() const
     4.53%     -0.12%  [.] thread_group_info::get_first_thread() const
     0.13%     -0.06%  [.] sinsp_threadinfo::~sinsp_threadinfo()

Heap diff from master - unit tests

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                                             Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                                                -0.0499         -0.0498           288           274           288           274
BM_sinsp_split_median                                                              -0.0460         -0.0456           287           274           287           274
BM_sinsp_split_stddev                                                              -0.6435         -0.6342             5             2             5             2
BM_sinsp_split_cv                                                                  -0.6247         -0.6150             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                                      -0.0670         -0.0668            67            63            67            63
BM_sinsp_concatenate_paths_relative_path_median                                    -0.0669         -0.0666            67            63            67            63
BM_sinsp_concatenate_paths_relative_path_stddev                                    +0.6298         +0.6650             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_cv                                        +0.7469         +0.7841             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                                         +0.0647         +0.0650            45            48            45            48
BM_sinsp_concatenate_paths_empty_path_median                                       +0.0751         +0.0751            44            48            44            48
BM_sinsp_concatenate_paths_empty_path_stddev                                       -0.7877         -0.7873             1             0             1             0
BM_sinsp_concatenate_paths_empty_path_cv                                           -0.8006         -0.8002             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                                      -0.1003         -0.1003            66            60            66            60
BM_sinsp_concatenate_paths_absolute_path_median                                    -0.1005         -0.1004            66            60            66            60
BM_sinsp_concatenate_paths_absolute_path_stddev                                    -0.6396         -0.6354             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_cv                                        -0.5994         -0.5947             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_ascii_short_mean                                  +0.0199         +0.0199            15            15            15            15
BM_sinsp_utf8_sanitize_fast_path_ascii_short_median                                +0.0173         +0.0171            15            15            15            15
BM_sinsp_utf8_sanitize_fast_path_ascii_short_stddev                               +51.7198        +51.5843             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_ascii_short_cv                                   +50.6892        +50.5560             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_ascii_long_mean                                   -0.0003         -0.0003            87            87            87            87
BM_sinsp_utf8_sanitize_fast_path_ascii_long_median                                 -0.0000         -0.0000            87            87            87            87
BM_sinsp_utf8_sanitize_fast_path_ascii_long_stddev                                 -0.5479         -0.6425             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_ascii_long_cv                                     -0.5478         -0.6424             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_multibyte_short_mean                              +0.0115         +0.0116            12            13            12            13
BM_sinsp_utf8_sanitize_fast_path_multibyte_short_median                            +0.0004         +0.0005            12            12            12            12
BM_sinsp_utf8_sanitize_fast_path_multibyte_short_stddev                          +109.1883       +107.3979             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_multibyte_short_cv                              +107.9302       +106.1575             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_multibyte_long_mean                               +0.1778         +0.1778          3801          4477          3800          4476
BM_sinsp_utf8_sanitize_fast_path_multibyte_long_median                             +0.2394         +0.2394          3801          4711          3800          4709
BM_sinsp_utf8_sanitize_fast_path_multibyte_long_stddev                           +361.1650       +305.0976             1           315             1           315
BM_sinsp_utf8_sanitize_fast_path_multibyte_long_cv                               +306.4983       +258.8973             0             0             0             0
BM_sinsp_utf8_sanitize_fast_path_mixed_long_mean                                   +0.2964         +0.2965          1676          2173          1675          2172
BM_sinsp_utf8_sanitize_fast_path_mixed_long_median                                 +0.2905         +0.2904          1683          2172          1683          2171
BM_sinsp_utf8_sanitize_fast_path_mixed_long_stddev                                 -0.6193         -0.6211            25            10            25            10
BM_sinsp_utf8_sanitize_fast_path_mixed_long_cv                                     -0.7063         -0.7078             0             0             0             0
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_alloc_mean                       +0.3184         +0.3185          1115          1470          1114          1469
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_alloc_median                     +0.3171         +0.3171          1114          1467          1114          1467
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_alloc_stddev                     +3.9600         +4.1044             2             8             2             8
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_alloc_cv                         +2.7621         +2.8714             0             0             0             0
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_noalloc_mean                     +0.3444         +0.3444          1112          1495          1111          1494
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_noalloc_median                   +0.3395         +0.3394          1111          1489          1111          1488
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_noalloc_stddev                   +9.9765         +9.7442             1            11             1            11
BM_sinsp_utf8_sanitize_slow_path_c1_controls_long_noalloc_cv                       +7.1645         +6.9916             0             0             0             0
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_alloc_mean                    -0.0072         -0.0072           235           234           235           234
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_alloc_median                  -0.0051         -0.0050           234           232           234           232
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_alloc_stddev                  +0.1937         +0.1944             4             5             4             5
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_alloc_cv                      +0.2024         +0.2031             0             0             0             0
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_noalloc_mean                  +0.0177         +0.0179           143           146           143           146
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_noalloc_median                +0.0271         +0.0273           142           146           142           146
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_noalloc_stddev                -0.8250         -0.8258             2             0             2             0
BM_sinsp_utf8_sanitize_slow_path_sparse_invalid_long_noalloc_cv                    -0.8281         -0.8289             0             0             0             0
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_alloc_mean                       -0.0511         -0.0511         11817         11213         11812         11209
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_alloc_median                     -0.0543         -0.0544         11749         11110         11744         11106
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_alloc_stddev                     +0.2790         +0.2862           187           239           186           240
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_alloc_cv                         +0.3478         +0.3554             0             0             0             0
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_noalloc_mean                     +0.0134         +0.0134         11311         11462         11307         11458
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_noalloc_median                   +0.0244         +0.0243         11178         11451         11174         11445
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_noalloc_stddev                   -0.9554         -0.9554          1056            47          1056            47
BM_sinsp_utf8_sanitize_slow_path_all_invalid_long_noalloc_cv                       -0.9560         -0.9560             0             0             0             0

@terror96

Copy link
Copy Markdown
Contributor

Ping @irozzo-1A ... do I remember correctly that you did makefile changes before, and could have a better view on this? looks good to me, though.

@irozzo-1A irozzo-1A left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mvanhorn, thanks for your contribution.
Just a potential issue and a nit.

Comment thread cmake/modules/zlib.cmake Outdated
-DCMAKE_INSTALL_LIBDIR=lib
CMAKE_CACHE_ARGS ${ZLIB_EXTERNAL_PROJECT_CACHE_ARGS}
# Build only the target we need so the unused library type is never compiled.
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> --target

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--config $<CONFIG> looks risky here because this branch also supports single-config generators. If $<CONFIG> expands to an empty value, the build command may still be invoked with a bare --config, which can break the external project build.

Could we make --config conditional on GENERATOR_IS_MULTI_CONFIG, similar to how ZLIB_BUILD_CONFIG_SUBDIR is handled above?

Comment thread cmake/modules/zlib.cmake Outdated
Comment on lines +34 to +48
set(ZLIB_HEADERS "")
list(
APPEND
ZLIB_HEADERS
"${ZLIB_INCLUDE}/crc32.h"
"${ZLIB_INCLUDE}/deflate.h"
"${ZLIB_INCLUDE}/gzguts.h"
"${ZLIB_INCLUDE}/inffast.h"
"${ZLIB_INCLUDE}/inffixed.h"
"${ZLIB_INCLUDE}/inflate.h"
"${ZLIB_INCLUDE}/inftrees.h"
"${ZLIB_INCLUDE}/trees.h"
"${ZLIB_SOURCE_DIR}/crc32.h"
"${ZLIB_SOURCE_DIR}/deflate.h"
"${ZLIB_SOURCE_DIR}/gzguts.h"
"${ZLIB_SOURCE_DIR}/inffast.h"
"${ZLIB_SOURCE_DIR}/inffixed.h"
"${ZLIB_SOURCE_DIR}/inflate.h"
"${ZLIB_SOURCE_DIR}/inftrees.h"
"${ZLIB_SOURCE_DIR}/trees.h"
"${ZLIB_INCLUDE}/zconf.h"
"${ZLIB_INCLUDE}/zlib.h"
"${ZLIB_INCLUDE}/zutil.h"
"${ZLIB_SOURCE_DIR}/zlib.h"
"${ZLIB_SOURCE_DIR}/zutil.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this seems to change the semantic of ZLIB_HEADERS, it does not seem to be a problem,
Would it make sense to rename it to something like _zlib_headers to avoid confusion ? In such case we should apply the same convention to other internal variables for consistency e.g.

  • ZLIB_SOURCE_DIR
  • ZLIB_BUILD_DIR
  • ZLIB_BUILD_TARGET
  • ZLIB_LIBRARY_INSTALL_TYPE
  • ZLIB_BUILD_CONFIG_SUBDIR
  • ZLIB_BUILT_LIB
  • ZLIB_INSTALL_SCRIPT
  • ZLIB_EXTERNAL_PROJECT_CACHE_ARGS
  • ZLIB_IS_MULTI_CONFIG

I don't consider this as a blocker for this PR though.

@mvanhorn

Copy link
Copy Markdown
Author

Addressed both points in ca60fa1: the external zlib build now passes --config $<CONFIG> only when GENERATOR_IS_MULTI_CONFIG is set (single-config generators get no bare --config), and the internal helper variables are renamed to the _zlib_* convention as suggested. Verified the single/multi-config build graph generation and ran cmake-format 0.6.13 with the repo config.

Comment thread cmake/modules/zlib.cmake
set(ZLIB_SRC "${PROJECT_BINARY_DIR}/zlib-prefix/src/zlib")
set(ZLIB_INCLUDE "${ZLIB_SRC}")
set(ZLIB_HEADERS "")
set(ZLIB_SRC "${PROJECT_BINARY_DIR}/zlib-prefix/src")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligning ZLIB_SRC with the jsoncpp convention SGTM. However, ZLIB_SRC is not private to this module, so re-pointing it has two side effects.

First, cmake/modules/libbpf.cmake:71 passes -L${ZLIB_SRC} to libbpf's make. That directory used to hold libz.a directly, now the library lives in ${ZLIB_SRC}/lib, so the flag points at a dir with no zlib in it. It is inert atm, since EXTRA_LDFLAGS only feeds the shared-object link rule that libbpf skips under BUILD_STATIC_ONLY=y. Still, may you fix it to -L${ZLIB_SRC}/lib here, before it bites us later? 🙏

Second, Falco reuses this very module and passes --with-zlib=${ZLIB_SRC} in its own cmake/modules/curl.cmake. curl's configure expands that to -I$OPT_ZLIB/include -L$OPT_ZLIB/lib 👉 https://github.com/curl/curl/blob/curl-8_7_1/configure.ac#L1320-L1322

Pre-PR neither of those dirs existed (the old build was in-source with INSTALL_COMMAND ""), so Falco's bundled curl was silently falling back to the system zlib. With this PR both exist, so curl will finally pick the bundled one. That is a fix rather than a regression, but it is still a behavior change downstream, so I'd prefer to see a Falco build green before we merge this.

Comment thread cmake/modules/zlib.cmake
ExternalProject_Add(
zlib
PREFIX "${PROJECT_BINARY_DIR}/zlib-prefix"
SOURCE_DIR "${_zlib_source_dir}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SOURCE_DIR "${_zlib_source_dir}"
SOURCE_DIR "${_zlib_source_dir}"
BINARY_DIR "${_zlib_build_dir}"

Nit. _zlib_build_dir (line 69) hardcodes ExternalProject's default binary dir, and the install script turns any mismatch into a FATAL_ERROR. Declaring BINARY_DIR explicitly drops that implicit coupling, and it is what re2.cmake already does.

Also, the file(MAKE_DIRECTORY ...) at line 83 can go, since file(WRITE ...) creates the parent dirs on its own.

Comment thread cmake/modules/zlib.cmake Outdated
Comment on lines +122 to +123
-DCMAKE_INSTALL_PREFIX=${ZLIB_SRC}
-DCMAKE_INSTALL_LIBDIR=lib

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-DCMAKE_INSTALL_PREFIX=${ZLIB_SRC}
-DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_INSTALL_PREFIX=${ZLIB_SRC}

Nit. zlib 1.3.1 does not use GNUInstallDirs, it hardcodes INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib", so CMAKE_INSTALL_LIBDIR is ignored and every configure of the sub-build warns about it:

CMake Warning (unused-cli):
  Manually-specified variables were not used by the project:

    CMAKE_INSTALL_LIBDIR

The layout is already lib/, so dropping it changes nothing. Same for line 172 in the Windows branch.

@poiana

poiana commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mvanhorn
Once this PR has been reviewed and has the lgtm label, please assign mstemm for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mvanhorn

mvanhorn commented Aug 2, 2026

Copy link
Copy Markdown
Author

All three applied in f0ed401.

BINARY_DIR is now declared explicitly, so the implicit coupling to _zlib_build_dir is gone, and the file(MAKE_DIRECTORY) above it is removed — I checked with a fresh configure from an empty build dir that file(WRITE ...) does create zlib-prefix/src itself.

Dropped CMAKE_INSTALL_LIBDIR from both the non-Windows and Windows argument lists, keeping -DCMAKE_INSTALL_PREFIX=${ZLIB_SRC}. The installed layout stays ${ZLIB_SRC}/lib either way, since that is what zlib 1.3.1 derives from the prefix.

libbpf.cmake now passes -L${ZLIB_SRC}/lib. I grepped ZLIB_SRC across the tree for other consumers of the old flat layout and found none — the remaining link sites go through ZLIB_LIB, which already points under ${ZLIB_SRC}/lib.

On your downstream point: I can't produce a green Falco build from here. Agreed it should gate the merge given curl will now pick up the bundled zlib where it previously fell back to the system one. Happy to open the Falco-side PR to test it if that's useful, or leave it to you.

@poiana poiana added size/L and removed size/XXL labels Aug 2, 2026
mvanhorn and others added 3 commits August 2, 2026 08:56
…alcosecurity#2584)

zlib v1.3.1 ships a first-class CMakeLists.txt, so build the bundled
dependency on non-Windows with its own CMake build (via CMAKE_ARGS and the
shared falcosecurity_external_project_cache_args toolchain mechanism) instead
of invoking the hand-written ./configure script through CONFIGURE_COMMAND.

Only the library type actually consumed is built (zlibstatic for static,
zlib for shared), preserving the previous './configure --static' behavior and
keeping static-only / cross toolchains working. The install step is
config-aware (handles multi-config generators) and preserves the shared
library SOVERSION symlink chain. ZLIB_INCLUDE / ZLIB_LIB / ZLIB_HEADERS are
unchanged for downstream consumers.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
(cherry picked from commit 3cc133a)
Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
…internal vars

Per review from @irozzo-1A: pass --config $<CONFIG> to the external zlib build only on multi-config generators (a single-config generator would expand to a bare --config and break the build), and rename the internal helper variables to the _zlib_* convention to avoid clashing with the public ZLIB_* cache variables.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
(cherry picked from commit dc1e7d9)
Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
…, fix libbpf -L path

Per review:
- Declare BINARY_DIR explicitly so ExternalProject's default is no longer
  implicitly coupled to _zlib_build_dir, and drop the now-redundant
  file(MAKE_DIRECTORY): file(WRITE ...) creates its parent dirs.
- zlib 1.3.1 hardcodes INSTALL_LIB_DIR from CMAKE_INSTALL_PREFIX and ignores
  GNUInstallDirs, so CMAKE_INSTALL_LIBDIR was unused and warned on every
  sub-build configure.
- libbpf's EXTRA_LDFLAGS pointed at ${ZLIB_SRC}, which no longer holds libz.a
  now that the build installs under ${ZLIB_SRC}/lib.

Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
(cherry picked from commit deaaba6)
Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
Comment thread cmake/modules/libbpf.cmake Outdated
Comment on lines 71 to 72
"LDFLAGS=-Wl,-Bstatic" "EXTRA_LDFLAGS=-L${LIBELF_SRC}/libelf/libelf -L${ZLIB_SRC}/lib" -C
${LIBBPF_SRC}/libbpf/src install install_uapi_headers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"LDFLAGS=-Wl,-Bstatic" "EXTRA_LDFLAGS=-L${LIBELF_SRC}/libelf/libelf -L${ZLIB_SRC}/lib" -C
${LIBBPF_SRC}/libbpf/src install install_uapi_headers
"LDFLAGS=-Wl,-Bstatic" "EXTRA_LDFLAGS=-L${LIBELF_SRC}/libelf/libelf -L${ZLIB_SRC}/lib"
-C ${LIBBPF_SRC}/libbpf/src install install_uapi_headers

This is what format code is failing on. Adding /lib took the line to 101 columns, one over the line_width: 100 in .cmake-format.json, so cmake-format wants -C wrapped down.

May you run cmake-format -i cmake/modules/libbpf.cmake (0.6.13, with the repo config) just to be safe? The patch is downloadable from the failing job too 👉 https://github.com/falcosecurity/libs/actions/runs/30755533927

Thanks 🙏

Adding the /lib suffix pushed the EXTRA_LDFLAGS line to 101 columns, one
over line_width in .cmake-format.json, so cmake-format 0.6.13 wraps -C
down. Both file(INSTALL DESTINATION ...) calls create their own
destination, so the MAKE_DIRECTORY ahead of them is redundant.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn

mvanhorn commented Aug 7, 2026

Copy link
Copy Markdown
Author

Thanks for the thorough pass, and for pinpointing the format failure.

  • libbpf.cmake: ran cmake-format -i with 0.6.13 and the repo config. Output matches your suggestion exactly, and --check is clean on both files now.
  • Dropped the file(MAKE_DIRECTORY ...). You're right that it is redundant, though for a slightly different reason than stated: both directories are file(INSTALL DESTINATION ...) targets further down, and file(INSTALL) creates its destination.
  • The --config $<CONFIG> gating, the _zlib_* renames, BINARY_DIR, and dropping CMAKE_INSTALL_LIBDIR all landed in c669940 and f5ddc15, which is why those threads show as outdated.

On the Falco side effect: agreed that curl picking up the bundled zlib rather than silently falling back to the system one is the point, but it is still a downstream behaviour change. I cannot run a Falco build myself, so I will leave that gate to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

(cmake) zlib bundled dep should use zlib cmake directly instead of CONFIGURE_COMMAND

5 participants