-
Notifications
You must be signed in to change notification settings - Fork 715
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
Feature 832 custom rust target #859
Feature 832 custom rust target #859
Conversation
☔ The latest upstream changes (presumably #861) made this pull request unmergeable. Please resolve the merge conflicts. |
I meant to review this yesterday, but didn't end up with enough time. I'll do my best to get to it today! Thanks for the patience @tmfink :) |
☔ The latest upstream changes (presumably #874) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This turned out really nice, and was way less invasive than I feared it might have been :)
I have a couple nitpicks below, and then we can merge this :)
Thanks! And sorry for the delay!
src/features.rs
Outdated
/// Define RustTarget struct definition, Default impl, and conversions | ||
/// between RustTarget and String. | ||
macro_rules! rust_target_def { | ||
( $( $release:ident => $value:expr => $attrs:meta; )* ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more natural with the attrs in the front:
( $( $(#[$attr:meta])* $release:ident => $value:expr ; )* ) => { ... }
And then we could use it like this:
rust_target_def!(
/// Rust stable 1.0
Stable_1_0 => 1.0;
/// Rust stable 1.19
Stable_1_19 => 1.19;
/// Nightly rust
Nightly => nightly;
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I didn't realize you could do that.
src/features.rs
Outdated
/// * The stable/beta versions of Rust are of the form "1.0", | ||
/// "1.19", etc. | ||
/// * The nightly version should be specified with "nightly". | ||
pub fn from_str<'a>(s: &'a str) -> io::Result<RustTarget> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be impl FromStr for RustTarget
: https://doc.rust-lang.org/nightly/std/str/trait.FromStr.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I did not know that existed.
src/features.rs
Outdated
|
||
rust_feature_def!( | ||
untagged_union => doc="Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md))"; | ||
const_fn => doc="Constant function ([RFC 911](https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md))"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the above comment: this would read a lot more naturally if the macro was refactored so that we could use normal doc comment sugar.
pub fn unstable_rust(mut self, doit: bool) -> Self { | ||
self.options.unstable_rust = doit; | ||
self | ||
#[deprecated(note="please use `rust_target` instead")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this detail :)
src/options.rs
Outdated
@@ -161,6 +161,10 @@ pub fn builder_from_flags<I> | |||
.takes_value(true) | |||
.multiple(true) | |||
.number_of_values(1), | |||
Arg::with_name("rust-target") | |||
.long("rust-target") | |||
.help("Version of the Rust compiler to target.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should list either
-
The exact set of supported target versions (as the string one would give to this flag). This would involve getting a string out of the macro somehow.
-
or we should define a
RustTarget
for every stable version of rust, and have an example of targeting a stable version and an example of targeting nightly here.
What we shouldn't do is leave users to guess how to format the string: is it "1.19" or "stable-1.19" or "stable" or "stable 1.19" or ...?? And if "1.19" works, then why doesn't "1.18" work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to use the macros.
One more thing: can you rebase and squash these commits into a single commit on top of master? Thanks! |
☔ The latest upstream changes (presumably #866) made this pull request unmergeable. Please resolve the merge conflicts. |
ec70f89
to
476d1ea
Compare
Looks like there were some issues with my rebase--I'll fix it tomorrow. |
Ok! Let me know if you have any questions or need any help or anythign :) |
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 release and stable 1.0.
476d1ea
to
0bb7b9f
Compare
I squashed everything, but the downside is that it lost "git copy" trick that I used to keep the provenance of the "1.0" tests. Now Git thinks that I made the headers/expectations from scratch. |
While that's too bad, ultimately, I don't think it's a huge deal. |
@@ -80,6 +82,8 @@ mod codegen { | |||
include!(concat!(env!("OUT_DIR"), "/codegen.rs")); | |||
} | |||
|
|||
pub use features::{RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see RUST_TARGET_STRINGS
used in this module, is it a leftover from some earlier iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, well there are no warnings in the travis ci compilation (and I guess we deny(warnings) anyhow).
@bors-servo r+ Thanks @tmfink ! |
📌 Commit 0bb7b9f has been approved by |
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
☀️ Test successful - status-travis |
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
andRustFeatures
are created withmacros.
In order to keep the test outputs the same,
bindgen-flags: --rust-target 1.0
was added to test headers.Todo:
RustFeatures
/RustTarget
structsunstable
withRustFeatures
query