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