-
Notifications
You must be signed in to change notification settings - Fork 706
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
Start emitting unions in stable mode #832
Comments
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the If you intend to work on this issue, then add |
Currently, we have a Bindgen code: #[allow(non_camel_case_types)]
#[derive(Debug)]
enum RustVersion {
Stable_1_0,
Stable_1_15,
Stable_1_20,
Nightly,
}
const LATEST_STABLE: RustVersion = RustVersion::Stable_1_20; Use case: let bindings = bindgen::Builder::default()
.rust_version(RustSupport::Stable_1_15) // Specify Rust version here
.header("wrapper.h")
.generate()
.expect("Unable to generate bindings"); This would allow users to upgrade bindgen versions without getting breaking changes in the generated Rust code (like using unions unless nightly or >= Stable 1.19). This may be more trouble than it's worth. Thoughts? |
@highfive: assign me |
Hey @tmfink! Thanks for your interest in working on this issue. It's now assigned to you! |
I think this is a good idea. That said, I'd nitpick the enum to be something like: pub enum TargetRust {
// As far as available features goes, no difference between stable 1.X and
// beta 1.X from our perspective...
//
// (major, minor)
StableAndBeta(u8, u8),
// Everything else...
Nightly
} Although ideally we would be able to turn individual nightly features on and off too. I suppose we could make the nightly variant be a struct variant with a bool for each feature? |
And thanks for picking this up @tmfink ! Let me know if you have any questions :) |
No problem @fitzgen! I would prefer that
As for implementation, I think the interface should accept a I think that Another small detail: if we go with |
Note that emitting I'd personally like to keep unions not the default, but I guess I can bite the bullet if needed. |
@emilio I feel like the language support of |
Yeah, I guess that's fair. |
Regarding feature flags and rust target versions: I think we really want to keep this as simple as possible to avoid the explosion of potential bugs from every combination of features. I agree we want to have a notion of the target rust version/channel and its supported features, but we should just do the minimum that achieves that IMO. Regarding impl ::std::fmt::Debug for Elephant {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "Elephant {{ ... }}")
}
} is likely good enough. |
Feature 832 custom rust target Addresses #832. Instead of specifying whether or not to use stable, specify the Rust release to support (one of several stable/beta releases or nightly). The `--unstable-rust` option is still accepted and implies `--rust-target nightly`. The definitions of `RustTarget` and `RustFeatures` are created with macros. In order to keep the test outputs the same, `bindgen-flags: --rust-target 1.0` was added to test headers. **Todo:** - [x] Create `RustFeatures`/`RustTarget` structs - [x] Replace uses of `unstable` with `RustFeatures` query - [x] Add new tests - [x] Fix doc comments TODOs
Fixed in #859 |
We still need to update the book chapter on unions. |
Re-add --rust-target option to replace --unstable-rust Re-apply commit. Addresses #832 Instead of specifying whether or not to use stable, specify the Rust release to support (one of several stable/beta releases or nightly). The `--unstable-rust` option is still accepted and implies nightly. The definitions of `RustTarget` and `RustFeatures` are created with macros. For each test that uses unions, there is a version that uses the latest stable and 1.0.
@fitzgen I am working on the Using the Union Types Generated by Bindgen chapter of the user's guide. |
Addresses rust-lang#832
Addresses rust-lang#832
Update doc for unions Addresses #832 I also modified the `--help` text to print the default Rust target.
Awesome, thanks! 👍 |
They're in stable now: https://blog.rust-lang.org/2017/07/20/Rust-1.19.html
Basically, we can go through all of the places where we check
ctx.options().unstable_rust
and use that to decide whether to use unions or not, and just always use the unions. We can also get rid of theBindgenUnion
type now.And finally, we can update the user guide's section on using unions.
I'm happy to mentor anyone who wants to pick this up.
The text was updated successfully, but these errors were encountered: