add a build command (#108)
Add a new command to build ebpf and userspace programs without running. ``` cargo xtask build ``` Co-authored-by: Michal Rostecki <vadorovsky@protonmail.com>pull/104/head
parent
f642921fee
commit
7c143de8af
@ -0,0 +1,42 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
use anyhow::Context as _;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::build_ebpf::{build_ebpf, Architecture, Options as BuildOptions};
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct Options {
|
||||||
|
/// Set the endianness of the BPF target
|
||||||
|
#[clap(default_value = "bpfel-unknown-none", long)]
|
||||||
|
pub bpf_target: Architecture,
|
||||||
|
/// Build and run the release target
|
||||||
|
#[clap(long)]
|
||||||
|
pub release: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build the project
|
||||||
|
fn build_project(opts: &Options) -> Result<(), anyhow::Error> {
|
||||||
|
let mut args = vec!["build"];
|
||||||
|
if opts.release {
|
||||||
|
args.push("--release")
|
||||||
|
}
|
||||||
|
let status = Command::new("cargo")
|
||||||
|
.args(&args)
|
||||||
|
.status()
|
||||||
|
.expect("failed to build userspace");
|
||||||
|
assert!(status.success());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build our ebpf program and the project
|
||||||
|
pub fn build(opts: Options) -> Result<(), anyhow::Error> {
|
||||||
|
// build our ebpf program followed by our application
|
||||||
|
build_ebpf(BuildOptions {
|
||||||
|
target: opts.bpf_target,
|
||||||
|
release: opts.release,
|
||||||
|
})
|
||||||
|
.context("Error while building eBPF program")?;
|
||||||
|
build_project(&opts).context("Error while building userspace application")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue