Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
67 lines (60 loc) · 2.45 KB
/
Copy pathbuild.rs
File metadata and controls
67 lines (60 loc) · 2.45 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Build script for `EasyHDR`
//!
//! This build script performs three main tasks:
//! 1. Compiles Slint UI files (`ui/main.slint`) into Rust code
//! 2. Embeds version and build metadata (commit SHA) for runtime access
//! 3. On Windows, embeds application resources (icon, version info, manifest) into the executable
//!
//! The Windows resources include:
//! - Application icon (`assets/icon.ico`)
//! - Version information from `Cargo.toml`
//! - Product metadata (name, description, copyright)
//! - Windows manifest for DPI awareness and compatibility
use std::process::Command;
fn main() {
// Compile Slint UI files
slint_build::compile("ui/main.slint")
.expect("Failed to compile Slint UI files. Check ui/main.slint for syntax errors.");
// Embed version information for runtime access
println!(
"cargo:rustc-env=CARGO_PKG_VERSION={}",
env!("CARGO_PKG_VERSION")
);
// Try to get the Git commit SHA (short form, 7 characters)
// This is used as a build identifier in the version display
let git_commit = Command::new("git")
.args(["rev-parse", "--short=7", "HEAD"])
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.map_or_else(|| "unknown".to_string(), |s| s.trim().to_string());
println!("cargo:rustc-env=GIT_COMMIT_SHA={git_commit}");
// Rerun if .git/HEAD changes (to update commit SHA on new commits)
println!("cargo:rerun-if-changed=.git/HEAD");
// Embed Windows resources (icon, version info)
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon("assets/icon.ico");
// ProductName: Full descriptive name shown in file properties
res.set(
"ProductName",
"EasyHDR - Automatic HDR management for Windows",
);
// FileDescription: Brief name shown in Windows Task Manager
res.set("FileDescription", "EasyHDR");
res.set("CompanyName", "engels74");
res.set("LegalCopyright", "Copyright © 2025 engels74");
res.set("OriginalFilename", "easyhdr.exe");
res.set("FileVersion", env!("CARGO_PKG_VERSION"));
res.set("ProductVersion", env!("CARGO_PKG_VERSION"));
res.compile()
.expect("Failed to compile Windows resources. Check that assets/icon.ico exists.");
}
}