From c8e9037ca65410e0f4d71f2b83b5363e36d4449e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 15 May 2025 12:54:27 -0400 Subject: [PATCH] Avoid uncontrolled stdout into cargo This fixes rebuild on change of C sources by black-holing: - Output of `make` (harmless). - Output of `llmv-objcopy` (harmful: binary data). --- test/integration-test/build.rs | 9 ++++++--- xtask/src/codegen/aya_ebpf_bindings.rs | 5 +++-- xtask/src/lib.rs | 21 +++++++++------------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/test/integration-test/build.rs b/test/integration-test/build.rs index 47bfce48..a9a36219 100644 --- a/test/integration-test/build.rs +++ b/test/integration-test/build.rs @@ -8,7 +8,7 @@ use std::{ use anyhow::{Context as _, Ok, Result, anyhow}; use aya_build::cargo_metadata::{Metadata, MetadataCommand, Package, Target, TargetKind}; -use xtask::{AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR, exec, install_libbpf_headers}; +use xtask::{AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR, exec, install_libbpf_headers_cmd}; /// This file, along with the xtask crate, allows analysis tools such as `cargo check`, `cargo /// clippy`, and even `cargo build` to work as users expect. Prior to this file's existence, this @@ -86,7 +86,9 @@ fn main() -> Result<()> { println!("cargo:rerun-if-changed={libbpf_dir}"); let libbpf_headers_dir = out_dir.join("libbpf_headers"); - install_libbpf_headers(&libbpf_dir, &libbpf_headers_dir)?; + let mut cmd = install_libbpf_headers_cmd(&libbpf_dir, &libbpf_headers_dir); + cmd.stdout(Stdio::null()); + exec(&mut cmd)?; let bpf_dir = manifest_dir.join("bpf"); @@ -158,7 +160,8 @@ fn main() -> Result<()> { .arg("--dump-section") .arg(output) .arg("-") - .stdin(stdout), + .stdin(stdout) + .stdout(Stdio::null()), )?; let output = child diff --git a/xtask/src/codegen/aya_ebpf_bindings.rs b/xtask/src/codegen/aya_ebpf_bindings.rs index 702761b3..d9ec9a61 100644 --- a/xtask/src/codegen/aya_ebpf_bindings.rs +++ b/xtask/src/codegen/aya_ebpf_bindings.rs @@ -8,7 +8,7 @@ use aya_tool::bindgen; use proc_macro2::TokenStream; use quote::ToTokens as _; use syn::{Item, parse_str}; -use xtask::install_libbpf_headers; +use xtask::{exec, install_libbpf_headers_cmd}; use crate::codegen::{ Architecture, SysrootOptions, @@ -30,7 +30,8 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> { let tmp_dir = tempfile::tempdir().context("tempdir failed")?; let libbpf_headers_dir = tmp_dir.path().join("libbpf_headers"); - install_libbpf_headers(libbpf_dir, &libbpf_headers_dir)?; + let mut cmd = install_libbpf_headers_cmd(libbpf_dir, &libbpf_headers_dir); + exec(&mut cmd)?; let dir = PathBuf::from("ebpf/aya-ebpf-bindings"); diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 492f211d..9d5a346b 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -15,25 +15,22 @@ pub fn exec(cmd: &mut Command) -> Result<()> { Ok(()) } -/// Installs the libbpf headers files from the `source_dir` to the +/// Returns a [`Command`]` that Installs the libbpf headers files from the `source_dir` to the /// `headers_dir`. -pub fn install_libbpf_headers( +pub fn install_libbpf_headers_cmd( source_dir: impl AsRef, headers_dir: impl AsRef, -) -> Result<()> { +) -> Command { let mut includedir = OsString::new(); includedir.push("INCLUDEDIR="); includedir.push(headers_dir.as_ref().as_os_str()); - exec( - Command::new("make") - .arg("-C") - .arg(source_dir.as_ref().join("src")) - .arg(includedir) - .arg("install_headers"), - )?; - - Ok(()) + let mut cmd = Command::new("make"); + cmd.arg("-C") + .arg(source_dir.as_ref().join("src")) + .arg(includedir) + .arg("install_headers"); + cmd } #[derive(Debug)]