-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17: Support for version-based code generation r=taiki-e a=taiki-e This rewrites the const_fn attribute to support the following four syntaxes: ```rust use const_fn::const_fn; // 1.36 and later compiler (including beta and nightly) #[const_fn("1.36")] pub const fn version() { /* ... */ } // nightly compiler (including dev build) #[const_fn(nightly)] pub const fn nightly() { /* ... */ } // `cfg(...)` #[const_fn(cfg(...))] pub const fn cfg() { /* ... */ } // `cfg(feature = "...")` #[const_fn(feature = "...")] pub const fn feature() { /* ... */ } ``` 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 Co-authored-by: Taiki Endo <[email protected]>
- Loading branch information
Showing
7 changed files
with
330 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::{env, fs, path::PathBuf}; | ||
|
||
fn main() { | ||
let version = match Version::new() { | ||
Some(version) => format!("{:#?}\n", version), | ||
None => panic!("unexpected output from `rustc --version`"), | ||
}; | ||
|
||
let out_dir = env::var_os("OUT_DIR").map(PathBuf::from).expect("OUT_DIR not set"); | ||
let out_file = out_dir.join("version.rs"); | ||
fs::write(out_file, version).expect("failed to write version.rs"); | ||
} | ||
|
||
#[derive(Debug)] | ||
struct Version { | ||
minor: u16, | ||
patch: u16, | ||
nightly: bool, | ||
} | ||
|
||
impl Version { | ||
fn new() -> Option<Self> { | ||
let (version, channel, _date) = version_check::triple()?; | ||
let (_major, minor, patch) = version.to_mmp(); | ||
let nightly = channel.is_nightly() || channel.is_dev(); | ||
Some(Version { minor, patch, nightly }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.