]> git.sesse.net Git - bcachefs-tools-debian/blob - bch_bindgen/build.rs
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / 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     println!("cargo:rerun-if-changed=src/libbcachefs_wrapper.h");
14
15     let out_dir: PathBuf = std::env::var_os("OUT_DIR")
16         .expect("ENV Var 'OUT_DIR' Expected")
17         .into();
18     let top_dir: PathBuf = std::env::var_os("CARGO_MANIFEST_DIR")
19         .expect("ENV Var 'CARGO_MANIFEST_DIR' Expected")
20         .into();
21
22     let bindings = bindgen::builder()
23         .header(
24             top_dir
25                 .join("src")
26                 .join("libbcachefs_wrapper.h")
27                 .display()
28                 .to_string(),
29         )
30         .clang_arg("-I..")
31         .clang_arg("-I../c_src")
32         .clang_arg("-I../include")
33         .clang_arg("-DZSTD_STATIC_LINKING_ONLY")
34         .clang_arg("-DNO_BCACHEFS_FS")
35         .clang_arg("-D_GNU_SOURCE")
36         .clang_arg("-DRUST_BINDGEN")
37         .clang_arg("-fkeep-inline-functions")
38         .derive_debug(true)
39         .derive_default(true)
40         .layout_tests(true)
41         .default_enum_style(bindgen::EnumVariation::Rust {
42             non_exhaustive: true,
43         })
44         .allowlist_function("bcachefs_usage")
45         .allowlist_function("raid_init")
46         .allowlist_function("cmd_.*")
47         .allowlist_function(".*_cmds")
48         .allowlist_function(".*bch2_.*")
49         .allowlist_function("bio_.*")
50         .allowlist_function("derive_passphrase")
51         .allowlist_function("request_key")
52         .allowlist_function("add_key")
53         .allowlist_function("keyctl_search")
54         .allowlist_function("match_string")
55         .allowlist_function("printbuf.*")
56         .blocklist_type("bch_extent_ptr")
57         .blocklist_type("btree_node")
58         .blocklist_type("bch_extent_crc32")
59         .blocklist_type("rhash_lock_head")
60         .blocklist_type("srcu_struct")
61         .allowlist_var("BCH_.*")
62         .allowlist_var("KEY_SPEC_.*")
63         .allowlist_var("Fix753_FMODE_.*")
64         .allowlist_var("bch.*")
65         .allowlist_var("__bch2.*")
66         .allowlist_var("__BTREE_ITER.*")
67         .allowlist_var("BTREE_ITER.*")
68         .blocklist_item("bch2_bkey_ops")
69         .allowlist_type("bch_.*")
70         .allowlist_type("fsck_err_opts")
71         .rustified_enum("fsck_err_opts")
72         .allowlist_type("nonce")
73         .no_debug("bch_replicas_padded")
74         .newtype_enum("bch_kdf_types")
75         .rustified_enum("bch_key_types")
76         .opaque_type("gendisk")
77         .opaque_type("gc_stripe")
78         .opaque_type("open_bucket.*")
79         .opaque_type("replicas_delta_list")
80         .no_copy("btree_trans")
81         .no_copy("printbuf")
82         .no_partialeq("bkey")
83         .no_partialeq("bpos")
84         .generate_inline_functions(true)
85         .parse_callbacks(Box::new(Fix753 {}))
86         .generate()
87         .expect("BindGen Generation Failiure: [libbcachefs_wrapper]");
88     bindings
89         .write_to_file(out_dir.join("bcachefs.rs"))
90         .expect("Writing to output file failed for: `bcachefs.rs`");
91
92     let keyutils = pkg_config::probe_library("libkeyutils").expect("Failed to find keyutils lib");
93     let bindings = bindgen::builder()
94         .header(
95             top_dir
96                 .join("src")
97                 .join("keyutils_wrapper.h")
98                 .display()
99                 .to_string(),
100         )
101         .clang_args(
102             keyutils
103                 .include_paths
104                 .iter()
105                 .map(|p| format!("-I{}", p.display())),
106         )
107         .generate()
108         .expect("BindGen Generation Failiure: [Keyutils]");
109     bindings
110         .write_to_file(out_dir.join("keyutils.rs"))
111         .expect("Writing to output file failed for: `keyutils.rs`");
112 }