diff options
author | Kayla Firestack <dev@kaylafire.me> | 2021-10-18 13:27:51 -0400 |
---|---|---|
committer | Kayla Firestack <dev@kaylafire.me> | 2021-10-18 16:30:52 -0400 |
commit | 1f8fc31ddc1975a1f2e7c2fa8f7f611eab761680 (patch) | |
tree | 62eef03a32544a61c45665e6c4b4ea8014fd6fc8 /rust-src/bch_bindgen/build.rs | |
parent | 7e97ef59bd30154776417748b6518ec43a3db2b9 (diff) |
split mount into a library crate for rust reuse
update makefile to output shared library and rust build
fix default.nix to properly get the binary name for `ln`ing - move binary to main.rs
add rustfmt and gitignore files
move build.rs file into bch_bindgen for reuse between projects
add outputs to nix flake and checks
add mount.toml to makefile
Diffstat (limited to 'rust-src/bch_bindgen/build.rs')
-rw-r--r-- | rust-src/bch_bindgen/build.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/rust-src/bch_bindgen/build.rs b/rust-src/bch_bindgen/build.rs new file mode 100644 index 00000000..fd570dbb --- /dev/null +++ b/rust-src/bch_bindgen/build.rs @@ -0,0 +1,74 @@ +fn main() { + use std::path::PathBuf; + // use std::process::Command; + + let out_dir: PathBuf = std::env::var_os("OUT_DIR").expect("ENV Var 'OUT_DIR' Expected").into(); + let top_dir: PathBuf = std::env::var_os("CARGO_MANIFEST_DIR") + .expect("ENV Var 'CARGO_MANIFEST_DIR' Expected") + .into(); + let libbcachefs_inc_dir = + std::env::var("LIBBCACHEFS_INCLUDE").unwrap_or_else(|_| top_dir.join("libbcachefs").display().to_string()); + let libbcachefs_inc_dir = std::path::Path::new(&libbcachefs_inc_dir); + println!("{}", libbcachefs_inc_dir.display()); + + println!("cargo:rustc-link-lib=dylib=bcachefs"); + println!("cargo:rustc-link-search={}", env!("LIBBCACHEFS_LIB")); + + let _libbcachefs_dir = top_dir.join("libbcachefs").join("libbcachefs"); + let bindings = bindgen::builder() + .header(top_dir.join("src").join("libbcachefs_wrapper.h").display().to_string()) + .clang_arg(format!("-I{}", libbcachefs_inc_dir.join("include").display())) + .clang_arg(format!("-I{}", libbcachefs_inc_dir.display())) + .clang_arg("-DZSTD_STATIC_LINKING_ONLY") + .clang_arg("-DNO_BCACHEFS_FS") + .clang_arg("-D_GNU_SOURCE") + .derive_debug(true) + .derive_default(true) + .derive_eq(true) + .layout_tests(true) + .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: true }) + .allowlist_function(".*bch2_.*") + // .allowlist_function("bch2_read_super") + // .allowlist_function("bch2_sb_field_.*") + // .allowlist_function("bch2_super_write") + // .allowlist_function("bch2_chacha_encrypt_key") + // .allowlist_function("__bch2_super_read") + .allowlist_function("bio_.*") + .allowlist_function("bch2_super_write_fd") + .allowlist_function("derive_passphrase") + .allowlist_function("request_key") + .allowlist_function("add_key") + .allowlist_function("keyctl_search") + .blocklist_type("bch_extent_ptr") + .blocklist_type("btree_node") + .blocklist_type("bch_extent_crc32") + .blocklist_type("rhash_lock_head") + .blocklist_type("srcu_struct") + .allowlist_var("BCH_.*") + .allowlist_var("KEY_SPEC_.*") + .allowlist_type("bch_kdf_types") + .allowlist_type("bch_sb_field_.*") + .allowlist_type("bch_encrypted_key") + .allowlist_type("nonce") + .newtype_enum("bch_kdf_types") + .opaque_type("gendisk") + .opaque_type("bkey") + // .opaque_type("bch_extent_ptr") + // .opaque_type("bch_extent_crc32") + .opaque_type("open_bucket.*") + .generate() + .expect("BindGen Generation Failiure: [libbcachefs_wrapper]"); + bindings + .write_to_file(out_dir.join("bcachefs.rs")) + .expect("Writing to output file failed for: `bcachefs.rs`"); + + let keyutils = pkg_config::probe_library("libkeyutils").expect("Failed to find keyutils lib"); + let bindings = bindgen::builder() + .header(top_dir.join("src").join("keyutils_wrapper.h").display().to_string()) + .clang_args(keyutils.include_paths.iter().map(|p| format!("-I{}", p.display()))) + .generate() + .expect("BindGen Generation Failiure: [Keyutils]"); + bindings + .write_to_file(out_dir.join("keyutils.rs")) + .expect("Writing to output file failed for: `keyutils.rs`"); +} |