diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2025-12-10 11:10:47 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2025-12-10 11:11:50 +0800 |
| commit | 15b508b7931aacd0c07ad6f52d4cefa6eef69fa1 (patch) | |
| tree | 13d4e55d27ae26f8184719556c2eac243c82c602 | |
| parent | be67a79c4a10fc42d7d15b87e488db00238e4676 (diff) | |
Add Windows installer script generation to build process
- Generate Inno Setup installer script from template at build time
- Extract author and homepage from Cargo.toml for script customization
- Add generated installer script to .gitignore to avoid committing build
artifacts
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | build.rs | 64 | ||||
| -rw-r--r-- | setup/windows/setup_jv_cli_template.iss | 6 |
4 files changed, 72 insertions, 3 deletions
@@ -22,3 +22,6 @@ # Compile info /src/data/compile_info.rs + +# Setup script +/setup/windows/setup_jv_cli.iss @@ -2,6 +2,8 @@ name = "just_enough_vcs_cli" edition = "2024" build = "build.rs" +authors = ["JustEnoughVCS Team"] +homepage = "http://jvcs.cc/" [workspace] members = ["crates/build_helper"] @@ -7,12 +7,76 @@ const COMPILE_INFO_RS_TEMPLATE: &str = "./src/data/compile_info.rs.template"; fn main() { let repo_root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); + // Only generate installer script on Windows + if cfg!(target_os = "windows") { + if let Err(e) = generate_installer_script(&repo_root) { + eprintln!("Failed to generate installer script: {}", e); + std::process::exit(1); + } + } + if let Err(e) = generate_compile_info(&repo_root) { eprintln!("Failed to generate compile info: {}", e); std::process::exit(1); } } +/// Generate Inno Setup installer script (Windows only) +fn generate_installer_script(repo_root: &PathBuf) -> Result<(), Box<dyn std::error::Error>> { + let template_path = repo_root.join("setup/windows/setup_jv_cli_template.iss"); + let output_path = repo_root.join("setup/windows/setup_jv_cli.iss"); + + let template = std::fs::read_to_string(&template_path)?; + + let author = get_author()?; + let version = get_version(); + let site = get_site()?; + + let generated = template + .replace("<<<AUTHOR>>>", &author) + .replace("<<<VERSION>>>", &version) + .replace("<<<SITE>>>", &site); + + std::fs::write(output_path, generated)?; + Ok(()) +} + +fn get_author() -> Result<String, Box<dyn std::error::Error>> { + let cargo_toml_path = std::path::Path::new("Cargo.toml"); + let cargo_toml_content = std::fs::read_to_string(cargo_toml_path)?; + let cargo_toml: toml::Value = toml::from_str(&cargo_toml_content)?; + + if let Some(package) = cargo_toml.get("package") { + if let Some(authors) = package.get("authors") { + if let Some(authors_array) = authors.as_array() { + if let Some(first_author) = authors_array.get(0) { + if let Some(author_str) = first_author.as_str() { + return Ok(author_str.to_string()); + } + } + } + } + } + + Err("Author not found in Cargo.toml".into()) +} + +fn get_site() -> Result<String, Box<dyn std::error::Error>> { + let cargo_toml_path = std::path::Path::new("Cargo.toml"); + let cargo_toml_content = std::fs::read_to_string(cargo_toml_path)?; + let cargo_toml: toml::Value = toml::from_str(&cargo_toml_content)?; + + if let Some(package) = cargo_toml.get("package") { + if let Some(homepage) = package.get("homepage") { + if let Some(site_str) = homepage.as_str() { + return Ok(site_str.to_string()); + } + } + } + + Err("Homepage not found in Cargo.toml".into()) +} + /// Generate compile info fn generate_compile_info(repo_root: &PathBuf) -> Result<(), Box<dyn std::error::Error>> { // Read the template code diff --git a/setup/windows/setup_jv_cli_template.iss b/setup/windows/setup_jv_cli_template.iss index 24b2a32..124d897 100644 --- a/setup/windows/setup_jv_cli_template.iss +++ b/setup/windows/setup_jv_cli_template.iss @@ -1,7 +1,7 @@ #define MyAppName "JustEnoughVCS" -#define MyAppVersion "0.1.0" -#define MyAppPublisher "JustEnoughVCS Team" -#define MyAppURL "https://jvcs.cc/" +#define MyAppVersion "<<<VERSION>>>" +#define MyAppPublisher "<<<AUTHOR>>>" +#define MyAppURL "<<<SITE>>>" [Setup] AppId={{8265DF21-F290-487E-9403-C2730EC31A03} |
