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