1 //! libbpf bindgen configuration
2 // Modified from the upstream libbpf-sys build.rs file in the libbpf-sys root dir.
3 use std::collections::HashSet;
main()4 fn main() {
5 #[derive(Debug)]
6 struct IgnoreMacros(HashSet<&'static str>);
7 impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
8 fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
9 if self.0.contains(name) {
10 bindgen::callbacks::MacroParsingBehavior::Ignore
11 } else {
12 bindgen::callbacks::MacroParsingBehavior::Default
13 }
14 }
15 }
16 let ignored_macros = IgnoreMacros(
17 vec![
18 "BTF_KIND_FUNC",
19 "BTF_KIND_FUNC_PROTO",
20 "BTF_KIND_VAR",
21 "BTF_KIND_DATASEC",
22 "BTF_KIND_FLOAT",
23 "BTF_KIND_DECL_TAG",
24 "BTF_KIND_TYPE_TAG",
25 "BTF_KIND_ENUM64",
26 ]
27 .into_iter()
28 .collect(),
29 );
30 bindgen_cmd::build(|mut builder| {
31 builder = builder
32 .derive_default(true)
33 .explicit_padding(true)
34 .default_enum_style(bindgen::EnumVariation::Consts)
35 .size_t_is_usize(false)
36 .prepend_enum_name(false)
37 .layout_tests(false)
38 .generate_comments(false)
39 .emit_builtins()
40 .allowlist_function("bpf_.+")
41 .allowlist_function("btf_.+")
42 .allowlist_function("libbpf_.+")
43 .allowlist_function("perf_.+")
44 .allowlist_function("ring_buffer_.+")
45 .allowlist_function("user_ring_buffer_.+")
46 .allowlist_function("vdprintf")
47 .allowlist_type("bpf_.+")
48 .allowlist_type("btf_.+")
49 .allowlist_type("xdp_.+")
50 .allowlist_type("perf_.+")
51 .allowlist_var("BPF_.+")
52 .allowlist_var("BTF_.+")
53 .allowlist_var("XDP_.+")
54 .allowlist_var("PERF_.+")
55 .parse_callbacks(Box::new(ignored_macros));
56 builder
57 })
58 }
59