hyperlight_wasm/
build_info.rs1use std::sync::Once;
18
19use log::info;
20static LOG_ONCE: Once = Once::new();
22
23include!(concat!(env!("OUT_DIR"), "/built.rs"));
31
32pub struct BuildInfo {
34 pub wasm_runtime_created: &'static str,
36 pub wasm_runtime_size: &'static str,
38 pub wasm_runtime_blake3_hash: &'static str,
40 pub wasm_runtime_wasmtime_version: &'static str,
42 pub package_name: &'static str,
44 pub package_version: &'static str,
46 pub features: Vec<&'static str>,
48 pub target: &'static str,
50 pub opt_level: &'static str,
52 pub profile: &'static str,
54 pub debug: bool,
56 pub rustc: &'static str,
58 pub built_time_utc: &'static str,
60 pub ci_platform: Option<&'static str>,
62 pub git_commit_hash: Option<&'static str>,
64 pub git_head_ref: Option<&'static str>,
66 pub git_version: Option<&'static str>,
68 pub git_dirty: bool,
70}
71
72impl Default for BuildInfo {
73 fn default() -> Self {
74 let mut features: Vec<&str> = Vec::new();
75
76 for feature in FEATURES {
77 features.push(feature);
78 }
79
80 Self {
81 wasm_runtime_created: WASM_RUNTIME_CREATED,
82 wasm_runtime_size: WASM_RUNTIME_SIZE,
83 wasm_runtime_blake3_hash: WASM_RUNTIME_BLAKE3_HASH,
84 wasm_runtime_wasmtime_version: WASM_RUNTIME_WASMTIME_VERSION,
85 package_name: PKG_NAME,
86 package_version: PKG_VERSION,
87 features,
88 target: TARGET,
89 opt_level: OPT_LEVEL,
90 profile: PROFILE,
91 debug: DEBUG,
92 rustc: RUSTC,
93 built_time_utc: BUILT_TIME_UTC,
94 ci_platform: CI_PLATFORM,
95 git_commit_hash: GIT_COMMIT_HASH,
96 git_head_ref: GIT_HEAD_REF,
97 git_version: GIT_VERSION,
98 git_dirty: GIT_DIRTY.unwrap_or(false),
99 }
100 }
101}
102
103impl BuildInfo {
104 pub fn get() -> Self {
106 Self::default()
107 }
108 pub(crate) fn log() {
109 Self::default().log_build_details();
110 }
111 fn log_build_details(&self) {
112 LOG_ONCE.call_once(|| {
113 info!("{}", self);
114 });
115 }
116 pub(crate) fn get_wasmtime_version() -> &'static str {
118 WASM_RUNTIME_WASMTIME_VERSION
119 }
120}
121
122impl std::fmt::Display for BuildInfo {
123 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
124 writeln!(
125 f,
126 "hyperlight-wasm-runtime created at: {}",
127 self.wasm_runtime_created
128 )?;
129 writeln!(
130 f,
131 "hyperlight-wasm-runtime size: {}",
132 self.wasm_runtime_size
133 )?;
134 writeln!(
135 f,
136 "hyperlight-wasm-runtime hash: {}",
137 self.wasm_runtime_blake3_hash
138 )?;
139 writeln!(
140 f,
141 "hyperlight-wasm-runtime wasmtime version: {}",
142 self.wasm_runtime_wasmtime_version
143 )?;
144 writeln!(f, "Package name: {}", self.package_name)?;
145 writeln!(f, "Package version: {}", self.package_version)?;
146 writeln!(f, "Package features: {:#?}", self.features)?;
147 writeln!(f, "Target triple: {}", self.target)?;
148 writeln!(f, "Optimization level: {}", self.opt_level)?;
149 writeln!(f, "Profile: {}", self.profile)?;
150 writeln!(f, "Debug: {}", self.debug)?;
151 writeln!(f, "Rustc: {}", self.rustc)?;
152 writeln!(f, "Built at: {}", self.built_time_utc)?;
153 writeln!(f, "CI platform: {:?}", self.ci_platform.unwrap_or("None"))?;
154 writeln!(
155 f,
156 "Git commit hash: {:?}",
157 self.git_commit_hash.unwrap_or("None")
158 )?;
159 writeln!(f, "Git head ref: {:?}", self.git_head_ref.unwrap_or("None"))?;
160 writeln!(f, "Git version: {:?}", self.git_version.unwrap_or("None"))?;
161 if self.git_dirty {
162 writeln!(f, "Repo had uncommitted changes when built")?;
163 }
164 Ok(())
165 }
166}