Skip to content

Commit

Permalink
Add all other rustc_version fields
Browse files Browse the repository at this point in the history
  • Loading branch information
danielschemmel committed May 20, 2020
1 parent cbcbfb2 commit ef3c9f5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
target
Cargo.lock
97 changes: 0 additions & 97 deletions Cargo.lock

This file was deleted.

5 changes: 5 additions & 0 deletions versionator-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ edition = "2018"

[dependencies]
derive-new = "0.5"
semver = { version = "0.9", optional = true }

[features]
default = ["with-semver"]
with-semver = ["semver"]
14 changes: 13 additions & 1 deletion versionator-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
pub use semver::Version;

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Version<'a> {
pub struct BuildInfo<'a> {
pub compiler: CompilerVersion<'a>,
}

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct CompilerVersion<'a> {
pub version_str: &'a str,
pub commit_hash: Option<&'a str>,
pub commit_date: Option<&'a str>,
pub channel: CompilerChannel,
pub host_triple: &'a str,
pub target_triple: &'a str,
}

#[cfg(feature = "semver")]
impl<'a> CompilerVersion<'a> {
pub fn version(&self) -> Version {
Version::parse(self.version_str).unwrap()
}
}

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum CompilerChannel {
Dev,
Expand Down
21 changes: 19 additions & 2 deletions versionator-proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ fn compiler_version() -> proc_macro2::TokenStream {

let version = version_meta().unwrap();

let semver = version.semver.to_string();

let commit_hash = if let Some(commit_hash) = version.commit_hash {
quote!(Some(#commit_hash))
} else {
quote!(None)
};

let commit_date = if let Some(commit_date) = version.commit_date {
quote!(Some(#commit_date))
} else {
quote!(None)
};

let channel = match version.channel {
Channel::Stable => quote!(versionator::CompilerChannel::Stable),
Channel::Beta => quote!(versionator::CompilerChannel::Beta),
Expand All @@ -18,6 +32,9 @@ fn compiler_version() -> proc_macro2::TokenStream {
let target_triple = env!("TARGET_TRIPLE");

quote!(versionator::CompilerVersion{
version_str: #semver,
commit_hash: #commit_hash,
commit_date: #commit_date,
channel: #channel,
host_triple: #host_triple,
target_triple: #target_triple,
Expand All @@ -30,11 +47,11 @@ pub fn versionator(id: TokenStream) -> TokenStream {
let compiler_version = compiler_version();

let output = quote!(
static #id: versionator::Version = versionator::Version{
static #id: versionator::BuildInfo = versionator::BuildInfo{
compiler: #compiler_version
};
);

// println!("{:?}", output.to_string());
println!("{}", output.to_string());
output.into()
}

0 comments on commit ef3c9f5

Please sign in to comment.