2020-04-07 18:09:17 +03:00
/*
* Copyright ( C ) 2019 Red Hat , Inc .
*
* SPDX - License - Identifier : Apache - 2.0 OR MIT
* /
2021-02-10 02:07:37 +03:00
use cxx ::{ type_id , ExternType } ;
2020-04-07 18:09:17 +03:00
/* This is an experiment in calling libdnf functions from Rust. Really, it'd be more sustainable to
* generate a " libdnf-sys " from SWIG ( though it doesn ' t look like that ' s supported yet
* https ://github.com/swig/swig/issues/1468) or at least `bindgen` for the strict C parts of the
* API . For now , I just took the shortcut of manually defining a tiny subset we care about . * /
// This technique for an uninstantiable/opaque type is used by libgit2-sys at least:
// https://github.com/rust-lang/git2-rs/blob/master/libgit2-sys/lib.rs#L51
2021-02-10 02:07:37 +03:00
// XXX: dedupe with macro
2020-04-07 18:09:17 +03:00
pub enum DnfPackage { }
2021-02-10 02:07:37 +03:00
unsafe impl ExternType for DnfPackage {
type Id = type_id! ( dnfcxx ::DnfPackage ) ;
type Kind = cxx ::kind ::Trivial ;
}
2020-04-07 18:09:17 +03:00
pub enum DnfRepo { }
2021-02-10 02:07:37 +03:00
unsafe impl ExternType for DnfRepo {
type Id = type_id! ( dnfcxx ::DnfRepo ) ;
type Kind = cxx ::kind ::Trivial ;
}
2020-04-07 18:09:17 +03:00
2021-02-10 02:07:37 +03:00
#[ cxx::bridge(namespace = " dnfcxx " ) ]
pub mod ffi {
unsafe extern " C++ " {
include! ( " libdnf.hxx " ) ;
2020-04-07 18:09:17 +03:00
2021-02-10 02:07:37 +03:00
type DnfPackage = crate ::DnfPackage ;
fn dnf_package_get_nevra ( pkg : & mut DnfPackage ) -> Result < String > ;
fn dnf_package_get_name ( pkg : & mut DnfPackage ) -> Result < String > ;
fn dnf_package_get_evr ( pkg : & mut DnfPackage ) -> Result < String > ;
fn dnf_package_get_arch ( pkg : & mut DnfPackage ) -> Result < String > ;
type DnfRepo = crate ::DnfRepo ;
fn dnf_repo_get_id ( repo : & mut DnfRepo ) -> Result < String > ;
fn dnf_repo_get_timestamp_generated ( repo : & mut DnfRepo ) -> Result < u64 > ;
}
2020-04-07 18:09:17 +03:00
}
2021-02-10 02:07:37 +03:00
pub use ffi ::* ;