-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Version-typed cfgs #3905
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
base: master
Are you sure you want to change the base?
Version-typed cfgs #3905
Conversation
weiznich
left a comment
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.
Overall I linke the idea, but I have some questions and remarks
(Obvious disclaimer: I'm not associated with any team, that's just my personal opinion, so feel free to ignore that)
RFCs are the place for community feedback. Insight from future feature users that aren't team members is just as (if not more) valuable, and always welcome in all discussion areas ❤️ |
860a935 to
11de2c7
Compare
This reverts commit 11de2c7. It had some in-progress changes I didn't mean to commit.
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 picking this up!
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Ed Page <eopage@gmail.com>
This RFC proposes a general mechanism for version-based conditional compilation called "typed cfgs".
Summary
This RFC proposes "typed
cfgs", a new form of conditional compilation predicate that understands types. Initially, this RFC proposes to add support for version-typedcfgs, allowing for ergonomic version comparisons against the language version supported by the compiler. This would be exposed through two new built-incfgnames:rust_version, which can be compared against a language version literal, e.g.,#[cfg(rust_version >= "1.85")].rust_edition, which can be compared against an edition literal, e.g.,#[cfg(rust_edition >= "2024")].This design solves a long-standing problem of conditionally compiling code for different Rust versions without requiring build scripts or forcing libraries to increase their Minimum Supported Rust Version (MSRV). It also replaces the
cfg(version(..))part of RFC 2523.History
There have been several previous attempts to solve the problem of conditional compilation by Rust version.
#[cfg(version(..))]. However, it left the syntax as an open question. Attempts to stabilize it were blocked because the new syntax would be a hard error on older compilers, defeating the goal of supporting older MSRVs.#[cfg(version_since(rust, "1.95"))]for Rust-version conditional compilation #3857 proposed#[cfg(version_since(rust, ...))], which solved the MSRV problem and generalized the mechanism beyond Rust versions while defining the interaction with command line flags like--check-cfg.This RFC takes the lessons from both previous attempts. It proposes a path to the ergonomic
rust_version >= "..."syntax that was preferred during language team discussions, while providing a clear MSRV-compatibility story from day one.The RFC also incorporates use cases from the
cfg_target_versionRFC (#3750), which proposed a way to compare against the version of the target platform's SDK (e.g.,#[cfg(target_version(macos >= "10.15"))]). Version-typed cfgs provide a path to supporting these comparions.Finally, it takes cues from previous discussions around mutually exclusive features and a
cfg_value!()macro, and lays out a path toward more single-valued config types that could support these features.Rendered