Skip to content

build: add generic Zig cross-compilation toolchain and refactor external project support#2974

Open
irozzo-1A wants to merge 1 commit intofalcosecurity:masterfrom
irozzo-1A:build/zig-toolchain
Open

build: add generic Zig cross-compilation toolchain and refactor external project support#2974
irozzo-1A wants to merge 1 commit intofalcosecurity:masterfrom
irozzo-1A:build/zig-toolchain

Conversation

@irozzo-1A
Copy link
Copy Markdown
Contributor

@irozzo-1A irozzo-1A commented Apr 28, 2026

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind test

/kind feature

/kind sync

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-modern-bpf

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

Introduce cmake/toolchains/zig.cmake, a generic Zig toolchain file that derives CMAKE_SYSTEM_PROCESSOR from the ZIG_TARGET env var and locates the zig executable via ZIG env var, CMAKE_C_COMPILER fallback, or PATH.

Refactor ExternalProjectToolchain.cmake to correctly propagate compiler subcommands (CMAKE_*_COMPILER_ARG1), target flags, and multi-tool archivers (via ENV{AR}/ENV{RANLIB}) to autotools-based external projects. Add FALCOSECURITY_AUTOTOOLS_HOST_FLAG for cross-compilation --host support.

Update install-zig action to export ZIG, ZIG_TARGET, and ZIG_TOOLCHAIN_FILE instead of wrapper scripts. Update CI to use -DCMAKE_TOOLCHAIN_FILE.

Additional fixes for glibc 2.17 compatibility:

  • Add gettid() fallback in libpman for glibc < 2.30
  • Propagate toolchain CFLAGS into zlib's configure
  • Use falcosecurity_external_project_cache_args in fmt

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

Perf diff from master - unit tests

    10.91%     +0.91%  [.] sinsp_threadinfo::get_main_thread()
    13.52%     +0.69%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
     7.87%     +0.62%  [.] sinsp_threadinfo::get_fd_table()
     7.15%     -0.57%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
     5.16%     -0.48%  [.] thread_group_info::get_first_thread() const
     0.50%     -0.27%  [.] scap_event_encode_params_v
     9.73%     -0.26%  [.] sinsp_threadinfo::update_main_fdtable()
    16.03%     -0.25%  [.] 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)
     9.73%     -0.21%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
     9.89%     -0.18%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()

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.0565         +0.0567           233           246           233           246
BM_sinsp_split_median                                                        +0.0605         +0.0605           233           247           233           247
BM_sinsp_split_stddev                                                        +1.4642         +1.4993             2             5             2             5
BM_sinsp_split_cv                                                            +1.3323         +1.3652             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                                -0.0056         -0.0057            72            71            72            71
BM_sinsp_concatenate_paths_relative_path_median                              -0.0243         -0.0241            72            70            72            70
BM_sinsp_concatenate_paths_relative_path_stddev                              +1.5623         +1.5647             1             2             1             2
BM_sinsp_concatenate_paths_relative_path_cv                                  +1.5768         +1.5793             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                                   +0.0049         +0.0050            42            42            42            42
BM_sinsp_concatenate_paths_empty_path_median                                 +0.0003         +0.0005            42            42            42            42
BM_sinsp_concatenate_paths_empty_path_stddev                                 -0.5558         -0.5577             1             0             1             0
BM_sinsp_concatenate_paths_empty_path_cv                                     -0.5579         -0.5599             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                                +0.0242         +0.0243            72            74            72            73
BM_sinsp_concatenate_paths_absolute_path_median                              +0.0215         +0.0216            72            73            72            73
BM_sinsp_concatenate_paths_absolute_path_stddev                              +2.2262         +2.2615             0             1             0             1
BM_sinsp_concatenate_paths_absolute_path_cv                                  +2.1500         +2.1842             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_mean                          +0.0008         +0.0008            18            18            18            18
BM_sinsp_sanitize_string_fast_path_ascii_short_median                        +0.0010         +0.0010            18            18            18            18
BM_sinsp_sanitize_string_fast_path_ascii_short_stddev                        -0.7348         -0.7428             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_cv                            -0.7350         -0.7430             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_mean                           -0.0131         -0.0130           167           165           167           164
BM_sinsp_sanitize_string_fast_path_ascii_long_median                         -0.0002         -0.0002           165           164           164           164
BM_sinsp_sanitize_string_fast_path_ascii_long_stddev                         -0.9799         -0.9803             9             0             9             0
BM_sinsp_sanitize_string_fast_path_ascii_long_cv                             -0.9796         -0.9800             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_mean                      +0.0003         +0.0002            14            14            14            14
BM_sinsp_sanitize_string_fast_path_multibyte_short_median                    +0.0002         +0.0000            14            14            14            14
BM_sinsp_sanitize_string_fast_path_multibyte_short_stddev                    -0.4484         -0.6292             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_cv                        -0.4485         -0.6293             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_long_mean                       -0.0007         -0.0008          4866          4863          4865          4861
BM_sinsp_sanitize_string_fast_path_multibyte_long_median                     -0.0006         -0.0007          4865          4862          4864          4860
BM_sinsp_sanitize_string_fast_path_multibyte_long_stddev                     -0.3681         -0.4682             3             2             3             2
BM_sinsp_sanitize_string_fast_path_multibyte_long_cv                         -0.3677         -0.4678             0             0             0             0
BM_sinsp_sanitize_string_fast_path_mixed_long_mean                           +0.0352         +0.0352          1982          2052          1982          2051
BM_sinsp_sanitize_string_fast_path_mixed_long_median                         +0.0475         +0.0475          1965          2058          1964          2057
BM_sinsp_sanitize_string_fast_path_mixed_long_stddev                         -0.6730         -0.6727            49            16            49            16
BM_sinsp_sanitize_string_fast_path_mixed_long_cv                             -0.6841         -0.6838             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_mean                     +0.0447         +0.0446          6638          6934          6640          6936
BM_sinsp_sanitize_string_slow_path_c1_controls_long_median                   +0.0049         +0.0046          6847          6881          6849          6881
BM_sinsp_sanitize_string_slow_path_c1_controls_long_stddev                   -0.6109         -0.6112           288           112           288           112
BM_sinsp_sanitize_string_slow_path_c1_controls_long_cv                       -0.6275         -0.6279             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_mean                  -0.0119         -0.0135          1096          1083          1103          1088
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_median                -0.0141         -0.0145          1099          1083          1105          1089
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_stddev                -0.2038         -0.2241            11             9            12             9
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_cv                    -0.1942         -0.2135             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_mean                     +0.0077         +0.0075         13312         13414         13313         13413
BM_sinsp_sanitize_string_slow_path_all_invalid_long_median                   +0.0008         +0.0006         13415         13426         13416         13423
BM_sinsp_sanitize_string_slow_path_all_invalid_long_stddev                   -0.8893         -0.8919           211            23           213            23
BM_sinsp_sanitize_string_slow_path_all_invalid_long_cv                       -0.8902         -0.8927             0             0             0             0

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.16%. Comparing base (408105b) to head (f3888e2).
⚠️ Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2974      +/-   ##
==========================================
+ Coverage   75.00%   75.16%   +0.16%     
==========================================
  Files         297      297              
  Lines       31912    32284     +372     
  Branches     5059     5107      +48     
