mirror of https://github.com/aya-rs/aya
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
2 years ago
|
use aya_tool::generate::{generate, InputFile};
|
||
4 years ago
|
|
||
|
use std::{path::PathBuf, process::exit};
|
||
|
|
||
3 years ago
|
use clap::Parser;
|
||
|
|
||
|
#[derive(Parser)]
|
||
4 years ago
|
pub struct Options {
|
||
3 years ago
|
#[clap(subcommand)]
|
||
4 years ago
|
command: Command,
|
||
|
}
|
||
|
|
||
3 years ago
|
#[derive(Parser)]
|
||
4 years ago
|
enum Command {
|
||
2 years ago
|
/// Generate Rust bindings to Kernel types using bpftool
|
||
3 years ago
|
#[clap(name = "generate", action)]
|
||
3 years ago
|
Generate {
|
||
3 years ago
|
#[clap(long, default_value = "/sys/kernel/btf/vmlinux", action)]
|
||
4 years ago
|
btf: PathBuf,
|
||
3 years ago
|
#[clap(long, conflicts_with = "btf", action)]
|
||
3 years ago
|
header: Option<PathBuf>,
|
||
3 years ago
|
#[clap(action)]
|
||
4 years ago
|
names: Vec<String>,
|
||
3 years ago
|
#[clap(last = true, action)]
|
||
3 years ago
|
bindgen_args: Vec<String>,
|
||
4 years ago
|
},
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
if let Err(e) = try_main() {
|
||
|
eprintln!("{:#}", e);
|
||
|
exit(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn try_main() -> Result<(), anyhow::Error> {
|
||
3 years ago
|
let opts = Options::parse();
|
||
4 years ago
|
match opts.command {
|
||
3 years ago
|
Command::Generate {
|
||
|
btf,
|
||
|
header,
|
||
|
names,
|
||
|
bindgen_args,
|
||
|
} => {
|
||
3 years ago
|
let bindings: String = if let Some(header) = header {
|
||
|
generate(InputFile::Header(header), &names, &bindgen_args)?
|
||
3 years ago
|
} else {
|
||
3 years ago
|
generate(InputFile::Btf(btf), &names, &bindgen_args)?
|
||
|
};
|
||
4 years ago
|
println!("{}", bindings);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Ok(())
|
||
|
}
|