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:
Jason Volk
2025-06-12 21:32:35 +00:00
parent 5799059196
commit b0b441d534
4 changed files with 109 additions and 0 deletions

View File

@@ -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()
}