-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new command to build ebpf and userspace programs without running. ``` cargo xtask build ``` Co-authored-by: Michal Rostecki <[email protected]>
- Loading branch information
1 parent
f642921
commit 7c143de
Showing
4 changed files
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters