aya-build: plumb features of ebpf crates

This allows callers to select features of the ebpf crate.
create-pull-request/codegen
Tim W 2 days ago committed by Tamir Duberstein
parent 948b8553ee
commit 17573e0e47

@ -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";

@ -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 {

@ -27,8 +27,12 @@ pub fn aya_build::Toolchain<'a>::borrow_mut(&mut self) -> &mut T
impl<T> core::convert::From<T> 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>

Loading…
Cancel
Save