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

rust elektra fails to build #4989

Open
markus2330 opened this issue Aug 10, 2023 · 3 comments
Open

rust elektra fails to build #4989

markus2330 opened this issue Aug 10, 2023 · 3 comments
Assignees

Comments

@markus2330
Copy link
Contributor

cd src/bindings/rust/elektra
git mv published_Cargo.toml Cargo.toml 
cargo build # or cargo publish
   Compiling elektra v0.11.0 (/home/markus/Projekte/Elektra/libelektra/src/bindings/rust/elektra)
error[E0308]: mismatched types
   --> elektra/src/key.rs:221:21
    |
218 |                 elektra_sys::keySetBinary(
    |                 ------------------------- arguments to this function are incorrect
...
221 |                     data.len(),
    |                     ^^^^^^^^^^ expected `u64`, found `usize`
    |
note: function defined here
   --> /home/markus/Projekte/Elektra/libelektra/src/bindings/rust/target/debug/build/elektra-sys-122c63e9e91011d8/out/bindings.rs:242:12
    |
242 |     pub fn keySetBinary(
    |            ^^^^^^^^^^^^
help: you can convert a `usize` to a `u64` and panic if the converted value doesn't fit
    |
221 |                     data.len().try_into().unwrap(),
    |                               ++++++++++++++++++++

error[E0308]: mismatched types
   --> elektra/src/key.rs:235:17
    |
232 |             elektra_sys::keyGetBinary(
    |             ------------------------- arguments to this function are incorrect
...
235 |                 vec.capacity(),
    |                 ^^^^^^^^^^^^^^ expected `u64`, found `usize`
    |
note: function defined here
   --> /home/markus/Projekte/Elektra/libelektra/src/bindings/rust/target/debug/build/elektra-sys-122c63e9e91011d8/out/bindings.rs:235:12
    |
235 |     pub fn keyGetBinary(
    |            ^^^^^^^^^^^^
help: you can convert a `usize` to a `u64` and panic if the converted value doesn't fit
    |
235 |                 vec.capacity().try_into().unwrap(),
    |                               ++++++++++++++++++++

error[E0308]: mismatched types
  --> elektra/src/readable.rs:43:18
   |
42 |     fn basename_size(&self) -> isize {
   |                                ----- expected `isize` because of return type
43 |         unsafe { elektra_sys::keyGetBaseNameSize(self.as_ref()) }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `i64`
   |
help: you can convert an `i64` to an `isize` and panic if the converted value doesn't fit
   |
43 |         unsafe { elektra_sys::keyGetBaseNameSize(self.as_ref()).try_into().unwrap() }
   |                                                                ++++++++++++++++++++

error[E0308]: mismatched types
   --> elektra/src/keyset.rs:177:50
    |
177 |         let ks_ptr = unsafe { elektra_sys::ksNew(capacity, elektra_sys::KS_END) };
    |                               ------------------ ^^^^^^^^ expected `u64`, found `usize`
    |                               |
    |                               arguments to this function are incorrect
    |
note: function defined here
   --> /home/markus/Projekte/Elektra/libelektra/src/bindings/rust/target/debug/build/elektra-sys-122c63e9e91011d8/out/bindings.rs:257:12
    |
257 |     pub fn ksNew(alloc: size_t, ...) -> *mut KeySet;
    |            ^^^^^
help: you can convert a `usize` to a `u64` and panic if the converted value doesn't fit
    |
177 |         let ks_ptr = unsafe { elektra_sys::ksNew(capacity.try_into().unwrap(), elektra_sys::KS_END) };
    |                                                          ++++++++++++++++++++

error[E0308]: mismatched types
   --> elektra/src/keyset.rs:194:18
    |
193 |     pub fn append(&mut self, to_append: &KeySet) -> isize {
    |                                                     ----- expected `isize` because of return type
194 |         unsafe { elektra_sys::ksAppend(self.as_ptr(), to_append.as_ref()) }
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `i64`
    |
help: you can convert an `i64` to an `isize` and panic if the converted value doesn't fit
    |
194 |         unsafe { elektra_sys::ksAppend(self.as_ptr(), to_append.as_ref()).try_into().unwrap() }
    |                                                                          ++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `elektra` due to 5 previous errors
@markus2330
Copy link
Contributor Author

Note: elektra-sys 0.11.0 is already published

@horenso horenso self-assigned this Aug 16, 2023
@horenso
Copy link

horenso commented Aug 16, 2023

The first error seems to be that:

extern "C" {
    pub fn keySetBinary(
        key: *mut Key,
        newBinary: *const ::std::os::raw::c_void,
        dataSize: size_t,
    ) -> ssize_t;
}

dataSize uses size_t, which is the size of a pointer (32bit/64bit usually). Now in our call:

unsafe {
    elektra_sys::keySetBinary(
        self.as_ptr(),
        data.as_ptr() as *const std::os::raw::c_void,
        data.len(),
    );
}

data.len() returns a usize which is supposed to be the same concept, a pointer sized unsized integer.

ChatGPT semi-helpfully says: "The complaint you're getting suggests that the Rust type usize doesn't match the expected C type size_t.". I'm going to research why the types no longer match.

@markus2330
Copy link
Contributor Author

@horenso Thx for the triage. Looking forward to a PR.

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

2 participants