==========================================
+ Hits        23936    24267     +331     
- Misses       7976     8017      +41     
Flag Coverage Δ
libsinsp 75.16% <ø> (+0.16%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

…nal project support

Introduce cmake/toolchains/zig.cmake, a generic Zig toolchain file that
derives CMAKE_SYSTEM_PROCESSOR from the ZIG_TARGET env var and locates
the zig executable via ZIG env var, CMAKE_C_COMPILER fallback, or PATH.

Refactor ExternalProjectToolchain.cmake to correctly propagate compiler
subcommands (CMAKE_*_COMPILER_ARG1), target flags, and multi-tool
archivers (via ENV{AR}/ENV{RANLIB}) to autotools-based external projects.
Add FALCOSECURITY_AUTOTOOLS_HOST_FLAG for cross-compilation --host support.

Update install-zig action to export ZIG, ZIG_TARGET, and
ZIG_TOOLCHAIN_FILE instead of wrapper scripts. Update CI to use
-DCMAKE_TOOLCHAIN_FILE.

Additional fixes for glibc 2.17 compatibility:
- Add gettid() fallback in libpman for glibc < 2.30
- Propagate toolchain CFLAGS into zlib's configure
- Use falcosecurity_external_project_cache_args in fmt

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
@irozzo-1A irozzo-1A force-pushed the build/zig-toolchain branch from 765e6d7 to f3888e2 Compare April 29, 2026 20:17
@irozzo-1A irozzo-1A added this to the 0.26.0 milestone Apr 30, 2026
@irozzo-1A irozzo-1A marked this pull request as ready for review April 30, 2026 07:17
Copy link
Copy Markdown
Contributor

@ekoops ekoops left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Copy Markdown
Contributor

poiana commented Apr 30, 2026

LGTM label has been added.

DetailsGit tree hash: 31710b15aacbd77788a6b9812ffb57b03c8d8111

@ekoops ekoops modified the milestones: 0.26.0, 0.25.0 Apr 30, 2026
@poiana
Copy link
Copy Markdown
Contributor

poiana commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops, irozzo-1A

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

The pull request process is described 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

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.

3 participants