-
Notifications
You must be signed in to change notification settings - Fork 702
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
Refactor RustTarget
#2993
Refactor RustTarget
#2993
Conversation
aa7ba97
to
43d5d32
Compare
43d5d32
to
9117083
Compare
9117083
to
5f6c6cd
Compare
Thanks for this, Christian! Just to confirm: for projects that need to support |
Yes all the previous valid inputs are still valid, e.g. |
Sounds great, thanks for confirming! The |
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.
Would've been nice to send the removal of deprecated targets separately, but looks good! Some minor bits only.
This is done because bindgen is producing bogus code where a single struct has both `packed` and `align` attributes.
5f7c9d5
to
2d68245
Compare
Yes, they'd have to add extra |
This PR refactors the
RustTarget
type to be more flexible.The motivation behind this change comes from the current definition of
RustTarget
as an enum. Which forces users to pick a specific version of Rust that might not match the msrv of their projects exactly.As an example, let's say that a project using bindgen has an msrv of
1.41.1
and they decide to use the--rust-target
flag to guarantee that bindgen won't produce code that breaks their msrv.Given that bindgen doesn't have a
RustTarget
variant that specifically matches1.41.1
, they have to use the closestRustTarget
that is still compatible. In this case that would be1.40
. If they decide to change their msrv in the future, they have to repeat this search process with their new msrv.With the changes done in this PR, it would be possible to pass any* Rust version to
--rust-target
and bindgen will automatically enable the Rust features that are compatible with that version. In our example, that means that it would be possible to use--rust-version=1.41.1
explicitly, or even better, read the value fromrust-version
so they don't have to manually change it in the future.The specific changes done in this PR are:
Replace the
RustTarget
enum for an opaque struct that can represent any* Rust version.Update the
FromStr
implementation forRustTarget
so it can parse any* Rust version.Introduce several deprecated constants under
RustTarget
so people can still use those as if they were still using the variants of the removed enum type.Introduce the builders
RustTarget::nightly
andRustTarget::stable
.Remove all the deprecated
RustTarget
s.Update the expectation tests to accommodate the removal of the deprecated targets.
(*): Unless it's not supported by bindgen anymore. To the date, anything earlier than 1.33 (inclusive)
cc @ojeda