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

bindgen generates a static mut where a const is expected #1316

Closed
alex opened this issue May 19, 2018 · 4 comments
Closed

bindgen generates a static mut where a const is expected #1316

alex opened this issue May 19, 2018 · 4 comments

Comments

@alex
Copy link
Member

alex commented May 19, 2018

Input C/C++ Header

#define __GFP_IO                0x40u
#define GFP_KERNEL (__GFP_IO)

const unsigned BINDING_GFP_KERNEL = GFP_KERNEL;

Bindgen Invocation

$ bindgen t.h

Actual Results

/* automatically generated by rust-bindgen */

pub const __GFP_IO: u32 = 64;
pub const GFP_KERNEL: u32 = 64;
extern "C" {
    #[link_name = "\u{1}BINDING_GFP_KERNEL"]
    pub static mut BINDING_GFP_KERNEL: ::std::os::raw::c_uint;
}

Expected Results

I expected BINDING_GFP_KERNEL to be generated as pub const BINDING_GFP_KERNEL = ...

@emilio
Copy link
Contributor

emilio commented May 19, 2018

Which versión of libclang is this using? I'd expect clang 4.0+ to generate the expected results

@alex
Copy link
Member Author

alex commented May 19, 2018

wontfix per discussion on IRC

@alex alex closed this as completed May 19, 2018
@WiSaGaN
Copy link
Contributor

WiSaGaN commented Mar 3, 2019

Any detailed explanation for the won't fix? Was it the use of a wrong libclang?

@geofft
Copy link
Contributor

geofft commented Mar 3, 2019

Yes. From my IRC logs, Alex was asked, "which libclang version are you using? Clang <= 3.9 doesn't offer APIs to resolve the actual values of constants, so we fall back to the following most likely thing to work which isn't really that great," to which he replied 3.8 and said using a newer version from https://apt.llvm.org fixed the bug. (If you're on Debian/Ubuntu, apt.llvm.org is a reasonable place to get things and is run by the same folks who package LLVM in Debian.)

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

4 participants