|
| 1 | +use winres::{VersionInfo, WindowsResource}; |
| 2 | + |
1 | 3 | fn main() { |
2 | | - // Derive version from the latest Git tag (e.g. "v1.0.7" → "1.0.7"). |
3 | | - let version = std::process::Command::new("git") |
4 | | - .args(["describe", "--tags", "--abbrev=0"]) |
5 | | - .output() |
6 | | - .ok() |
7 | | - .and_then(|o| { |
8 | | - if o.status.success() { |
9 | | - String::from_utf8(o.stdout).ok() |
10 | | - } else { |
11 | | - None |
12 | | - } |
13 | | - }) |
14 | | - .unwrap_or_else(|| String::from("0.0.0")); |
| 4 | + let version = env!("CARGO_PKG_VERSION"); |
15 | 5 |
|
16 | | - let version = version.trim().trim_start_matches('v'); |
17 | | - println!("cargo:rustc-env=APP_VERSION={version}"); |
| 6 | + // Embed the icon and richer PE version metadata into the executable. |
| 7 | + let mut res = WindowsResource::new(); |
| 8 | + let numeric_version = pack_version(version); |
18 | 9 |
|
19 | | - // Re-run build script whenever HEAD or tags change so the version stays current. |
20 | | - println!("cargo:rerun-if-changed=.git/HEAD"); |
21 | | - println!("cargo:rerun-if-changed=.git/refs/tags"); |
| 10 | + res.set_icon("src/icons/icon.ico") |
| 11 | + .set("FileVersion", version) |
| 12 | + .set("ProductVersion", version) |
| 13 | + .set_version_info(VersionInfo::FILEVERSION, numeric_version) |
| 14 | + .set_version_info(VersionInfo::PRODUCTVERSION, numeric_version); |
22 | 15 |
|
23 | | - // Embed the application icon into the executable. |
24 | | - let mut res = winres::WindowsResource::new(); |
25 | | - res.set_icon("src/icons/icon.ico"); |
26 | 16 | res.compile().expect("Failed to compile Windows resources"); |
27 | 17 | } |
| 18 | + |
| 19 | +fn pack_version(version: &str) -> u64 { |
| 20 | + let core = version.split('-').next().unwrap_or(version); |
| 21 | + let mut parts = core |
| 22 | + .split('.') |
| 23 | + .map(|part| part.parse::<u64>().unwrap_or(0)); |
| 24 | + |
| 25 | + let major = parts.next().unwrap_or(0).min(u16::MAX as u64); |
| 26 | + let minor = parts.next().unwrap_or(0).min(u16::MAX as u64); |
| 27 | + let patch = parts.next().unwrap_or(0).min(u16::MAX as u64); |
| 28 | + |
| 29 | + (major << 48) | (minor << 32) | (patch << 16) |
| 30 | +} |
0 commit comments