From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Quentin Monnet <qmo@kernel.org>, Miguel Ojeda <ojeda@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>
Cc: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org,
llvm@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 0/3] tools: Add Rust library build infrastructure and prefer zlib-rs
Date: Fri, 30 Oct 2026 13:27:07 -0700 [thread overview]
Message-ID: <20261030202710.3863806-1-irogers@google.com> (raw)
The zlib-rs project (https://github.com/trifectatechfoundation/zlib-rs)
provides a memory-safe, high-performance Rust implementation of the zlib
compression specification along with a C ABI layer (libz-rs-sys) that is a
drop-in replacement for the standard C zlib library. Transitioning
decompression of kernel configuration files (/proc/config.gz), compressed
ELF/BTF sections, and perf data from C zlib to zlib-rs improves both memory
safety and decompression performance.
On many Linux distributions (such as Debian, Ubuntu, and Fedora), Rust
crates like zlib-rs and libz-rs-sys are packaged as Cargo registry sources
under /usr/share/cargo/registry/ (e.g. librust-libz-rs-sys-dev or
rust-libz-rs-sys-devel) rather than as prebuilt C shared libraries, while
other environments may install prebuilt libz_rs libraries via pkg-config or
a custom prefix (LIBZ_RS_DIR).
This RFC series lays the groundwork for building and linking Rust crate
libraries in tools/ offline from the system Cargo registry and integrates
zlib-rs support into perf and bpftool, preferring zlib-rs over C zlib when
available:
1. **tools build: Add Rust library build infrastructure and zlib-rs feature test**:
- Adds `tools/build/Makefile.rust` with helpers to resolve C compiler and
linker flags for Rust libraries via `%-cflags` and `%-libs` targets.
- Resolves `zlib-rs` compiler and linker flags via `LIBZ_RS_DIR`,
`pkg-config` (`libz-rs-sys-cdylib`, `zlib-rs`, `z_rs`), or building
`libz_rs.a` (with the `export-symbols`, `c-allocator`, `std`, and `gz`
features) into `$(OUTPUT)libz_rs/` from `/usr/share/cargo/registry`
using offline Cargo (`cargo metadata --offline` and
`cargo build --offline`).
- Adds `tools/build/feature/test-zlib-rs.c` checking
`ZLIB_VER_SUBREVISION == 15` (`0xf`, which distinguishes
`libz-rs-sys`'s `zlib.h` from standard C `zlib.h`) and linking against
`inflateInit()`.
- Extends `tools/scripts/Makefile.include` with cross-compilation target
triples (`RUST_TARGET_FLAGS_<arch>`) and the `feature_rust_lib` macro.
2. **perf build: Prefer zlib-rs over zlib when available**:
- Moves Rust detection ahead of zlib detection in
`tools/perf/Makefile.config` and prefers `zlib-rs` over C `zlib` unless
`NO_ZLIB_RS=1` (or `NO_ZLIB=1` / `NO_RUST=1`) is set.
- Defines both `HAVE_ZLIB_SUPPORT` and `HAVE_ZLIB_RS_SUPPORT` when
`zlib-rs` is used so existing zlib call sites in `perf` work unchanged
while `perf version --build-options` and `perf check feature zlib-rs`
report whether `zlib-rs` is active.
- Shares `$(OUTPUT)libz_rs/` with the host bootstrap `bpftool` build in
`tools/perf/bpf_skel.mak` and adds `NO_ZLIB` / `NO_ZLIB_RS` tests to
`tools/perf/tests/make`.
3. **bpftool: Prefer zlib-rs over zlib when available**:
- Adds `zlib-rs` and `zlib` to `FEATURE_TESTS` and `FEATURE_DISPLAY` in
`tools/bpf/bpftool/Makefile` and configures `ZLIB_CFLAGS` and
`ZLIB_LIBS` via `feature_rust_lib` when `zlib-rs` is detected.
Changes in v2:
- Use offline Cargo (`cargo metadata --offline` and `cargo build --offline`
configured against `CARGO_REGISTRY_DIR` = `/usr/share/cargo/registry` and
isolated from `~/.cargo`) to resolve crate versions, dependency graphs,
features, and build scripts instead of manually globbing crate directory
names and invoking `rustc` on hardcoded `.rlib` edges (Miguel Ojeda).
- Avoid including `../../scripts/Makefile.arch` in `tools/bpf/bpftool/Makefile`
(to keep the standalone bpftool mirror self-contained) by placing
`RUST_TARGET_FLAGS_<arch>` in `tools/scripts/Makefile.include`, and expand
the bpftool commit message on the security and performance motivation for
preferring `zlib-rs` (Quentin Monnet).
- Drop unused `.rlib` pattern rules and helpers from `tools/build/Build.include`
and `tools/build/Makefile.build` (Sashiko).
- Address Sashiko review feedback on `PKG_CONFIG` handling when unset or with
`-static`, `test-all.bin` re-checking `zlib-rs` and `rust`, preserving
`EXTRA_CFLAGS` optimization defaults when building `libbpf.a`, and
honoring `NO_ZLIB_RS=1` in `bpftool` when `FEATURES_DUMP` is used.
AI Assistance Disclosure (per Documentation/process/coding-assistants.rst
and Documentation/process/generated-content.rst):
- Tools used: Antigravity coding assistant and Sashiko automated patch
review using Gemini 4 LLMs.
- Summary of prompts and assistance: Interactive pair-programming session to
identify distro packaging for zlib-rs/libz-rs-sys, implement the zlib-rs
feature test and offline Cargo build rules in Makefile.rust, integrate
zlib-rs detection into perf and bpftool, separate Rust library outputs
into $(OUTPUT)libz_rs/, and address reviewer and automated Sashiko
feedback.
- Testing performed: Built and tested perf and bpftool with zlib-rs
(default), NO_ZLIB_RS=1 (fallback to C zlib), NO_ZLIB=1, and MINIMAL=1;
verified `perf version --build-options`, `perf check feature`, and the
`make_no_zlib` / `make_no_zlib_rs` tests in `tools/perf/tests/make`; and
checked all commits with `scripts/checkpatch.pl`.
Ian Rogers (3):
tools build: Add Rust library build infrastructure and zlib-rs feature
test
perf build: Prefer zlib-rs over zlib when available
bpftool: Prefer zlib-rs over zlib when available
tools/bpf/bpftool/.gitignore | 1 +
tools/bpf/bpftool/Makefile | 57 +++++++++-
tools/build/Makefile.feature | 12 +-
tools/build/Makefile.rust | 160 +++++++++++++++++++++++
tools/build/feature/.gitignore | 1 +
tools/build/feature/Makefile | 11 +-
tools/build/feature/test-zlib-rs.c | 19 +++
tools/perf/.gitignore | 1 +
tools/perf/Documentation/perf-check.txt | 1 +
tools/perf/Makefile.config | 88 +++++++------
tools/perf/Makefile.perf | 32 ++++-
tools/perf/bpf_skel.mak | 8 +-
tools/perf/builtin-check.c | 1 +
tools/perf/scripts/install-build-deps.sh | 6 +
tools/perf/tests/make | 9 ++
tools/scripts/Makefile.include | 25 ++++
16 files changed, 382 insertions(+), 50 deletions(-)
create mode 100644 tools/build/Makefile.rust
create mode 100644 tools/build/feature/test-zlib-rs.c
--
2.56.0.317.g454f8302e1-goog
next reply other threads:[~2026-10-30 20:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 20:27 Ian Rogers [this message]
2026-10-30 20:27 ` [RFC PATCH v2 1/3] tools build: Add Rust library build infrastructure and zlib-rs feature test Ian Rogers
2026-10-30 20:44 ` sashiko-bot
2026-10-30 20:27 ` [RFC PATCH v2 2/3] perf build: Prefer zlib-rs over zlib when available Ian Rogers
2026-10-30 20:46 ` sashiko-bot
2026-10-30 20:27 ` [RFC PATCH v2 3/3] bpftool: " Ian Rogers
2026-10-30 20:39 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261030202710.3863806-1-irogers@google.com \
--to=irogers@google.com \
--cc=a.hindborg@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=jolsa@kernel.org \
--cc=justinstitt@google.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=lossin@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=qmo@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox