From 5991905ae9fb519a3a43c599c5515ba39c04e5fb Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 4 Nov 2025 14:29:34 +0800 Subject: Add compile-time version and build information - Add build script to generate compile_info.rs with build metadata - Include version, build date, target platform, and toolchain info - Add version command to both jv and jvv binaries - Update help documentation with version information - Ignore generated compile_info.rs in git --- crates/build_helper/src/bin/exporter.rs | 80 +++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 33 deletions(-) (limited to 'crates/build_helper/src/bin/exporter.rs') diff --git a/crates/build_helper/src/bin/exporter.rs b/crates/build_helper/src/bin/exporter.rs index edc7e9c..4a35de5 100644 --- a/crates/build_helper/src/bin/exporter.rs +++ b/crates/build_helper/src/bin/exporter.rs @@ -6,12 +6,34 @@ fn main() -> Result<(), Box> { println!(" {} `.cargo/cargo.toml`", "Reading".green().bold()); let start_time = std::time::Instant::now(); - let mut copied_files = 0; let target_dir = current_target_dir().expect("Failed to get target directory"); let publish_dir = current_publish_dir().expect("Failed to get publish directory"); let publish_binaries = publish_binaries().expect("Failed to get publish binaries"); + // Final, export binaries to publish directory + let copied_files = export(target_dir, publish_dir, publish_binaries)?; + + let duration = start_time.elapsed(); + println!(); + println!( + "Done (in {:.1}s) Publish {} {}", + duration.as_secs_f32(), + copied_files, + if copied_files == 1 { "file" } else { "files" } + ); + + Ok(()) +} + +/// Export binaries to publish directory +fn export( + target_dir: std::path::PathBuf, + publish_dir: std::path::PathBuf, + publish_binaries: Vec, +) -> Result> { + let mut copied_files = 0; + if publish_dir.exists() { std::fs::remove_dir_all(&publish_dir)?; } @@ -39,42 +61,34 @@ fn main() -> Result<(), Box> { } if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) - && publish_binaries.contains(&file_name.to_string()) { - let parent_dir_name = path - .parent() - .and_then(|p| p.file_name()) - .and_then(|n| n.to_str()) - .unwrap_or(""); - - let dest_path = publish_dir.join(parent_dir_name).join(file_name); - - if let Some(parent) = dest_path.parent() { - std::fs::create_dir_all(parent)?; - } - - println!( - " {} `{}/{}` ({})", - "Copy".green().bold(), - parent_dir_name, - file_name, - path.display() - ); - std::fs::copy(&path, &dest_path)?; - copied_files += 1; + && publish_binaries.contains(&file_name.to_string()) + { + let parent_dir_name = path + .parent() + .and_then(|p| p.file_name()) + .and_then(|n| n.to_str()) + .unwrap_or(""); + + let dest_path = publish_dir.join(parent_dir_name).join(file_name); + + if let Some(parent) = dest_path.parent() { + std::fs::create_dir_all(parent)?; } + + println!( + " {} `{}/{}` ({})", + "Copy".green().bold(), + parent_dir_name, + file_name, + path.display() + ); + std::fs::copy(&path, &dest_path)?; + copied_files += 1; + } } } - let duration = start_time.elapsed(); - println!(); - println!( - "Done (in {:.1}s) Publish {} {}", - duration.as_secs_f32(), - copied_files, - if copied_files == 1 { "file" } else { "files" } - ); - - Ok(()) + Ok(copied_files) } /// Get a target directory from the cargo config -- cgit