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

Exported statics aren't declared in the generated header #47

Closed
Ortham opened this issue Aug 31, 2017 · 7 comments
Closed

Exported statics aren't declared in the generated header #47

Ortham opened this issue Aug 31, 2017 · 7 comments

Comments

@Ortham
Copy link

Ortham commented Aug 31, 2017

I've got some Rust code looking like this:

#[no_mangle]
pub static LIBLO_OK: c_uint = 0;

#[no_mangle]
pub static LIBLO_ERROR_INVALID_ARGS: c_uint = 12;

These are used as return codes for some of my API functions, but when cbindgen runs it doesn't include their declarations in the header. I'd expect it to include them like this:

extern unsigned int LIBLO_OK;
extern unsigned int LIBLO_ERROR_INVALID_ARGS;

If I add the above block to cbindgen's trailer config string, I can then use the constants in the C code that calls my library, but isn't this the sort of thing that cbindgen should be doing automatically?

@eqrion
Copy link
Collaborator

eqrion commented Sep 1, 2017

Yeah cbindgen should definitely be able to handle this.

Finding static declarations won't be too challenging, the harder part is knowing which ones to output. Right now we only output declarations that are using by the FFI, but that won't work here.

I suppose we could just output all static items with #[no_mangle] as they are all probably meant to be exported.

@Ortham
Copy link
Author

Ortham commented Sep 1, 2017

I suppose we could just output all static items with #[no_mangle] as they are all probably meant to be exported.

That's the behaviour I'd expect, I don't know of any reason for not mangling names other than for FFI export.

@RazrFalcon
Copy link
Contributor

@eqrion what about const?

@Michael-F-Bryan
Copy link
Contributor

@eqrion what about const?

I was about to open an issue for this, but looks like it's already been mentioned. I reckon const statements should be converted to a #define. This'll work fine for integers and strings, but I haven't put much thought into more complex types...

@RazrFalcon
Copy link
Contributor

At least numbers support will be fine for now.

@eqrion
Copy link
Collaborator

eqrion commented Oct 19, 2017

Fixed in 0.1.27. Please reopen if you're still having an issue with this.

@eqrion eqrion closed this as completed Oct 19, 2017
@Ortham
Copy link
Author

Ortham commented Oct 19, 2017

Thanks 👍

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

No branches or pull requests

4 participants