Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error[E0308]: mismatched types #35

Open
peterneutron opened this issue Dec 1, 2023 · 6 comments
Open

error[E0308]: mismatched types #35

peterneutron opened this issue Dec 1, 2023 · 6 comments

Comments

@peterneutron
Copy link

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
Copy link
Author

Closing. See Morganamilo/paru#1085

@kwankiu
Copy link

kwankiu commented Mar 18, 2024

This error occurs on the current 3.0.x on aarch64

@7Ji FYI

@7Ji
Copy link

7Ji commented Mar 18, 2024

@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
Copy link

kwankiu commented Mar 18, 2024

@Morganamilo

@peterneutron peterneutron reopened this Mar 18, 2024
@7Ji
Copy link

7Ji commented Mar 20, 2024

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
Copy link
Author

@7Ji Builds successfully with proposed fix.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants