diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-17 14:47:25 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-17 14:47:25 +0800 |
| commit | 92670ec92b555383fc31cf42b15d4ea38f8e9c8f (patch) | |
| tree | b2f1479247411027fb41b346d2195e79e38729a1 /gen/gen_compile_info.rs | |
| parent | 7fcc38d0e76fc4088269cd3ea22c56a60e5db109 (diff) | |
Extract build-time generation code into separate crate
Diffstat (limited to 'gen/gen_compile_info.rs')
| -rw-r--r-- | gen/gen_compile_info.rs | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/gen/gen_compile_info.rs b/gen/gen_compile_info.rs deleted file mode 100644 index 8d68d89..0000000 --- a/gen/gen_compile_info.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::path::PathBuf; - -use just_template::{Template, tmpl_param}; - -use crate::r#gen::{ - constants::{COMPILE_INFO_RS, COMPILE_INFO_RS_TEMPLATE}, - env::{get_git_branch, get_git_commit, get_platform, get_toolchain, get_version}, -}; - -/// Generate compile info using just_template -pub async fn generate_compile_info(repo_root: &PathBuf) { - // Read the template code - let template_code = tokio::fs::read_to_string(repo_root.join(COMPILE_INFO_RS_TEMPLATE)) - .await - .unwrap(); - - // Get all the values needed for the template - let date = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(); - let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string()); - let platform = get_platform(&target); - let toolchain = get_toolchain(); - let version = get_version(); - let branch = get_git_branch().unwrap_or_else(|_| "unknown".to_string()); - let commit = get_git_commit().unwrap_or_else(|_| "unknown".to_string()); - - // Create a Template instance - let mut template = Template::from(template_code); - - // Set all parameters - tmpl_param!( - template, - date = date, - target = target, - platform = platform, - toolchain = toolchain, - version = version, - branch = branch, - commit = commit - ); - - // Expand the template - let generated_code = template.expand().unwrap(); - - // Write the generated code - let compile_info_path = repo_root.join(COMPILE_INFO_RS); - tokio::fs::write(compile_info_path, generated_code) - .await - .unwrap(); - - println!("Generated compile_info.rs using just_template"); -} |
