From 643ff21ecb76d3f6ce88f0615a0a82717c2f9bf1 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 5 Sep 2023 15:53:01 +0200 Subject: [PATCH] Update bindgen and improve link code --- alpm-sys/Cargo.toml | 4 ++-- alpm-sys/build.rs | 43 ++++++++++++++++++++++++++------------- alpm-utils/src/depends.rs | 6 +----- alpm/src/filelist.rs | 3 ++- alpm/src/handle.rs | 16 ++++++++------- 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/alpm-sys/Cargo.toml b/alpm-sys/Cargo.toml index 3cd50a4..d04a2d2 100644 --- a/alpm-sys/Cargo.toml +++ b/alpm-sys/Cargo.toml @@ -19,8 +19,8 @@ generate = ["bindgen"] docs-rs = [] [build-dependencies] -bindgen = { version = "0.55.1", optional = true, default-features = false, features = ["runtime"] } -pkg-config = "0.3.19" +bindgen = { version = "0.66.1", optional = true, default-features = false, features = ["runtime"] } +pkg-config = "0.3.27" [package.metadata.docs.rs] features = [ "docs-rs" ] diff --git a/alpm-sys/build.rs b/alpm-sys/build.rs index eb9f95e..c59e1d1 100644 --- a/alpm-sys/build.rs +++ b/alpm-sys/build.rs @@ -8,8 +8,6 @@ fn main() { #[cfg(feature = "static")] println!("cargo:rerun-if-changed=/usr/lib/pacman/lib/pkgconfig"); - #[cfg(feature = "static")] - println!("cargo:rustc-link-search=/usr/lib/pacman/lib/"); println!("cargo:rerun-if-env-changed=ALPM_LIB_DIR"); if cfg!(feature = "static") && Path::new("/usr/lib/pacman/lib/pkgconfig").exists() { @@ -20,7 +18,8 @@ fn main() { println!("cargo:rustc-link-search={}", dir); } - pkg_config::Config::new() + #[allow(dead_code)] + let lib = pkg_config::Config::new() .atleast_version("13.0.0") .statik(cfg!(feature = "static")) .probe("libalpm") @@ -28,23 +27,32 @@ fn main() { #[cfg(feature = "generate")] { - println!("cargo:rerun-if-env-changed=ALPM_INCLUDE_DIR"); - let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("ffi_generated.rs"); - let alpm_dir = env::var("ALPM_INCLUDE_DIR"); - let alpm_dir = match alpm_dir { - Ok(ref dir) => Path::new(dir), - Err(_) => Path::new("/usr/include"), - }; + let header = lib + .include_paths + .iter() + .map(|i| i.join("alpm.h")) + .find(|i| i.exists()) + .expect("could not find alpm.h"); + let mut include = lib + .include_paths + .iter() + .map(|i| format!("-I{}", i.display().to_string())) + .collect::>(); - let header = alpm_dir.join("alpm.h").to_str().unwrap().to_string(); + println!("cargo:rerun-if-env-changed=ALPM_INCLUDE_DIR"); + if let Ok(path) = env::var("ALPM_INCLUDE_DIR") { + include.clear(); + include.insert(0, path); + } let bindings = bindgen::builder() - .header(header) - .whitelist_type("(alpm|ALPM).*") - .whitelist_function("(alpm|ALPM).*") + .clang_args(&include) + .header(header.display().to_string()) + .allowlist_type("(alpm|ALPM).*") + .allowlist_function("(alpm|ALPM).*") .rustified_enum("_alpm_[a-z_]+_t") .rustified_enum("alpm_download_event_type_t") .constified_enum_module("_alpm_siglevel_t") @@ -60,6 +68,13 @@ fn main() { .opaque_type("alpm_pkg_t") .opaque_type("alpm_trans_t") .size_t_is_usize(true) + .derive_eq(true) + .derive_ord(true) + .derive_copy(true) + .derive_hash(true) + .derive_debug(true) + .derive_partialeq(true) + .derive_debug(true) .generate() .unwrap(); diff --git a/alpm-utils/src/depends.rs b/alpm-utils/src/depends.rs index 70c734c..49ebb13 100644 --- a/alpm-utils/src/depends.rs +++ b/alpm-utils/src/depends.rs @@ -1,11 +1,7 @@ use alpm::{AsDep, DepModVer, Ver}; /// Checks if a dependency is satisfied by a package (name + version). -pub fn satisfies_dep, V: AsRef>( - dep: impl AsDep, - name: S, - version: V, -) -> bool { +pub fn satisfies_dep, V: AsRef>(dep: impl AsDep, name: S, version: V) -> bool { let name = name.as_ref(); let dep = dep.as_dep(); diff --git a/alpm/src/filelist.rs b/alpm/src/filelist.rs index a4bf080..edf20b5 100644 --- a/alpm/src/filelist.rs +++ b/alpm/src/filelist.rs @@ -35,7 +35,8 @@ impl File { } pub fn mode(&self) -> u32 { - self.inner.mode + #[allow(clippy::useless_conversion)] + self.inner.mode.into() } } diff --git a/alpm/src/handle.rs b/alpm/src/handle.rs index db204dc..ff405b4 100644 --- a/alpm/src/handle.rs +++ b/alpm/src/handle.rs @@ -444,13 +444,15 @@ mod tests { assert!(!handle.check_space()); assert_eq!(handle.default_siglevel(), SigLevel::NONE); - handle - .set_default_siglevel(SigLevel::PACKAGE | SigLevel::DATABASE) - .unwrap(); - assert_eq!( - handle.default_siglevel(), - SigLevel::PACKAGE | SigLevel::DATABASE - ); + if crate::Capabilities::new().signatures() { + handle + .set_default_siglevel(SigLevel::PACKAGE | SigLevel::DATABASE) + .unwrap(); + assert_eq!( + handle.default_siglevel(), + SigLevel::PACKAGE | SigLevel::DATABASE + ); + } handle.set_ignorepkgs(["a", "b", "c"].iter()).unwrap(); let pkgs = handle.ignorepkgs().iter().collect::>();