xtask: aya-bpf-bindings: generate bindings for aarch64

pull/1/head
Alessandro Decina 4 years ago
parent 713494609e
commit 9d112c35c7

@ -7,7 +7,7 @@ use structopt::StructOpt;
use aya_gen::{
bindgen,
getters::{generate_getters_for_items, read_getter},
write_to_file, write_to_file_fmt,
write_to_file_fmt,
};
use syn::{parse_str, Item};
@ -18,17 +18,14 @@ use crate::codegen::{
#[derive(StructOpt)]
pub struct CodegenOptions {
#[structopt(long)]
arch: Architecture,
#[structopt(long)]
libbpf_dir: PathBuf,
}
pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
let dir = PathBuf::from("bpf/aya-bpf-bindings");
let generated = dir.join("src").join(opts.arch.to_string());
let builder = || {
let mut bindgen = bindgen::bpf_builder()
.header(&*dir.join("include/bindings.h").to_string_lossy())
.clang_args(&["-I", &*opts.libbpf_dir.join("src").to_string_lossy()]);
@ -44,7 +41,13 @@ pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
bindgen = bindgen.whitelist_var(x);
}
let bindings = bindgen
bindgen
};
for arch in Architecture::supported() {
let generated = dir.join("src").join(arch.to_string());
let bindings = builder()
.generate()
.map_err(|_| anyhow!("bindgen failed"))?
.to_string();
@ -57,7 +60,7 @@ pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
}
// write the bindings, with the original helpers removed
write_to_file(
write_to_file_fmt(
&generated.join("bindings.rs"),
&tree.to_token_stream().to_string(),
)?;
@ -80,6 +83,7 @@ pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
.to_string()
),
)?;
}
Ok(())
}

Loading…
Cancel
Save