]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/bch_bindgen/build.rs
92ec3cefc38a030647dd619add8a65d00a5848ab
[bcachefs-tools-debian] / rust-src / bch_bindgen / build.rs
1
2 #[derive(Debug)]
3 pub struct Fix753 {}
4 impl bindgen::callbacks::ParseCallbacks for Fix753 {
5     fn item_name(&self, original_item_name: &str) -> Option<String> {
6         Some(original_item_name.trim_start_matches("Fix753_").to_owned())
7     }
8 }
9
10 fn main() {
11     use std::path::PathBuf;
12
13     let out_dir: PathBuf = std::env::var_os("OUT_DIR")
14         .expect("ENV Var 'OUT_DIR' Expected")
15         .into();
16     let top_dir: PathBuf = std::env::var_os("CARGO_MANIFEST_DIR")
17         .expect("ENV Var 'CARGO_MANIFEST_DIR' Expected")
18         .into();
19
20     let libbcachefs_inc_dir = std::path::Path::new("../..");
21
22     let _libbcachefs_dir = top_dir.join("libbcachefs").join("libbcachefs");
23     let bindings = bindgen::builder()
24         .header(
25             top_dir
26                 .join("src")
27                 .join("libbcachefs_wrapper.h")
28                 .display()
29                 .to_string(),
30         )
31         .clang_arg(format!(
32             "-I{}",
33             libbcachefs_inc_dir.join("include").display()
34         ))
35         .clang_arg(format!("-I{}", libbcachefs_inc_dir.display()))
36         .clang_arg("-DZSTD_STATIC_LINKING_ONLY")
37         .clang_arg("-DNO_BCACHEFS_FS")
38         .clang_arg("-D_GNU_SOURCE")
39         .clang_arg("-fkeep-inline-functions")
40         .derive_debug(true)
41         .derive_default(true)
42         .layout_tests(true)
43         .default_enum_style(bindgen::EnumVariation::Rust {
44             non_exhaustive: true,
45         })
46         .allowlist_function(".*bch2_.*")
47         .allowlist_function("bio_.*")
48         .allowlist_function("derive_passphrase")
49         .allowlist_function("request_key")
50         .allowlist_function("add_key")
51         .allowlist_function("keyctl_search")
52         .allowlist_function("match_string")
53         .allowlist_function("printbuf.*")
54         .blocklist_type("bch_extent_ptr")
55         .blocklist_type("btree_node")
56         .blocklist_type("bch_extent_crc32")
57         .blocklist_type("rhash_lock_head")
58         .blocklist_type("srcu_struct")
59         .allowlist_var("BCH_.*")
60         .allowlist_var("KEY_SPEC_.*")
61         .allowlist_var("Fix753_FMODE_.*")
62         .allowlist_var("bch.*")
63         .allowlist_var("__BTREE_ITER.*")
64         .allowlist_var("BTREE_ITER.*")
65         .blocklist_item("bch2_bkey_ops")
66         .allowlist_type("bch_.*")
67         .allowlist_type("fsck_err_opts")
68         .rustified_enum("fsck_err_opts")
69         .allowlist_type("nonce")
70         .no_debug("bch_replicas_padded")
71         .newtype_enum("bch_kdf_types")
72         .rustified_enum("bch_key_types")
73         .opaque_type("gendisk")
74         .opaque_type("gc_stripe")
75         .opaque_type("open_bucket.*")
76         .opaque_type("replicas_delta_list")
77         .no_copy("btree_trans")
78         .no_copy("printbuf")
79         .no_partialeq("bkey")
80         .no_partialeq("bpos")
81         .generate_inline_functions(true)
82         .parse_callbacks(Box::new(Fix753 {}))
83         .generate()
84         .expect("BindGen Generation Failiure: [libbcachefs_wrapper]");
85     bindings
86         .write_to_file(out_dir.join("bcachefs.rs"))
87         .expect("Writing to output file failed for: `bcachefs.rs`");
88
89     let keyutils = pkg_config::probe_library("libkeyutils").expect("Failed to find keyutils lib");
90     let bindings = bindgen::builder()
91         .header(
92             top_dir
93                 .join("src")
94                 .join("keyutils_wrapper.h")
95                 .display()
96                 .to_string(),
97         )
98         .clang_args(
99             keyutils
100                 .include_paths
101                 .iter()
102                 .map(|p| format!("-I{}", p.display())),
103         )
104         .generate()
105         .expect("BindGen Generation Failiure: [Keyutils]");
106     bindings
107         .write_to_file(out_dir.join("keyutils.rs"))
108         .expect("Writing to output file failed for: `keyutils.rs`");
109 }