-
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathbuild.rs
More file actions
35 lines (32 loc) · 1.11 KB
/
build.rs
File metadata and controls
35 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#[cfg(target_os = "linux")]
use anyhow::{Context as _, anyhow};
#[cfg(target_os = "linux")]
use aya_build::Toolchain;
#[cfg(not(target_os = "linux"))]
fn main() {}
/// Based on https://github.com/aya-rs/aya-template/blob/main/%7B%7Bproject-name%7D%7D/build.rs
#[cfg(target_os = "linux")]
fn main() -> anyhow::Result<()> {
let cargo_metadata::Metadata { packages, .. } = cargo_metadata::MetadataCommand::new()
.no_deps()
.exec()
.context("MetadataCommand::exec")?;
let ebpf_package = packages
.into_iter()
.find(|cargo_metadata::Package { name, .. }| *name == "mitmproxy-linux-ebpf")
.ok_or_else(|| anyhow!("mitmproxy-linux-ebpf package not found"))?;
let cargo_metadata::Package {
name,
manifest_path,
..
} = ebpf_package;
let ebpf_package = aya_build::Package {
name: name.as_str(),
root_dir: manifest_path
.parent()
.ok_or_else(|| anyhow!("no parent for {manifest_path}"))?
.as_str(),
..Default::default()
};
aya_build::build_ebpf([ebpf_package], Toolchain::default())
}