]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/bch_bindgen/build.rs
Rust now integrated into bcachefs binary
[bcachefs-tools-debian] / rust-src / bch_bindgen / build.rs
1 fn main() {
2     use std::path::PathBuf;
3
4     let out_dir: PathBuf = std::env::var_os("OUT_DIR")
5         .expect("ENV Var 'OUT_DIR' Expected")
6         .into();
7     let top_dir: PathBuf = std::env::var_os("CARGO_MANIFEST_DIR")
8         .expect("ENV Var 'CARGO_MANIFEST_DIR' Expected")
9         .into();
10
11     let libbcachefs_inc_dir = std::path::Path::new("../..");
12
13     let _libbcachefs_dir = top_dir.join("libbcachefs").join("libbcachefs");
14     let bindings = bindgen::builder()
15         .header(
16             top_dir
17                 .join("src")
18                 .join("libbcachefs_wrapper.h")
19                 .display()
20                 .to_string(),
21         )
22         .clang_arg(format!(
23             "-I{}",
24             libbcachefs_inc_dir.join("include").display()
25         ))
26         .clang_arg(format!("-I{}", libbcachefs_inc_dir.display()))
27         .clang_arg("-DZSTD_STATIC_LINKING_ONLY")
28         .clang_arg("-DNO_BCACHEFS_FS")
29         .clang_arg("-D_GNU_SOURCE")
30         .derive_debug(true)
31         .derive_default(true)
32         .derive_eq(true)
33         .layout_tests(true)
34         .default_enum_style(bindgen::EnumVariation::Rust {
35             non_exhaustive: true,
36         })
37         .allowlist_function(".*bch2_.*")
38         .allowlist_function("bio_.*")
39         .allowlist_function("bch2_super_write_fd")
40         .allowlist_function("derive_passphrase")
41         .allowlist_function("request_key")
42         .allowlist_function("add_key")
43         .allowlist_function("keyctl_search")
44         .blocklist_type("bch_extent_ptr")
45         .blocklist_type("btree_node")
46         .blocklist_type("bch_extent_crc32")
47         .blocklist_type("rhash_lock_head")
48         .blocklist_type("srcu_struct")
49         .allowlist_var("BCH_.*")
50         .allowlist_var("KEY_SPEC_.*")
51         .allowlist_type("bch_kdf_types")
52         .allowlist_type("bch_sb_field_.*")
53         .allowlist_type("bch_encrypted_key")
54         .allowlist_type("nonce")
55         .newtype_enum("bch_kdf_types")
56         .opaque_type("gendisk")
57         .opaque_type("bkey")
58         .opaque_type("gc_stripe")
59         .opaque_type("open_bucket.*")
60         .generate()
61         .expect("BindGen Generation Failiure: [libbcachefs_wrapper]");
62     bindings
63         .write_to_file(out_dir.join("bcachefs.rs"))
64         .expect("Writing to output file failed for: `bcachefs.rs`");
65
66     let keyutils = pkg_config::probe_library("libkeyutils").expect("Failed to find keyutils lib");
67     let bindings = bindgen::builder()
68         .header(
69             top_dir
70                 .join("src")
71                 .join("keyutils_wrapper.h")
72                 .display()
73                 .to_string(),
74         )
75         .clang_args(
76             keyutils
77                 .include_paths
78                 .iter()
79                 .map(|p| format!("-I{}", p.display())),
80         )
81         .generate()
82         .expect("BindGen Generation Failiure: [Keyutils]");
83     bindings
84         .write_to_file(out_dir.join("keyutils.rs"))
85         .expect("Writing to output file failed for: `keyutils.rs`");
86 }