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

c_void Libc::unix conflicts with core::ffi #274

Closed
ghost opened this issue Nov 23, 2019 · 3 comments
Closed

c_void Libc::unix conflicts with core::ffi #274

ghost opened this issue Nov 23, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 23, 2019

Using rules_rust it seems, that libc::unix::c_void conflicts with core::ffi::c_void type. This used to be the case but according to this the rfc was merged where libc re-exports core::ffi types from November 2018.

I am seeing this problem trying to compile libbacktrace which is a transient dependency for tonic crate. I am seeing the following errors

error[E0308]: mismatched types
   --> external/raze__backtrace__0_3_40/src/symbolize/libbacktrace.rs:100:45
    |
100 |             Symbol::Dladdr(ref s) => return s.addr(),
    |                                             ^^^^^^^^ expected enum `libc::unix::c_void`, found enum `core::ffi::c_void`
    |
    = note: expected type `core::option::Option<*mut libc::unix::c_void>`
               found type `core::option::Option<*mut core::ffi::c_void>`

Any ideas if this is a known behavior of rules_rust?

@ghost
Copy link
Author

ghost commented Nov 23, 2019

Sovled. Compiling libc in context of rules_rust require the following flags

    "--cfg=libc_priv_mod_use",
    "--cfg=libc_union",
    "--cfg=libc_const_size_of",
    "--cfg=libc_core_cvoid",
    "--cfg=libc_align",
    "--cfg=libc_packedN",

Hope this helps somehow.

@ghost ghost closed this as completed Nov 23, 2019
@sholokhov
Copy link

Hi @Sythanis !
I'm still getting this error (macOS 10.15.4, Bazel 3.0.0, rules_rust a1d8936161beddadddd17d2b1c335ceac77d1d53) when trying to build backtrace as a transitive dependency:

error[E0308]: mismatched types
   --> external/raze__backtrace__0_3_46/src/symbolize/libbacktrace.rs:100:45
    |
96  |     pub fn addr(&self) -> Option<*mut c_void> {
    |                           ------------------- expected `core::option::Option<*mut libc::unix::c_void>` because of return type
...
100 |             Symbol::Dladdr(ref s) => return s.addr(),
    |                                             ^^^^^^^^ expected enum `libc::unix::c_void`, found enum `core::ffi::c_void`
    |
    = note: expected type `core::option::Option<*mut libc::unix::c_void>`
               found type `core::option::Option<*mut core::ffi::c_void>`

error[E0308]: mismatched types
   --> external/raze__backtrace__0_3_46/src/symbolize/libbacktrace.rs:451:32
    |
451 |         return dladdr_fallback(what.address_or_ip(), cb);
    |                                ^^^^^^^^^^^^^^^^^^^^ expected enum `libc::unix::c_void`, found enum `core::ffi::c_void`
    |
    = note: expected type `*mut libc::unix::c_void`
               found type `*mut core::ffi::c_void`

error[E0308]: mismatched types
   --> external/raze__backtrace__0_3_46/src/symbolize/libbacktrace.rs:479:25
    |
479 |         dladdr_fallback(what.address_or_ip(), cb);
    |                         ^^^^^^^^^^^^^^^^^^^^ expected enum `libc::unix::c_void`, found enum `core::ffi::c_void`
    |
    = note: expected type `*mut libc::unix::c_void`
               found type `*mut core::ffi::c_void`

error[E0308]: mismatched types
   --> external/raze__backtrace__0_3_46/src/symbolize/libbacktrace.rs:484:21
    |
484 |     dladdr::resolve(addr, &mut |sym| {
    |                     ^^^^ expected enum `core::ffi::c_void`, found enum `libc::unix::c_void`
    |
    = note: expected type `*mut core::ffi::c_void`
               found type `*mut libc::unix::c_void`

I've tried to add flags that you've mentioned in Cargo.toml like this (not sure if it's correct since I'm quite new to rules_rust):

[raze.crates.backtrace.'0.3.46']
additional_flags = [
  "--cfg=libc_priv_mod_use",
  "--cfg=libc_union",
  "--cfg=libc_const_size_of",
  "--cfg=libc_core_cvoid",
  "--cfg=libc_align",
  "--cfg=libc_packedN",
]

Do you have any thoughts or ideas how to fix it?

@vrusinov
Copy link

@sholokhov and anyone else also wondering: it seems those flags need to be passed to libc. This worked for me:

[raze.crates.libc.'0.2.70']
additional_flags = [
  # https://github.com/bazelbuild/rules_rust/issues/274
  "--cfg=libc_priv_mod_use",
  "--cfg=libc_union",
  "--cfg=libc_const_size_of",
  "--cfg=libc_core_cvoid",
  "--cfg=libc_align",
  "--cfg=libc_packedN",
]

[raze.crates.libc.'0.2.71']
additional_flags = [
  # https://github.com/bazelbuild/rules_rust/issues/274
  "--cfg=libc_priv_mod_use",
  "--cfg=libc_union",
  "--cfg=libc_const_size_of",
  "--cfg=libc_core_cvoid",
  "--cfg=libc_align",
  "--cfg=libc_packedN",
]

This issue was closed.
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