From 17573e0e47fd53c24097a1f92b3e0ecf66a298d4 Mon Sep 17 00:00:00 2001 From: Tim W Date: Sun, 2 Nov 2025 20:49:17 +0100 Subject: [PATCH] aya-build: plumb features of ebpf crates This allows callers to select features of the ebpf crate. --- aya-build/src/lib.rs | 15 ++++++++++++++- test/integration-test/build.rs | 1 + xtask/public-api/aya-build.txt | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/aya-build/src/lib.rs b/aya-build/src/lib.rs index 7820a781..4caf28a6 100644 --- a/aya-build/src/lib.rs +++ b/aya-build/src/lib.rs @@ -11,9 +11,12 @@ use std::{ use anyhow::{Context as _, Result, anyhow}; use cargo_metadata::{Artifact, CompilerMessage, Message, Target}; +#[derive(Default)] pub struct Package<'a> { pub name: &'a str, pub root_dir: &'a str, + pub no_default_features: bool, + pub features: &'a [&'a str], } fn target_arch_fixup(target_arch: Cow<'_, str>) -> Cow<'_, str> { @@ -62,7 +65,13 @@ pub fn build_ebpf<'a>( let bpf_target_arch = target_arch_fixup(bpf_target_arch.into()); let target = format!("{target}-unknown-none"); - for Package { name, root_dir } in packages { + for Package { + name, + root_dir, + no_default_features, + features, + } in packages + { // We have a build-dependency on `name`, so cargo will automatically rebuild us if `name`'s // *library* target or any of its dependencies change. Since we depend on `name`'s *binary* // targets, that only gets us half of the way. This stanza ensures cargo will rebuild us on @@ -85,6 +94,10 @@ pub fn build_ebpf<'a>( "--target", &target, ]); + if no_default_features { + cmd.arg("--no-default-features"); + } + cmd.args(["--features", &features.join(",")]); { const SEPARATOR: &str = "\x1f"; diff --git a/test/integration-test/build.rs b/test/integration-test/build.rs index 44a4783a..881cdd57 100644 --- a/test/integration-test/build.rs +++ b/test/integration-test/build.rs @@ -219,6 +219,7 @@ fn main() -> Result<()> { .parent() .ok_or_else(|| anyhow!("no parent for {manifest_path}"))? .as_str(), + ..Default::default() }; aya_build::build_ebpf([integration_ebpf_package], aya_build::Toolchain::default())?; } else { diff --git a/xtask/public-api/aya-build.txt b/xtask/public-api/aya-build.txt index a9fe663c..a5af3847 100644 --- a/xtask/public-api/aya-build.txt +++ b/xtask/public-api/aya-build.txt @@ -27,8 +27,12 @@ pub fn aya_build::Toolchain<'a>::borrow_mut(&mut self) -> &mut T impl core::convert::From for aya_build::Toolchain<'a> pub fn aya_build::Toolchain<'a>::from(t: T) -> T pub struct aya_build::Package<'a> +pub aya_build::Package::features: &'a [&'a str] pub aya_build::Package::name: &'a str +pub aya_build::Package::no_default_features: bool pub aya_build::Package::root_dir: &'a str +impl<'a> core::default::Default for aya_build::Package<'a> +pub fn aya_build::Package<'a>::default() -> aya_build::Package<'a> impl<'a> core::marker::Freeze for aya_build::Package<'a> impl<'a> core::marker::Send for aya_build::Package<'a> impl<'a> core::marker::Sync for aya_build::Package<'a>