Cleanup rustc_tool_util and add a convenient macro for build.rs
This commit is contained in:
@@ -2,19 +2,21 @@
|
||||
|
||||
use std::env;
|
||||
|
||||
/// This macro creates the version string during compilation from the
|
||||
/// current environment
|
||||
#[macro_export]
|
||||
macro_rules! get_version_info {
|
||||
() => {{
|
||||
let major = env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
|
||||
let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
|
||||
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
||||
let crate_name = String::from(env!("CARGO_PKG_NAME"));
|
||||
let major = std::env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
|
||||
let minor = std::env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
|
||||
let patch = std::env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
||||
let crate_name = String::from(std::env!("CARGO_PKG_NAME"));
|
||||
|
||||
let host_compiler = option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
|
||||
let commit_hash = option_env!("GIT_HASH").map(str::to_string);
|
||||
let commit_date = option_env!("COMMIT_DATE").map(str::to_string);
|
||||
let host_compiler = std::option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
|
||||
let commit_hash = std::option_env!("GIT_HASH").map(str::to_string);
|
||||
let commit_date = std::option_env!("COMMIT_DATE").map(str::to_string);
|
||||
|
||||
VersionInfo {
|
||||
$crate::VersionInfo {
|
||||
major,
|
||||
minor,
|
||||
patch,
|
||||
@@ -26,6 +28,24 @@ macro_rules! get_version_info {
|
||||
}};
|
||||
}
|
||||
|
||||
/// This macro can be used in `build.rs` to automatically set the needed
|
||||
/// environment values, namely `GIT_HASH`, `COMMIT_DATE` and
|
||||
/// `RUSTC_RELEASE_CHANNEL`
|
||||
#[macro_export]
|
||||
macro_rules! setup_version_info {
|
||||
() => {{
|
||||
println!(
|
||||
"cargo:rustc-env=GIT_HASH={}",
|
||||
$crate::get_commit_hash().unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=COMMIT_DATE={}",
|
||||
$crate::get_commit_date().unwrap_or_default()
|
||||
);
|
||||
println!("cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", $crate::get_channel());
|
||||
}};
|
||||
}
|
||||
|
||||
// some code taken and adapted from RLS and cargo
|
||||
pub struct VersionInfo {
|
||||
pub major: u8,
|
||||
|
||||
Reference in New Issue
Block a user