Skip to content

Commit 17573e0

Browse files
timwoockertamird
authored andcommitted
aya-build: plumb features of ebpf crates
This allows callers to select features of the ebpf crate.
1 parent 948b855 commit 17573e0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

aya-build/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ use std::{
1111
use anyhow::{Context as _, Result, anyhow};
1212
use cargo_metadata::{Artifact, CompilerMessage, Message, Target};
1313

14+
#[derive(Default)]
1415
pub struct Package<'a> {
1516
pub name: &'a str,
1617
pub root_dir: &'a str,
18+
pub no_default_features: bool,
19+
pub features: &'a [&'a str],
1720
}
1821

1922
fn target_arch_fixup(target_arch: Cow<'_, str>) -> Cow<'_, str> {
@@ -62,7 +65,13 @@ pub fn build_ebpf<'a>(
6265
let bpf_target_arch = target_arch_fixup(bpf_target_arch.into());
6366
let target = format!("{target}-unknown-none");
6467

65-
for Package { name, root_dir } in packages {
68+
for Package {
69+
name,
70+
root_dir,
71+
no_default_features,
72+
features,
73+
} in packages
74+
{
6675
// We have a build-dependency on `name`, so cargo will automatically rebuild us if `name`'s
6776
// *library* target or any of its dependencies change. Since we depend on `name`'s *binary*
6877
// 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>(
8594
"--target",
8695
&target,
8796
]);
97+
if no_default_features {
98+
cmd.arg("--no-default-features");
99+
}
100+
cmd.args(["--features", &features.join(",")]);
88101

89102
{
90103
const SEPARATOR: &str = "\x1f";

test/integration-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ fn main() -> Result<()> {
219219
.parent()
220220
.ok_or_else(|| anyhow!("no parent for {manifest_path}"))?
221221
.as_str(),
222+
..Default::default()
222223
};
223224
aya_build::build_ebpf([integration_ebpf_package], aya_build::Toolchain::default())?;
224225
} else {

xtask/public-api/aya-build.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ pub fn aya_build::Toolchain<'a>::borrow_mut(&mut self) -> &mut T
2727
impl<T> core::convert::From<T> for aya_build::Toolchain<'a>
2828
pub fn aya_build::Toolchain<'a>::from(t: T) -> T
2929
pub struct aya_build::Package<'a>
30+
pub aya_build::Package::features: &'a [&'a str]
3031
pub aya_build::Package::name: &'a str
32+
pub aya_build::Package::no_default_features: bool
3133
pub aya_build::Package::root_dir: &'a str
34+
impl<'a> core::default::Default for aya_build::Package<'a>
35+
pub fn aya_build::Package<'a>::default() -> aya_build::Package<'a>
3236
impl<'a> core::marker::Freeze for aya_build::Package<'a>
3337
impl<'a> core::marker::Send for aya_build::Package<'a>
3438
impl<'a> core::marker::Sync for aya_build::Package<'a>

0 commit comments

Comments
 (0)