-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alias] | ||
xtask = "run --package xtask --" |
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
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,23 @@ | ||
mod run; | ||
|
||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct Options { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
enum Command { | ||
Run(run::Options), | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let Options { command } = Parser::parse(); | ||
|
||
match command { | ||
Command::Run(opts) => run::run(opts), | ||
} | ||
} |
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,47 @@ | ||
use std::{ffi::OsString, process::Command}; | ||
|
||
use anyhow::{bail, Context as _, Result}; | ||
use clap::Parser; | ||
use xtask::AYA_BUILD_EBPF; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct Options { | ||
/// Build and run the release target. | ||
#[clap(long)] | ||
release: bool, | ||
/// The command used to wrap your application. | ||
#[clap(short, long, default_value = "sudo -E")] | ||
runner: String, | ||
/// Arguments to pass to your application. | ||
#[clap(global = true, last = true)] | ||
run_args: Vec<OsString>, | ||
} | ||
|
||
/// Build and run the project. | ||
pub fn run(opts: Options) -> Result<()> { | ||
let Options { | ||
release, | ||
runner, | ||
run_args, | ||
} = opts; | ||
|
||
let mut cmd = Command::new("cargo"); | ||
cmd.env(AYA_BUILD_EBPF, "true"); | ||
cmd.args(["run", "--package", "{{project-name}}-ebpf", "--config"]); | ||
if release { | ||
cmd.arg(format!("target.release.runner=\"{}\"", runner)); | ||
cmd.arg("--release"); | ||
} else { | ||
cmd.arg(format!("target.dev.runner=\"{}\"", runner)); | ||
} | ||
if !run_args.is_empty() { | ||
cmd.arg("--").args(run_args); | ||
} | ||
let status = cmd | ||
.status() | ||
.with_context(|| format!("failed to run {cmd:?}"))?; | ||
if status.code() != Some(0) { | ||
bail!("{cmd:?} failed: {status:?}") | ||
} | ||
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