diff --git a/xtask/src/codegen/aya.rs b/xtask/src/codegen/aya.rs index 16724b38..07191f4e 100644 --- a/xtask/src/codegen/aya.rs +++ b/xtask/src/codegen/aya.rs @@ -1,23 +1,16 @@ use anyhow::anyhow; use std::path::PathBuf; -use structopt::StructOpt; use aya_gen::{bindgen, write_to_file}; -use crate::codegen::Architecture; +use crate::codegen::{Architecture, Options}; -#[derive(StructOpt)] -pub struct CodegenOptions { - #[structopt(long)] - libbpf_dir: PathBuf, +pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> { + codegen_internal_btf_bindings(opts)?; + codegen_bindings(opts) } -pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> { - codegen_internal_btf_bindings(&opts)?; - codegen_bindings(&opts) -} - -fn codegen_internal_btf_bindings(opts: &CodegenOptions) -> Result<(), anyhow::Error> { +fn codegen_internal_btf_bindings(opts: &Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("aya"); let generated = dir.join("src/generated"); let mut bindgen = bindgen::user_builder().header( @@ -46,7 +39,7 @@ fn codegen_internal_btf_bindings(opts: &CodegenOptions) -> Result<(), anyhow::Er Ok(()) } -fn codegen_bindings(opts: &CodegenOptions) -> Result<(), anyhow::Error> { +fn codegen_bindings(opts: &Options) -> Result<(), anyhow::Error> { let types = [ // BPF "BPF_TYPES", diff --git a/xtask/src/codegen/aya_bpf_bindings.rs b/xtask/src/codegen/aya_bpf_bindings.rs index 9bd6ff4c..02eca595 100644 --- a/xtask/src/codegen/aya_bpf_bindings.rs +++ b/xtask/src/codegen/aya_bpf_bindings.rs @@ -2,7 +2,6 @@ use anyhow::anyhow; use proc_macro2::TokenStream; use quote::ToTokens; use std::path::PathBuf; -use structopt::StructOpt; use aya_gen::{ bindgen, @@ -13,16 +12,10 @@ use syn::{parse_str, Item}; use crate::codegen::{ helpers::{expand_helpers, extract_helpers}, - Architecture, + Architecture, Options, }; -#[derive(StructOpt)] -pub struct CodegenOptions { - #[structopt(long)] - libbpf_dir: PathBuf, -} - -pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> { +pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("bpf/aya-bpf-bindings"); let builder = || { diff --git a/xtask/src/codegen/mod.rs b/xtask/src/codegen/mod.rs index 8e90e3a7..c603fdd9 100644 --- a/xtask/src/codegen/mod.rs +++ b/xtask/src/codegen/mod.rs @@ -2,6 +2,8 @@ mod aya; mod aya_bpf_bindings; mod helpers; +use std::path::PathBuf; + use structopt::StructOpt; const SUPPORTED_ARCHS: &'static [Architecture] = &[Architecture::X86_64, Architecture::AArch64]; @@ -41,22 +43,29 @@ impl std::fmt::Display for Architecture { #[derive(StructOpt)] pub struct Options { + #[structopt(long)] + libbpf_dir: PathBuf, + #[structopt(subcommand)] - command: Command, + command: Option, } #[derive(StructOpt)] enum Command { #[structopt(name = "aya")] - Aya(aya::CodegenOptions), + Aya, #[structopt(name = "aya-bpf-bindings")] - AyaBpfBindings(aya_bpf_bindings::CodegenOptions), + AyaBpfBindings, } pub fn codegen(opts: Options) -> Result<(), anyhow::Error> { use Command::*; match opts.command { - Aya(opts) => aya::codegen(opts), - AyaBpfBindings(opts) => aya_bpf_bindings::codegen(opts), + Some(Aya) => aya::codegen(&opts), + Some(AyaBpfBindings) => aya_bpf_bindings::codegen(&opts), + None => { + aya::codegen(&opts)?; + aya_bpf_bindings::codegen(&opts) + } } }