Skip to content

Commit

Permalink
Update bindgen and improve link code
Browse files Browse the repository at this point in the history
  • Loading branch information
Morganamilo committed Sep 12, 2023
1 parent 9c005e6 commit 643ff21
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
4 changes: 2 additions & 2 deletions alpm-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
43 changes: 29 additions & 14 deletions alpm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -20,31 +18,41 @@ 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")
.unwrap();

#[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::<Vec<_>>();

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")
Expand All @@ -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();

Expand Down
6 changes: 1 addition & 5 deletions alpm-utils/src/depends.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use alpm::{AsDep, DepModVer, Ver};

/// Checks if a dependency is satisfied by a package (name + version).
pub fn satisfies_dep<S: AsRef<str>, V: AsRef<Ver>>(
dep: impl AsDep,
name: S,
version: V,
) -> bool {
pub fn satisfies_dep<S: AsRef<str>, V: AsRef<Ver>>(dep: impl AsDep, name: S, version: V) -> bool {
let name = name.as_ref();
let dep = dep.as_dep();

Expand Down
3 changes: 2 additions & 1 deletion alpm/src/filelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl File {
}

pub fn mode(&self) -> u32 {
self.inner.mode
#[allow(clippy::useless_conversion)]
self.inner.mode.into()
}
}

Expand Down
16 changes: 9 additions & 7 deletions alpm/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
Expand Down

0 comments on commit 643ff21

Please sign in to comment.