فهرست منبع

aya-bpf-bindings: fix anonymous enums

Alessandro Decina 4 سال پیش
والد
کامیت
bdca32cebf
3فایلهای تغییر یافته به همراه17 افزوده شده و 3 حذف شده
  1. 1 1
      aya-gen/src/bindgen.rs
  2. 1 1
      bpf/aya-bpf/src/maps/perf_map.rs
  3. 15 1
      xtask/src/codegen/aya_bpf_bindings.rs

+ 1 - 1
aya-gen/src/bindgen.rs

@@ -15,7 +15,7 @@ pub fn bpf_builder() -> Builder {
         .ctypes_prefix("::aya_bpf_cty")
         .layout_tests(false)
         .clang_arg("-Wno-unknown-attributes")
-        .default_enum_style(EnumVariation::Consts)
+        .default_enum_style(EnumVariation::ModuleConsts)
         .prepend_enum_name(false);
 
     bindgen

+ 1 - 1
bpf/aya-bpf/src/maps/perf_map.rs

@@ -1,7 +1,7 @@
 use core::{marker::PhantomData, mem};
 
 use crate::{
-    bindings::{bpf_map_def, BPF_F_CURRENT_CPU, BPF_MAP_TYPE_PERF_EVENT_ARRAY},
+    bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_F_CURRENT_CPU},
     helpers::bpf_perf_event_output,
     BpfContext,
 };

+ 15 - 1
xtask/src/codegen/aya_bpf_bindings.rs

@@ -21,7 +21,21 @@ pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
     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()]);
+            .clang_args(&["-I", &*opts.libbpf_dir.join("src").to_string_lossy()])
+            // open aya-bpf-bindings/.../bindings.rs and look for mod
+            // _bindgen, those are anonymous enums
+            .constified_enum("BPF_F_.*")
+            .constified_enum("BPF_REG_.*")
+            .constified_enum("BPF_CSUM_.*")
+            .constified_enum("BPF_ADJ_.*")
+            .constified_enum("BPF_SK_.*")
+            .constified_enum("BPF_RB_.*")
+            .constified_enum("BPF_RINGBUF_.*")
+            .constified_enum("BPF_SOCK_.*")
+            .constified_enum("BPF_TCP_.*")
+            .constified_enum("BPF_DEVCG_.*")
+            .constified_enum("BPF_FIB_.*")
+            .constified_enum("BPF_FLOW_.*");
 
         let types = ["bpf_map_.*"];
         let vars = ["BPF_.*", "bpf_.*"];