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

can't not build at aarch64 #121

Closed
z2665 opened this issue Apr 24, 2019 · 3 comments · Fixed by #162
Closed

can't not build at aarch64 #121

z2665 opened this issue Apr 24, 2019 · 3 comments · Fixed by #162

Comments

@z2665
Copy link
Contributor

z2665 commented Apr 24, 2019

I have project need to build for aarch64 Architecture.
when build rust-rdkafka-0.20. I got some error.

 --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:120:76
    |
120 |         unsafe { rdsys::rd_kafka_conf_set_log_cb(native_config.ptr(), Some(native_log_cb::<C>)) };
    |                                                                            ^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `unsafe extern "C" fn(*const rdsys::rd_kafka_s, i32, *const u8, *const u8)`
               found type `unsafe extern "C" fn(*const rdsys::rd_kafka_s, i32, *const i8, *const i8) {client::native_log_cb::<C>}`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:121:78
    |
121 |         unsafe { rdsys::rd_kafka_conf_set_stats_cb(native_config.ptr(), Some(native_stats_cb::<C>)) };
    |                                                                              ^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `unsafe extern "C" fn(*mut rdsys::rd_kafka_s, *mut u8, usize, *mut std::ffi::c_void) -> i32`
               found type `unsafe extern "C" fn(*mut rdsys::rd_kafka_s, *mut i8, usize, *mut std::ffi::c_void) -> i32 {client::native_stats_cb::<C>}`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:122:78
    |
122 |         unsafe { rdsys::rd_kafka_conf_set_error_cb(native_config.ptr(), Some(native_error_cb::<C>)) };
    |                                                                              ^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `unsafe extern "C" fn(*mut rdsys::rd_kafka_s, i32, *const u8, *mut std::ffi::c_void)`
               found type `unsafe extern "C" fn(*mut rdsys::rd_kafka_s, i32, *const i8, *mut std::ffi::c_void) {client::native_error_cb::<C>}`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:125:74
    |
125 |             rdsys::rd_kafka_new(rd_kafka_type, native_config.ptr_move(), errstr.as_ptr() as *mut i8, errstr.len())
    |                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*mut u8`
               found type `*mut i8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:274:30
    |
274 |     let fac = CStr::from_ptr(fac).to_string_lossy();
    |                              ^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:275:38
    |
275 |     let log_message = CStr::from_ptr(buf).to_string_lossy();
    |                                      ^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/client.rs:309:33
    |
309 |     let reason = CStr::from_ptr(reason).to_string_lossy();
    |                                 ^^^^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/config.rs:154:44
    |
154 |                                            errstr.as_ptr() as *mut i8, errstr.len())
    |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*mut u8`
               found type `*mut i8`

error[E0308]: mismatched types
  --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/consumer/mod.rs:54:52
   |
54 |                 let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(err)) };
   |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i8, found u8
   |
   = note: expected type `*const i8`
              found type `*const u8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/consumer/base_consumer.rs:179:48
    |
179 |             let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(ret_code)) };
    |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i8, found u8
    |
    = note: expected type `*const i8`
               found type `*const u8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/consumer/base_consumer.rs:192:48
    |
192 |             let error = unsafe { cstr_to_owned(rdsys::rd_kafka_err2str(ret_code)) };
    |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i8, found u8
    |
    = note: expected type `*const i8`
               found type `*const u8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/util.rs:106:20
    |
106 |     CStr::from_ptr(bytes_cstr.as_ptr()).to_string_lossy().into_owned()
    |                    ^^^^^^^^^^^^^^^^^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`

error[E0308]: mismatched types
   --> /root/.cargo/registry/src/mirrors.ustc.edu.cn-b63e9dae659fc205/rdkafka-0.20.0/src/util.rs:111:20
    |
111 |     CStr::from_ptr(cstr).to_string_lossy().into_owned()
    |                    ^^^^ expected u8, found i8
    |
    = note: expected type `*const u8`
               found type `*const i8`

error: aborting due to 13 previous errors

@flavray
Copy link
Collaborator

flavray commented Apr 25, 2019

I've done some digging. It seems to come from the definition of c_char.
For most architectures, it's mapped to be i8. For some architectures however (like aarch64), it's mapped to u8.

It may just be a matter of casting all of these with as ::std::os::raw::c_char. I'll try to get this fixed asap!

@z2665 z2665 mentioned this issue Jul 9, 2019
@z2665
Copy link
Contributor Author

z2665 commented Jul 9, 2019

@flavray I try to solve this problem. use the as ::std::os::raw::c_char.
my way may not the best. but it can build in aarch64 Architecture now.

@AlexanderThaller
Copy link
Contributor

I have the same problem for armv7. The pull request seems to fix it.

dlorenc added a commit to dlorenc/sudo-rs that referenced this issue Jul 5, 2023
When I built on arm (aarch64), I got this compiler error:

```
   Compiling sudo-rs v0.2.0-dev.20230703 (/sudo-rs)
error[E0308]: mismatched types
   --> src/pam/mod.rs:217:44
    |
217 |         let cstr = unsafe { CStr::from_ptr(data as *const i8) };
    |                             -------------- ^^^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |                             |
    |                             arguments to this function are incorrect
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: associated function defined here
   --> /home/build/rustc-1.70.0-src/library/core/src/ffi/c_str.rs:260:25

For more information about this error, try `rustc --explain E0308`.
```

After some research, I learned that this is an architecture issue - on many platforms char is mapped to i8, but not on aarch64.
Here's a source: fede1024/rust-rdkafka#121

With this change it now builds successfully on arm!

Signed-off-by: Dan Lorenc <dlorenc@chainguard.dev>
dlorenc added a commit to dlorenc/sudo-rs that referenced this issue Jul 5, 2023
When I built on arm (aarch64), I got this compiler error:

```
   Compiling sudo-rs v0.2.0-dev.20230703 (/sudo-rs)
error[E0308]: mismatched types
   --> src/pam/mod.rs:217:44
    |
217 |         let cstr = unsafe { CStr::from_ptr(data as *const i8) };
    |                             -------------- ^^^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
    |                             |
    |                             arguments to this function are incorrect
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`
note: associated function defined here
   --> /home/build/rustc-1.70.0-src/library/core/src/ffi/c_str.rs:260:25

For more information about this error, try `rustc --explain E0308`.
```

After some research, I learned that this is an architecture issue - on many platforms char is mapped to i8, but not on aarch64.
Here's a source: fede1024/rust-rdkafka#121

With this change it now builds successfully on arm!

Signed-off-by: Dan Lorenc <dlorenc@chainguard.dev>
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

Successfully merging a pull request may close this issue.

3 participants