-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support for version-based code generation #17
Conversation
Just for reference, when cfg_version is implemented (if it's not already), the lsng team decided it was best to have nightly be treated as one version prior — essentially the current beta. This is because there's no guarantee that a feature available in a given nightly will land two releases later. I can pull up a reference tomorrow if you'd like, as I'm on mobile right now. I believe I'm remembering it correctly, though. Also, may I suggest you check out the version_check crate? It's widely used and does pretty much the same thing as you're doing in the build script. |
Hmm, I think that discussion has not been finished yet: rust-lang/rust#64796 (comment)
Sounds good. |
4d47247
to
9a416d2
Compare
// 1.36 and later compiler (including beta and nightly) | ||
#[const_fn("1.36")] | ||
pub const fn version() { | ||
/* ... */ |
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.
It currently only accepts string literals as version requirements, like cfg_version does.
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.
Filed #19
// nightly compiler (including dev build) | ||
#[const_fn(nightly)] | ||
pub const fn 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.
To use the nightly only unstable feature, it needs to enable the feature at crate-level, and in any case, it needs build-script. So, this may not be very useful in practice, but I'll keep it for now.
Looks like I must've missed that comment; I just remembered this comment off the top of my head. Changing the behavior would of course be a breaking change, so it's something to be mindful of at the least. Is it common/accepted practice to write details to a file, which is later accessed as part of the compilation process? It's a neat trick, but I don't think I've ever seen it anywhere before. I've always used rustc cfgs, prefixed with something unique to the crate. |
cfgs have no values, so version info should be output another way. (Of course, we can also output a cfg like I don't know how widely it is used, but at least I think bindgen users are using it. |
bors r+ There may be minor bugs and lack of documentation, but I think the implementation is ok with this. |
Build succeeded: |
21: Release 0.4.0 r=taiki-e a=taiki-e Changes: * [Add support for version-based code generation.](#17) The following conditions are available: ```rust use const_fn::const_fn; // function is `const` on specified version and later compiler (including beta and nightly) #[const_fn("1.36")] pub const fn version() { /* ... */ } // function is `const` on nightly compiler (including dev build) #[const_fn(nightly)] pub const fn nightly() { /* ... */ } // function is `const` if `cfg(...)` is true #[const_fn(cfg(...))] pub const fn cfg() { /* ... */ } // function is `const` if `cfg(feature = "...")` is true #[const_fn(feature = "...")] pub const fn feature() { /* ... */ } ``` * Improve compile time by removing proc-macro related dependencies ([#18](#18), [#20](#20)). Co-authored-by: Taiki Endo <[email protected]>
This rewrites the const_fn attribute to support the following four syntaxes:
This does not provide any special support for beta. This is because unlike nighty there are no unstable features (features available in beta are already stabilized, so I think it is preferable to specify that version).
Closes #15