feat: add more useful debug information to system metadata

This commit is contained in:
Chance 2025-04-03 18:21:19 -04:00 committed by BitSyndicate
parent 1f7807094b
commit f96690f00e
Signed by: bitsyndicate
GPG key ID: 443E4198D6BBA6DE
5 changed files with 1055 additions and 42 deletions

964
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,6 @@ members = ["engine","subcrates/zen_core"]
[workspace.dependencies]
lazy_static = "1.5.0"
parking_lot = "0.12.3"
[profile.release]

View file

@ -16,7 +16,7 @@ regex = "1.11.1"
rustyline = { version = "15.0.0", features = ["derive", "rustyline-derive"] }
thiserror = "2.0.11"
# Tokio is heavy but so far its the best option, we should make better use of it or switch to another runtime.
tokio = { version = "1.44.1", features = ["fs", "macros", "parking_lot", "rt-multi-thread"] }
tokio = { version = "1.44.1", features = ["macros", "parking_lot", "rt-multi-thread"] }
wgpu = "24.0.3"
winit = "0.30.9"
bytemuck = "1.21.0"
@ -38,3 +38,5 @@ image = "0.25.6"
[build-dependencies]
built = { version = "0.7.7", features = ["chrono"] }
build-print = "0.1.1"
cargo-lock = "10.1.0"

View file

@ -1,3 +1,99 @@
fn main() {
built::write_built_file().expect("Failed to write build information");
use std::process::Command;
use std::env;
use std::path::Path;
use std::fs::OpenOptions;
use std::io::Write;
use build_print::*;
use cargo_lock::Lockfile;
fn get_git_info() -> String {
match Command::new("git").arg("describe").arg("--always").arg("--dirty").output() {
Ok(output) if output.status.success() => {
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
_ => {
match Command::new("git").arg("rev-parse").arg("--abbrev-ref").arg("HEAD").output() {
Ok(output) if output.status.success() => {
let head = String::from_utf8_lossy(&output.stdout);
let head = head.trim();
if head == "HEAD" {
"DETACHED".to_string()
} else {
//TDDO: properly parse branch hashes
format!("BRANCH: {}", head)
}
}
_ => "UNKNOWN".to_string(),
}
}
}
}
fn main() {
if let Err(e) = built::write_built_file() {
panic!("{e}");
}
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("built.rs");
let proj_root = env!("CARGO_MANIFEST_DIR").to_string();
let tmp = format!("{}/../Cargo.lock",proj_root);
let lockfile_path = Path::new(&tmp).canonicalize().expect("INvalid");
let cargo_version = match Command::new("cargo").arg("--version").output() {
Ok(output) if output.status.success() => {
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
_ => "unknown".to_string(),
};
info!("{cargo_version}");
let rustc_version = match Command::new("rustc").arg("--version").output() {
Ok(output) if output.status.success() => {
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
_ => "unknown".to_string(),
};
info!("{rustc_version}");
let git_info = get_git_info();
info!("Git Info: {}", git_info);
let mut built_rs = match OpenOptions::new().append(true).open(&dest_path) {
Ok(file) => file,
Err(e) => {
error!("Could not open built.rs for appending: {}", e);
return;
}
};
writeln!(built_rs, "pub const GIT_COMMIT_HASH: &str = \"{}\";", git_info).unwrap();
match Lockfile::load(lockfile_path) {
Ok(lockfile) => {
let dependencies_to_track = ["tokio", "winit", "wgpu"];
for package in lockfile.packages {
let name = package.name.as_str();
if dependencies_to_track.contains(&name) {
let version = package.version.to_string();
writeln!(
built_rs,
"pub const {}_VERSION: &str = \"{}\";",
name.to_uppercase().replace('-', "_"),
version
)
.unwrap();
}
}
}
Err(e) => {
error!("Error loading Cargo.lock: {}", e);
}
}
std::println!("cargo:rerun-if-changed=Cargo.lock");
std::println!("cargo:rerun-if-changed=.git/HEAD");
std::println!("cargo:rerun-if-changed=.git/index");
}

View file

@ -195,8 +195,10 @@ impl CPU {
);
sys.refresh_cpu_all();
let cpu_opt = sys.cpus().first();
let brand = cpu_opt
.map(|cpu| cpu.brand().into())
.unwrap_or(CPUBrand::Other("unknown".into()));
@ -464,16 +466,20 @@ impl SystemMemory {
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CompileInfo {
pub struct EngineInfo {
pub timestamp: String,
pub pkg_version: String,
pub pkg_name: String,
pub target_arch: String,
pub target_os: String,
pub target_env: String,
pub rustc_version: String,
pub wgpu_version: String,
pub winit_version: String,
pub commit_hash: String,
}
impl CompileInfo {
impl EngineInfo {
pub fn current() -> Self {
Self {
timestamp: build_info::BUILT_TIME_UTC.to_string(),
@ -482,6 +488,10 @@ impl CompileInfo {
target_arch: build_info::CFG_TARGET_ARCH.to_string(),
target_os: build_info::CFG_OS.to_string(),
target_env: build_info::CFG_ENV.to_string(),
rustc_version: build_info::RUSTC_VERSION.to_string(),
wgpu_version: build_info::WGPU_VERSION.to_string(),
winit_version: build_info::WGPU_VERSION.to_string(),
commit_hash: build_info::GIT_COMMIT_HASH.to_string()
}
}
@ -491,13 +501,21 @@ impl CompileInfo {
- Timestamp: {}\n\
- Package: {} v{}\n\
- Target: {} {} {}\n\
- Rustc version: {}\n\
- Wgpu version: {}\n\
- Winit version: {}\n\
- commit_hash: {}\n\
",
self.timestamp,
self.pkg_name,
self.pkg_version,
self.target_arch,
self.target_os,
self.target_env
self.target_env,
self.rustc_version,
self.wgpu_version,
self.winit_version,
self.commit_hash
)
}
}
@ -507,7 +525,7 @@ pub struct SystemMetadata {
pub cpu: CPU,
pub memory: SystemMemory,
pub gpus: Vec<GPU>,
pub compile_info: CompileInfo,
pub compile_info: EngineInfo,
}
impl SystemMetadata {
@ -516,7 +534,7 @@ impl SystemMetadata {
cpu: CPU::current(),
memory: SystemMemory::current(),
gpus: GPU::current(),
compile_info: CompileInfo::current(),
compile_info: EngineInfo::current(),
}
}