From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793392049; b=L114QLx4YPTtitkJFOtK8eTCs3qJWxRZKPpc4IgzBTFlZeQwWB1cPpgGsAF6/LkHzsN9 2sobrRJoz6Dh0wLok+4PvIQE0qoW5xMSKIpe8TnWdD43fo+7BjHUMSSUqy7bbSbpSHv1x dRLOBQHjbAzzu5wKrOO2GcaAwpt8upvoXJL8o285+W7BjTFqQMhGUbvkNO4Kf3dfYfEDo HGPl2+n6QonQPiKy4JXXhrcbXqwYQD6uBAsQqZBdewluiCYBV6eqkJTArfZspXDt0KD9V WMs7C+TztktIurlp3gQfd4WfwKYcz9BJeDnlkWSR41/5TCpoRxYz1ttDSCYpJI/hECQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793392049; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=5lyHfD9gDVe46qmCqsjdgsoBvqJkPXERQXV0cBBlSa4=; b=2wCnjk3g1LsMMTW82tTJLrDjjM+IW7f4IUVjX3NulH4/hxl2INKPJ0MUJHvgXV400K0j dpuA/Y3wYFtWADlVbgTR3xqNSSBvAcohmVXqeCg5MebZsP5jC1FDEmXADZRfI1t/wMOQO bESWs8Ois93G5iD649Kh9aRUwVIL5MFr7xibtad+LTZg4f+DpxpD8500anqDXOBtd1uV2 oVTZHUSEjIG4m6cKsWBZ/lPJJDsp7r3p8aCQeN0Cm31I3jk8CBxB+gf+1JfBvfz4F8AuY etV8+kV7En2xK6x8U05IpbHj7eghf95EP24K/ADeLko9k30vrHdLJGpnKkoMBjIeWYQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="F5F/X96P"; arc=none smtp.remote-ip=74.125.82.199 Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33285606A31C for ; Fri, 30 Oct 2026 20:27:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33285606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=F5F/X96P Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-36a3451ea93so1731101eec.1 for ; Fri, 30 Oct 2026 13:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793392047; x=1793996847; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5lyHfD9gDVe46qmCqsjdgsoBvqJkPXERQXV0cBBlSa4=; b=F5F/X96P1iqUjyleF+j+g+WMxCXe8TUdoAZ9XNl+xhg6eBka4wv1Je+Fp8Acg1oyi0 pcRS08rsh5H8DOB4G0zbvClmRh6T3oKDS5qXv1tMV6k1Nwf9AdWosKfnO4cq9esqjjp/ iroU6gt2PY/vbz4JDwzwzQwy7ZdLQVw+IYMILW+FWPvHx1wd8yFWV7rCERIPgfexW7dF gzxLi7Dz7rAJwAkUvRQNLbUP9LPN4mdgOMJxJSDpj/bQEMaDxf/U/pNy5eOyJ2XBYkXi ICBIwL9mst9ncb13ysGM6hO1jj2up3SkvMxRqkYBqhQYxF5ysalWZ6MHNZDB+eBgoi05 FvUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793392047; x=1793996847; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5lyHfD9gDVe46qmCqsjdgsoBvqJkPXERQXV0cBBlSa4=; b=GRTkWM76+K5VwYUzPkFEMl7rhNi2KVhbftjYoPjEmoAiAbSbdE8OwkLIjWpf5lo+6l YFnZyN6wf7d24tiRxsVjWdLswtY17TMbJXv1RG2tzePOo8UxK3bIXdoprXxviLTJbsaH 33JcIWA8sfA3TIb5qeg/Q49Pwvi0bbHfK/QjS1c9xKV/1ah2ZhX9Xhz3oTprXvR+JQs6 U4kdy+Ojc9OL5YismV8jcsIKTom4ExVFmeYUH1/Y+yYePmv0mdx+eSFXmMv3mJeTeZ8j 4KfOwZMWpDqEr48qFmOQC6bpcNwpAKy/m7Ixui1Mw1uQYTUr3sZaFV8tTE3KgLJvvZOH S9Hg== X-Forwarded-Encrypted: i=1; AKwUvBwzCTbZl2tIPW0XJrLOH0SsJPuVlL839rJgGbBElCE8iOe4gCCEAyyi6G9L7hNKR/YAfGQNaThB/ZNWTTBjIlHM@vger.kernel.org X-Gm-Message-State: AFq9FYIl8nAiB9m3MkyxIDHRiwtHyzSEvzMzthS0YafYBevuOWeC7qKY bkDTo4FqWyyJWrpB2/l69c3jxCbJRN5Vun+ObLHVqe2gEb4Ji22EMdVxKZG7nVDlNl1aVSDPpei s77dV2PwVpg== X-Received: from dlbtp7.prod.google.com ([2002:a05:7022:3b87:b0:15f:5ef4:b896]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:1602:b0:1a8:4997:65f6 with SMTP id a92af1059eb24-1ac5d88c579mr6176377c88.20.1793392046539; Fri, 30 Oct 2026 13:27:26 -0700 (PDT) Date: Fri, 30 Oct 2026 13:27:07 -0700 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.0.317.g454f8302e1-goog Message-ID: <20261030202710.3863806-1-irogers@google.com> Subject: [RFC PATCH v2 0/3] tools: Add Rust library build infrastructure and prefer zlib-rs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Ian Rogers , Adrian Hunter , Quentin Monnet , Miguel Ojeda , Nathan Chancellor , Nicolas Schier Cc: Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Nick Desaulniers , Bill Wendling , Justin Stitt , 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 Content-Type: text/plain; charset="UTF-8" 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_`) 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_` 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