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

Feature 832 custom rust target #859

Merged
merged 1 commit into from
Aug 4, 2017

Conversation

tmfink
Copy link
Contributor

@tmfink tmfink commented Jul 27, 2017

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:

  • Create RustFeatures/RustTarget structs
  • Replace uses of unstable with RustFeatures query
  • Add new tests
  • Fix doc comments TODOs

@tmfink
Copy link
Contributor Author

tmfink commented Jul 30, 2017

r? @fitzgen or @emilio

@bors-servo
Copy link

☔ The latest upstream changes (presumably #861) made this pull request unmergeable. Please resolve the merge conflicts.

@fitzgen
Copy link
Member

fitzgen commented Aug 1, 2017

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 :)

@bors-servo
Copy link

☔ The latest upstream changes (presumably #874) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@fitzgen fitzgen left a 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; )* ) => {
Copy link
Member

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;
);

Copy link
Contributor Author

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> {
Copy link
Member

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

Copy link
Contributor Author

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))";
Copy link
Member

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")]
Copy link
Member

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.")
Copy link
Member

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?

Copy link
Contributor Author

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.

@fitzgen
Copy link
Member

fitzgen commented Aug 3, 2017

One more thing: can you rebase and squash these commits into a single commit on top of master? Thanks!

@bors-servo
Copy link

☔ The latest upstream changes (presumably #866) made this pull request unmergeable. Please resolve the merge conflicts.

@tmfink tmfink force-pushed the feature-832-custom-rust-target branch from ec70f89 to 476d1ea Compare August 4, 2017 09:47
@tmfink
Copy link
Contributor Author

tmfink commented Aug 4, 2017

Looks like there were some issues with my rebase--I'll fix it tomorrow.

@fitzgen
Copy link
Member

fitzgen commented Aug 4, 2017

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.
@tmfink tmfink force-pushed the feature-832-custom-rust-target branch from 476d1ea to 0bb7b9f Compare August 4, 2017 16:52
@tmfink
Copy link
Contributor Author

tmfink commented Aug 4, 2017

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.

@fitzgen
Copy link
Member

fitzgen commented Aug 4, 2017

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};
Copy link
Member

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?

Copy link
Member

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).

@fitzgen
Copy link
Member

fitzgen commented Aug 4, 2017

@bors-servo r+

Thanks @tmfink !

@bors-servo
Copy link

📌 Commit 0bb7b9f has been approved by fitzgen

@bors-servo
Copy link

⌛ Testing commit 0bb7b9f with merge de180c4...

bors-servo pushed a commit that referenced this pull request Aug 4, 2017
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
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: fitzgen
Pushing de180c4 to master...

@bors-servo bors-servo merged commit 0bb7b9f into rust-lang:master Aug 4, 2017
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

Successfully merging this pull request may close these issues.

3 participants