archlinux / alpm.rs

Rust bindings for libalpm
GNU General Public License v3.0
112 stars 21 forks source link

error[E0308]: mismatched types #35

Open peterneutron opened 9 months ago

peterneutron commented 9 months ago

Affected Version

alpm.rs 144ced6 on aarch64 cargo 1.74.0

Description

Building from source fails, resulting in the error provided below.

Output

error[E0308]: mismatched types
   --> alpm/src/cb.rs:244:60
    |
244 |         unsafe { alpm_option_set_logcb(self.as_ptr(), Some(cb), &*ctx as *const _ as *mut _) };
    |                                                       ---- ^^ expected fn pointer, found fn item
    |                                                       |
    |                                                       arguments to this enum variant are incorrect
    |
    = note: expected fn pointer `unsafe extern "C" fn(_, _, _, *mut __va_list_tag)`
                  found fn item `extern "C" fn(_, _, _, [__va_list_tag; 1]) {logcb::<LogCbImpl<T, F>>}`
help: the type constructed contains `extern "C" fn(*mut c_void, u32, *const u8, [__va_list_tag; 1]) {logcb::<LogCbImpl<T, F>>}` due to the type of the argument passed
   --> alpm/src/cb.rs:244:55
    |
244 |         unsafe { alpm_option_set_logcb(self.as_ptr(), Some(cb), &*ctx as *const _ as *mut _) };
    |                                                       ^^^^^--^
    |                                                            |
    |                                                            this argument influences the type of `Some`
note: tuple variant defined here
   --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:571:5

For more information about this error, try `rustc --explain E0308`.
error: could not compile `alpm` (lib) due to previous error
peterneutron commented 9 months ago

Closing. See https://github.com/Morganamilo/paru/issues/1085

kwankiu commented 5 months ago

This error occurs on the current 3.0.x on aarch64

@7Ji FYI

7Ji commented 5 months ago

@kwankiu Strangely, pacman from vanilla Arch Linux on x86_64 and pacman from Arch Linux ARM on aarch64 pack the exactly same alpm.h and alpm_list.h, 1:1. Yet they would produce different bindgen for alpm-sys even on the same rust-bindgen, rust, clang and llvm-libs version.

The following is how ffi.rs would be generated differently on ALARM aarch64:

diff --git a/alpm-sys/src/ffi.rs b/alpm-sys/src/ffi.rs
index f735def..80f7401 100644
--- a/alpm-sys/src/ffi.rs
+++ b/alpm-sys/src/ffi.rs
@@ -1,10 +1,10 @@
-/* automatically generated by rust-bindgen 0.68.1 */
+/* automatically generated by rust-bindgen 0.69.4 */

 pub type __mode_t = ::std::os::raw::c_uint;
 pub type __off_t = ::std::os::raw::c_long;
 pub type mode_t = __mode_t;
 pub type off_t = __off_t;
-pub type va_list = __builtin_va_list;
+pub type va_list = [u64; 4usize];
 #[repr(C)]
 #[derive(Debug, Copy, Clone)]
 pub struct archive {
@@ -3324,7 +3324,7 @@ pub type alpm_cb_log = ::std::option::Option<
         ctx: *mut ::std::os::raw::c_void,
         level: alpm_loglevel_t,
         fmt: *const ::std::os::raw::c_char,
-        args: *mut __va_list_tag,
+        args: va_list,
     ),
 >;
 extern "C" {
@@ -4221,67 +4221,3 @@ extern "C" {
     #[doc = " Get the capabilities of the library.\n @return a bitmask of the capabilities"]
     pub fn alpm_capabilities() -> ::std::os::raw::c_int;
 }
-pub type __builtin_va_list = [__va_list_tag; 1usize];
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct __va_list_tag {
-    pub gp_offset: ::std::os::raw::c_uint,
-    pub fp_offset: ::std::os::raw::c_uint,
-    pub overflow_arg_area: *mut ::std::os::raw::c_void,
-    pub reg_save_area: *mut ::std::os::raw::c_void,
-}
-#[test]
-fn bindgen_test_layout___va_list_tag() {
-    const UNINIT: ::std::mem::MaybeUninit<__va_list_tag> = ::std::mem::MaybeUninit::uninit();
-    let ptr = UNINIT.as_ptr();
-    assert_eq!(
-        ::std::mem::size_of::<__va_list_tag>(),
-        24usize,
-        concat!("Size of: ", stringify!(__va_list_tag))
-    );
-    assert_eq!(
-        ::std::mem::align_of::<__va_list_tag>(),
-        8usize,
-        concat!("Alignment of ", stringify!(__va_list_tag))
-    );
-    assert_eq!(
-        unsafe { ::std::ptr::addr_of!((*ptr).gp_offset) as usize - ptr as usize },
-        0usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(__va_list_tag),
-            "::",
-            stringify!(gp_offset)
-        )
-    );
-    assert_eq!(
-        unsafe { ::std::ptr::addr_of!((*ptr).fp_offset) as usize - ptr as usize },
-        4usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(__va_list_tag),
-            "::",
-            stringify!(fp_offset)
-        )
-    );
-    assert_eq!(
-        unsafe { ::std::ptr::addr_of!((*ptr).overflow_arg_area) as usize - ptr as usize },
-        8usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(__va_list_tag),
-            "::",
-            stringify!(overflow_arg_area)
-        )
-    );
-    assert_eq!(
-        unsafe { ::std::ptr::addr_of!((*ptr).reg_save_area) as usize - ptr as usize },
-        16usize,
-        concat!(
-            "Offset of field: ",
-            stringify!(__va_list_tag),
-            "::",
-            stringify!(reg_save_area)
-        )
-    );
-}
kwankiu commented 5 months ago

@Morganamilo

7Ji commented 5 months ago

As a temporary workaround, projects using alpm.rs could enable its generate feature to generate the bindings on the fly, e.g. on one of my projects:

diff --git a/Cargo.toml b/Cargo.toml
index 32cacb3..71a9ac0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

 [dependencies]
-alpm = "3.0"
+alpm = { version = "3.0", features = [ "generate" ] }
 blake2 = "0.10"
 crc = "3"
 env_logger = "0.10"

This would introduce a few deps both into the project and into system (pacman -S rust-bindgen would satisfy that)

peterneutron commented 5 months ago

@7Ji Builds successfully with proposed fix.

alpm = { version = "3.0.4", features = [ "generate" ] }