Skip to content

Commit

Permalink
Merge pull request #687 from ajwerner/cargo-args
Browse files Browse the repository at this point in the history
xtask: allow arbitrary flags to cargo build
  • Loading branch information
tamird authored Jul 25, 2023
2 parents 5ebaf5f + a6b1fb9 commit 51cd363
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
ffi::OsString,
fmt::Write as _,
io::BufReader,
path::PathBuf,
Expand All @@ -12,12 +13,9 @@ use xtask::AYA_BUILD_INTEGRATION_BPF;

#[derive(Debug, Parser)]
pub struct BuildOptions {
/// Pass --release to `cargo build`.
/// Arguments to pass to `cargo build`.
#[clap(long)]
pub release: bool,
/// Pass --target to `cargo build`.
#[clap(long)]
pub target: Option<String>,
pub cargo_arg: Vec<OsString>,
}

#[derive(Debug, Parser)]
Expand All @@ -28,26 +26,22 @@ pub struct Options {
#[clap(short, long, default_value = "sudo -E")]
pub runner: String,
/// Arguments to pass to your application.
#[clap(name = "args", last = true)]
pub run_args: Vec<String>,
#[clap(last = true)]
pub run_args: Vec<OsString>,
}

/// Build the project
pub fn build(opts: BuildOptions) -> Result<Vec<(String, PathBuf)>> {
let BuildOptions { release, target } = opts;
let BuildOptions { cargo_arg } = opts;
let mut cmd = Command::new("cargo");
cmd.env(AYA_BUILD_INTEGRATION_BPF, "true").args([
"build",
"--tests",
"--message-format=json",
"--package=integration-test",
]);
if release {
cmd.arg("--release");
}
if let Some(target) = target {
cmd.args(["--target", &target]);
}
cmd.env(AYA_BUILD_INTEGRATION_BPF, "true")
.args([
"build",
"--tests",
"--message-format=json",
"--package=integration-test",
])
.args(cargo_arg);

let mut child = cmd
.stdout(Stdio::piped())
Expand Down

0 comments on commit 51cd363

Please sign in to comment.