-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: #[cfg(version_since(rust, "1.95"))]
for Rust-version conditional compilation
#3857
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
Changes from 1 commit
4dbd2d2
ecb3459
236f2a5
2ee3718
20233b0
3d827bc
a24a6a4
5a7c0e9
d392d50
e51caf2
cb8acba
a1a8164
c5e9d5f
465cecc
0fed553
3a7609a
55a7632
545ef52
4352a95
c0a7dc4
ce77858
7ba5578
0d7f46c
b2e8cdb
50e6949
2348d45
6f656d5
21b8dc0
ee1c8cf
ec2e54c
96ffa15
a07e1c6
c386700
741f854
5ee6b1e
95c2998
1b8355a
0ab2847
f1dedc5
7139923
e71bdc1
c12e4a4
28b52e1
b445f73
5eef426
9da21e1
d27c10d
0a839bd
005c608
5d01721
e036b23
940b979
b37fe10
2c3cbe4
75c486b
602eec6
e352338
995eeed
c7ebc40
679116a
5accada
19dca3e
12f6745
303bb64
4347c60
53e0d39
8a57b6b
97d86b6
6241a5d
955a11e
3e89ae8
e544016
3e632bf
5b9fefe
1024808
4031627
2bbed78
56305c3
7561a72
fed559b
459c87b
dbbcab4
bc71f84
94d2438
b3b7c76
be317a1
851d2ed
f461c5b
102adb1
83a393c
fb896af
18a9594
f3b4a69
ae5822c
6b7ec78
1589434
cab1e93
674ec04
be94add
79f50aa
3f765c1
56ddfc3
3519b83
b3bff0f
b4338cb
6703ecd
ff3f075
ce9390b
d089ddd
4551bbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,6 +533,65 @@ so we do not include that information. | |
|
||
## Alternative designs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From @kornelski at #3857 (comment)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From @tmandry at #3857 (comment)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From @traviscross at #3857 (comment)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've covered binary operators and types in 674ec04. This greatly enlarges the scope of this RFC which has me worried about this being available in a reasonable time frame and, if we go down this route, I wonder if we should have a short-term solution, like From @traviscross
Keep in mind that Cargo also parses and evaluates the syntax. We'd also have to figure out how concepts like name-only cfg's translates to "rust". |
||
|
||
### `cfg(rust >= "1.95")` | ||
|
||
[RFC #3796](https://github.com/rust-lang/rfcs/pull/3796) | ||
will be allowing operators in addition to predicates and it stands to reason that we can extend that | ||
to version comparisons as well. | ||
|
||
The expression `rust >= "1.95"` without any other changes would be a string comparison and not a version precedence comparison. | ||
We'd need to add the concept of types to cfg. | ||
We could make check-cfg load-bearing by relying on its type information | ||
or we could add coercion functions to cfg. | ||
|
||
So given `--cfg=rust --cfg=rust=version("1.95.0")`, you could do `cfg(rust >= version("1.95"))`. | ||
|
||
With typing, | ||
`cfg_values!` (a future possibility) could evaluate to the given type. | ||
So for `--cfg foo=integer("1')`, `cfg_value!(foo)` would be as if you typed `1`. | ||
|
||
For versions, | ||
as there is no native Rust type, | ||
we'd likely have it evaluate to a `&'static str`. | ||
|
||
[RFC #3796](https://github.com/rust-lang/rfcs/pull/3796) | ||
does not address questions around binary operators, | ||
requiring us to work it out. | ||
For example, are the sides of the operator fully swappable? | ||
If we define all comparisons, would `==` be different than `=`? | ||
How will these operators work in the presence of multiple values or a name-only cfg? | ||
|
||
Would we allow implicit coercion so you can skip the `version` inside of `cfg`, like `cfg(rust >= "1.95")`? | ||
I would suggest not because this would make it harder to catch bugs where | ||
- The `--cfg` is not a version but you thought it was | ||
- The `--cfg` should be a version but `version()` was left off | ||
|
||
Currently, check-cfg does not apply at all to `--cfg` because it is commonly used with `RUSTFLAGS` which | ||
are applied to all packages and would warn that an unknown `IDENTIFIER` is in use for packages that don't care. | ||
We could still skip checking for unknown `IDENTIFIER`s and instead warn on misuse of `IDENTIFIER`s which would increase the chance of catching a mistake (unless a person duplicated there `--cfg` mistake with `--check-cfg`. | ||
|
||
Another is how to handle check-cfg. | ||
The proposed syntax is a binary operator but there is no left-hand side in check-cfg. | ||
Would we accept `cfg(rust, values(>="1.95"))`? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion is to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recorded this in 79f50aa |
||
How would we specify types? Would we replace `values` with `versions`? | ||
|
||
Adding typing to cfg, | ||
while likely something we'll do one day, | ||
greatly enlarges the scope of this RFC. | ||
This makes it harder to properly evaluate each part, | ||
making it more likely we'll make mistakes. | ||
This further delays the feature as the unstable period is likely to be longer. | ||
We also are not ready to evaluate other use cases for typing to evaluate the impact | ||
and likely won't until we move forward with [global features](https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618) | ||
and `cfg_values!`, | ||
allowing us to cover use cases like embedded using [toml_cfg](https://crates.io/crates/toml-cfg). | ||
|
||
If we defer typing, we'll have to allow implicit coercion of values so we can mark `rust` as a version in the future without it being a breaking change. | ||
|
||
If we consider typing the correct long term solution but defer it, | ||
we may want to consider the most narrowly scoped solution in the short term, | ||
like `rust_version("1.95")`. | ||
These "big questions" can then have dedicated issues and versions can be built on top of that. | ||
|
||
### `version(rust, ">=1.95")` | ||
|
||
Instead of having an assumed operator for the predicate, | ||
|
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.
Could we have a vote on the proposed "since" versus the alternative designs?
I personally like them better.
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.
The "vote" will be done by the owning team for this RFC (T-lang). The responsibility for the rest of us is to provide meaningful feedback that can be included for them to review in their evaluation.
Keep in mind though that part of why this RFC came about is concerns that came up during the stabilization of
rust_version(_)
which makes it unlikely we will pivot in that direction.