cat_gateway/
build_info.rs1use std::fmt::Write;
4
5use build_info::{self as build_info_crate};
6use local_ip_address::list_afinet_netifas;
7use tracing::info;
8
9use crate::service::utilities;
10
11pub(crate) const BUILD_INFO: &str = build_info_crate::format!("
13version: {},
14git info: {{{}}}
15compiler: {}
16build time: {}
17",
18 $.crate_info.version,
19 $.version_control,
20 $.compiler,
21 $.timestamp
22);
23
24build_info_crate::build_info!(pub(crate) fn build_info);
25
26pub(crate) fn log_build_info() {
28 let info = build_info();
29 let timestamp = info.timestamp.to_rfc3339();
30 let profile = info.profile.clone();
31 let optimization_level = info.optimization_level.to_string();
32
33 let name = info.crate_info.name.clone();
34 let version = info.crate_info.version.to_string();
35 let features = info.crate_info.enabled_features.join(",");
36
37 let triple = info.target.triple.clone();
38 let family = info.target.family.clone();
39 let os = info.target.os.clone();
40 let cpu_arch = info.target.cpu.arch.clone();
41 let cpu_features = info.target.cpu.features.join(",");
42
43 let compiler_channel = info.compiler.channel.to_string();
44 let compiler_version = info.compiler.version.to_string();
45
46 let mut commit_id = "Unknown".to_string();
47 let mut commit_timestamp = "Unknown".to_string();
48 let mut branch = "Unknown".to_string();
49 let mut tags = "Unknown".to_string();
50
51 if let Some(ref vc) = info.version_control {
52 if let Some(git) = vc.git() {
53 commit_id.clone_from(&git.commit_short_id);
54 commit_timestamp = git.commit_timestamp.to_rfc3339();
55 if let Some(git_branch) = git.branch.clone() {
56 branch = git_branch;
57 }
58 tags = git.tags.join(",");
59 }
60 }
61
62 let ipv4 = utilities::net::get_public_ipv4().to_string();
63 let ipv6 = utilities::net::get_public_ipv6().to_string();
64
65 let mut interfaces: String = "Unknown".to_string();
66
67 if let Ok(network_interfaces) = list_afinet_netifas() {
69 if !network_interfaces.is_empty() {
70 interfaces.clear();
71 for iface in network_interfaces {
72 if !interfaces.is_empty() {
73 interfaces.push(',');
74 }
75 let _ = write!(interfaces, "{}:{}", iface.0, iface.1);
76 }
77 }
78 }
79
80 info!(
81 BuildTime = timestamp,
82 Profile = profile,
83 OptimizationLevel = optimization_level,
84 Name = name,
85 Version = version,
86 Features = features,
87 TargetTriple = triple,
88 TargetFamily = family,
89 TargetOs = os,
90 CPUArch = cpu_arch,
91 CPUFeatures = cpu_features,
92 RustChannel = compiler_channel,
93 RustVersion = compiler_version,
94 GitCommitId = commit_id,
95 GitCommitTimestamp = commit_timestamp,
96 GitBranch = branch,
97 GitTags = tags,
98 PublicIPv4 = ipv4,
99 PublicIPv6 = ipv6,
100 NetworkInterfaces = interfaces,
101 "Catalyst Gateway"
102 );
103}
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn build_info_test() {
111 println!("{BUILD_INFO}");
112 }
113}