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

Loading…
Cancel
Save