-
-
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.
Support for version-based code generation
- Loading branch information
Showing
7 changed files
with
328 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.