Add macro to get rustc version. (#62)
Add macro to query git-describe. (#62) Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::process::Command;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
@@ -27,3 +29,32 @@ pub(super) fn flags_capture(args: TokenStream) -> TokenStream {
|
||||
|
||||
ret.into()
|
||||
}
|
||||
|
||||
pub(super) fn version(args: TokenStream) -> TokenStream {
|
||||
let Some(_) = get_crate_name() else {
|
||||
return args;
|
||||
};
|
||||
|
||||
let rustc_path = std::env::args()
|
||||
.next()
|
||||
.expect("Path to rustc executable");
|
||||
|
||||
let version = Command::new(rustc_path)
|
||||
.args(["-V"])
|
||||
.output()
|
||||
.map(|output| {
|
||||
str::from_utf8(&output.stdout)
|
||||
.map(str::trim)
|
||||
.map(String::from)
|
||||
.ok()
|
||||
})
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_default();
|
||||
|
||||
let ret = quote! {
|
||||
static RUSTC_VERSION: &'static str = #version;
|
||||
};
|
||||
|
||||
ret.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user