mirror of https://github.com/aya-rs/aya
xtask: inline build_ebpf
parent
8c61fc9ea6
commit
bc9f059d53
@ -1,56 +0,0 @@
|
|||||||
use std::{path::PathBuf, process::Command};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
use crate::utils::{exec, workspace_root};
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub enum Architecture {
|
|
||||||
BpfEl,
|
|
||||||
BpfEb,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::str::FromStr for Architecture {
|
|
||||||
type Err = &'static str;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
Ok(match s {
|
|
||||||
"bpfel-unknown-none" => Architecture::BpfEl,
|
|
||||||
"bpfeb-unknown-none" => Architecture::BpfEb,
|
|
||||||
_ => return Err("invalid target"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for Architecture {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.write_str(match self {
|
|
||||||
Architecture::BpfEl => "bpfel-unknown-none",
|
|
||||||
Architecture::BpfEb => "bpfeb-unknown-none",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct BuildEbpfOptions {
|
|
||||||
/// Set the endianness of the BPF target
|
|
||||||
#[clap(default_value = "bpfel-unknown-none", long)]
|
|
||||||
pub target: Architecture,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_ebpf(opts: BuildEbpfOptions) -> Result<()> {
|
|
||||||
let BuildEbpfOptions { target } = opts;
|
|
||||||
|
|
||||||
let mut dir = PathBuf::from(workspace_root());
|
|
||||||
dir.push("test/integration-ebpf");
|
|
||||||
|
|
||||||
exec(
|
|
||||||
Command::new("cargo")
|
|
||||||
.current_dir(&dir)
|
|
||||||
.args(["+nightly", "build", "--release", "--target"])
|
|
||||||
.arg(target.to_string())
|
|
||||||
.args(["-Z", "build-std=core"])
|
|
||||||
.current_dir(&dir),
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
use std::{cell::OnceCell, process::Command};
|
|
||||||
|
|
||||||
use anyhow::{bail, Context as _, Result};
|
|
||||||
|
|
||||||
pub fn workspace_root() -> &'static str {
|
|
||||||
static mut WORKSPACE_ROOT: OnceCell<String> = OnceCell::new();
|
|
||||||
unsafe { &mut WORKSPACE_ROOT }.get_or_init(|| {
|
|
||||||
let cmd = cargo_metadata::MetadataCommand::new();
|
|
||||||
cmd.exec().unwrap().workspace_root.to_string()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn exec(cmd: &mut Command) -> Result<()> {
|
|
||||||
let status = cmd
|
|
||||||
.status()
|
|
||||||
.with_context(|| format!("failed to run {cmd:?}"))?;
|
|
||||||
match status.code() {
|
|
||||||
Some(code) => match code {
|
|
||||||
0 => Ok(()),
|
|
||||||
code => bail!("{cmd:?} exited with code {code}"),
|
|
||||||
},
|
|
||||||
None => bail!("{cmd:?} terminated by signal"),
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue