Detailed version string. (closes #62)
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -10,6 +10,9 @@ use std::{
|
||||
|
||||
use crate::utils::exchange;
|
||||
|
||||
// Capture rustc version during compilation.
|
||||
tuwunel_macros::rustc_version! {}
|
||||
|
||||
/// Raw capture of rustc flags used to build each crate in the project. Informed
|
||||
/// by rustc_flags_capture macro (one in each crate's mod.rs). This is
|
||||
/// done during static initialization which is why it's mutex-protected and pub.
|
||||
@@ -23,6 +26,16 @@ static FEATURES: OnceLock<Vec<&'static str>> = OnceLock::new();
|
||||
/// List of features enabled for the project.
|
||||
pub fn features() -> &'static Vec<&'static str> { FEATURES.get_or_init(init_features) }
|
||||
|
||||
/// Version of the rustc compiler used during build.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn version() -> Option<&'static str> {
|
||||
RUSTC_VERSION
|
||||
.len()
|
||||
.gt(&0)
|
||||
.then_some(RUSTC_VERSION)
|
||||
}
|
||||
|
||||
fn init_features() -> Vec<&'static str> {
|
||||
let mut features = Vec::new();
|
||||
FLAGS
|
||||
|
||||
@@ -9,7 +9,8 @@ use std::sync::OnceLock;
|
||||
|
||||
static BRANDING: &str = "Tuwunel";
|
||||
static SEMANTIC: &str = env!("CARGO_PKG_VERSION");
|
||||
tuwunel_macros::git_describe!();
|
||||
tuwunel_macros::git_commit! {}
|
||||
tuwunel_macros::git_semantic! {}
|
||||
|
||||
static VERSION: OnceLock<String> = OnceLock::new();
|
||||
static USER_AGENT: OnceLock<String> = OnceLock::new();
|
||||
@@ -24,17 +25,36 @@ pub fn version() -> &'static str { VERSION.get_or_init(init_version) }
|
||||
#[inline]
|
||||
pub fn user_agent() -> &'static str { USER_AGENT.get_or_init(init_user_agent) }
|
||||
|
||||
fn init_user_agent() -> String { format!("{}/{}", name(), version()) }
|
||||
fn init_user_agent() -> String { format!("{}/{}", name(), semantic()) }
|
||||
|
||||
fn init_version() -> String {
|
||||
option_env!("TUWUNEL_VERSION_EXTRA")
|
||||
.or(option_env!("CONDUWUIT_VERSION_EXTRA"))
|
||||
.or(option_env!("CONDUIT_VERSION_EXTRA"))
|
||||
.map_or(SEMANTIC.to_owned(), |extra| {
|
||||
if extra.is_empty() {
|
||||
SEMANTIC.to_owned()
|
||||
} else {
|
||||
format!("{SEMANTIC} ({extra})")
|
||||
}
|
||||
.map_or_else(detailed, |extra| {
|
||||
extra
|
||||
.is_empty()
|
||||
.then(detailed)
|
||||
.unwrap_or_else(|| format!("{} ({extra})", detailed()))
|
||||
})
|
||||
}
|
||||
|
||||
fn detailed() -> String {
|
||||
let tag_dirty = semantic()
|
||||
.rsplit_once('-')
|
||||
.is_some_and(|(_, s)| !s.is_empty());
|
||||
|
||||
if !GIT_COMMIT.is_empty() && tag_dirty {
|
||||
format!("{} ({})", semantic(), GIT_COMMIT)
|
||||
} else {
|
||||
semantic().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn semantic() -> &'static str {
|
||||
if !GIT_SEMANTIC.is_empty() {
|
||||
GIT_SEMANTIC
|
||||
} else {
|
||||
SEMANTIC
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user