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

Integrate better with bindgen #68

Closed
eqrion opened this issue Oct 16, 2017 · 4 comments
Closed

Integrate better with bindgen #68

eqrion opened this issue Oct 16, 2017 · 4 comments

Comments

@eqrion
Copy link
Collaborator

eqrion commented Oct 16, 2017

Currently if you need to define an item in C/C++ and use it from Rust, you can use rust-bindgen and it will output the Rust definition for you.

This is problematic if that type needs to be used in a Rust FFI boundary, as cbindgen will try to output a second C/C++ definition for that type, which will cause errors.

I believe that if cbindgen is run before bindgen, we'll do the right thing and not output a definition for those items, but you will need to ensure you include the proper C/C++ files before the generated header.

I just added an annotation no-export which will prevent a type from being given a definition in the output header, which can help with this, but isn't optimal.

@eqrion
Copy link
Collaborator Author

eqrion commented Oct 16, 2017

I think an optimal solution could be:

# config.rs
[rust-bindgen]
mod = "generated"
header = "source.h"

We would then flag every item in mod generated as being from rust-bindgen and not give them definitions. We could then add an include to the output header for the header rust-bindgen generated from.

This depends on refactoring rustlib.rs to expose what mod items are from, which I've been meaning to do for a while.

@Gankra
Copy link
Contributor

Gankra commented Oct 16, 2017

If cbindgen finds an undefined type, it will just ignore it, instead of failing?

@eqrion
Copy link
Collaborator Author

eqrion commented Oct 16, 2017

It will generate a warning in the console, but it won't fail to generate a header. In the future it might.

If you want to use this to not generate a definition for a type, you'll need some way of hiding it from cbindgen but not from rustc. Or maybe generating the definitition after cbindgen runs.

@eqrion
Copy link
Collaborator Author

eqrion commented Aug 18, 2018

I'm going to close this now as it's not clear what action is required here.

@eqrion eqrion closed this as completed Aug 18, 2018
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

2 participants