1 use std::process::Command; 2 3 use anyhow::Context as _; 4 use clap::Parser; 5 6 use crate::build_ebpf::{build_ebpf, Architecture, Options as BuildOptions}; 7 8 #[derive(Debug, Parser)] 9 pub struct Options { 10 /// Set the endianness of the BPF target 11 #[clap(default_value = "bpfel-unknown-none", long)] 12 pub bpf_target: Architecture, 13 /// Build and run the release target 14 #[clap(long)] 15 pub release: bool, 16 } 17 18 /// Build the project 19 fn build_project(opts: &Options) -> Result<(), anyhow::Error> { 20 let mut args = vec!["build"]; 21 if opts.release { 22 args.push("--release") 23 } 24 let status = Command::new("cargo") 25 .args(&args) 26 .status() 27 .expect("failed to build userspace"); 28 assert!(status.success()); 29 Ok(()) 30 } 31 32 /// Build our ebpf program and the project 33 pub fn build(opts: Options) -> Result<(), anyhow::Error> { 34 // build our ebpf program followed by our application 35 build_ebpf(BuildOptions { 36 target: opts.bpf_target, 37 release: opts.release, 38 }) 39 .context("Error while building eBPF program")?; 40 build_project(&opts).context("Error while building userspace application")?; 41 Ok(()) 42 }