-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuild.rs
More file actions
28 lines (21 loc) · 1 KB
/
build.rs
File metadata and controls
28 lines (21 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use winres::{VersionInfo, WindowsResource};
fn main() {
let version = env!("CARGO_PKG_VERSION");
// Embed the icon and richer PE version metadata into the executable.
let mut res = WindowsResource::new();
let numeric_version = pack_version(version);
res.set_icon("src/icons/icon.ico")
.set("FileVersion", version)
.set("ProductVersion", version)
.set_version_info(VersionInfo::FILEVERSION, numeric_version)
.set_version_info(VersionInfo::PRODUCTVERSION, numeric_version);
res.compile().expect("Failed to compile Windows resources");
}
fn pack_version(version: &str) -> u64 {
let core = version.split('-').next().unwrap_or(version);
let mut parts = core.split('.').map(|part| part.parse::<u64>().unwrap_or(0));
let major = parts.next().unwrap_or(0).min(u16::MAX as u64);
let minor = parts.next().unwrap_or(0).min(u16::MAX as u64);
let patch = parts.next().unwrap_or(0).min(u16::MAX as u64);
(major << 48) | (minor << 32) | (patch << 16)
}