use std::sync::Once;
use log::info;
static LOG_ONCE: Once = Once::new();
include!(concat!(env!("OUT_DIR"), "/built.rs"));
pub struct BuildInfo {
pub wasm_runtime_created: &'static str,
pub wasm_runtime_size: &'static str,
pub wasm_runtime_blake3_hash: &'static str,
pub wasm_runtime_wasmtime_version: &'static str,
pub package_name: &'static str,
pub package_version: &'static str,
pub features: Vec<&'static str>,
pub target: &'static str,
pub opt_level: &'static str,
pub profile: &'static str,
pub debug: bool,
pub rustc: &'static str,
pub built_time_utc: &'static str,
pub ci_platform: Option<&'static str>,
pub git_commit_hash: Option<&'static str>,
pub git_head_ref: Option<&'static str>,
pub git_version: Option<&'static str>,
pub git_dirty: bool,
}
impl Default for BuildInfo {
fn default() -> Self {
let mut features: Vec<&str> = Vec::new();
for feature in FEATURES {
features.push(feature);
}
Self {
wasm_runtime_created: WASM_RUNTIME_CREATED,
wasm_runtime_size: WASM_RUNTIME_SIZE,
wasm_runtime_blake3_hash: WASM_RUNTIME_BLAKE3_HASH,
wasm_runtime_wasmtime_version: WASM_RUNTIME_WASMTIME_VERSION,
package_name: PKG_NAME,
package_version: PKG_VERSION,
features,
target: TARGET,
opt_level: OPT_LEVEL,
profile: PROFILE,
debug: DEBUG,
rustc: RUSTC,
built_time_utc: BUILT_TIME_UTC,
ci_platform: CI_PLATFORM,
git_commit_hash: GIT_COMMIT_HASH,
git_head_ref: GIT_HEAD_REF,
git_version: GIT_VERSION,
git_dirty: GIT_DIRTY.unwrap_or(false),
}
}
}
impl BuildInfo {
pub fn get() -> Self {
Self::default()
}
pub(crate) fn log() {
Self::default().log_build_details();
}
fn log_build_details(&self) {
LOG_ONCE.call_once(|| {
info!("{}", self);
});
}
pub(crate) fn get_wasmtime_version() -> &'static str {
WASM_RUNTIME_WASMTIME_VERSION
}
}
impl std::fmt::Display for BuildInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(
f,
"hyperlight-wasm-runtime created at: {}",
self.wasm_runtime_created
)?;
writeln!(
f,
"hyperlight-wasm-runtime size: {}",
self.wasm_runtime_size
)?;
writeln!(
f,
"hyperlight-wasm-runtime hash: {}",
self.wasm_runtime_blake3_hash
)?;
writeln!(
f,
"hyperlight-wasm-runtime wasmtime version: {}",
self.wasm_runtime_wasmtime_version
)?;
writeln!(f, "Package name: {}", self.package_name)?;
writeln!(f, "Package version: {}", self.package_version)?;
writeln!(f, "Package features: {:#?}", self.features)?;
writeln!(f, "Target triple: {}", self.target)?;
writeln!(f, "Optimization level: {}", self.opt_level)?;
writeln!(f, "Profile: {}", self.profile)?;
writeln!(f, "Debug: {}", self.debug)?;
writeln!(f, "Rustc: {}", self.rustc)?;
writeln!(f, "Built at: {}", self.built_time_utc)?;
writeln!(f, "CI platform: {:?}", self.ci_platform.unwrap_or("None"))?;
writeln!(
f,
"Git commit hash: {:?}",
self.git_commit_hash.unwrap_or("None")
)?;
writeln!(f, "Git head ref: {:?}", self.git_head_ref.unwrap_or("None"))?;
writeln!(f, "Git version: {:?}", self.git_version.unwrap_or("None"))?;
if self.git_dirty {
writeln!(f, "Repo had uncommitted changes when built")?;
}
Ok(())
}
}