-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
64 lines (56 loc) · 2.17 KB
/
Copy pathbuild.rs
File metadata and controls
64 lines (56 loc) · 2.17 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
//! Attaches the icon and the version metadata to the Windows executable.
//!
//! A failure here is not fatal: with no resource compiler available the binary
//! still builds, only with the default icon.
fn main() {
println!("cargo:rerun-if-changed=assets/icon.ico");
println!("cargo:rerun-if-changed=build.rs");
#[cfg(windows)]
{
let version = env!("CARGO_PKG_VERSION");
let mut resource = winresource::WindowsResource::new();
resource.set_icon("assets/icon.ico");
resource.set("ProductName", "Ferrite");
resource.set("FileDescription", "Ferrite, workspace cleanup");
resource.set("CompanyName", "infinition");
resource.set("LegalCopyright", "Copyright (c) infinition. MIT licensed.");
resource.set("OriginalFilename", "Ferrite.exe");
resource.set("InternalName", "Ferrite");
resource.set("ProductVersion", version);
resource.set("FileVersion", version);
// Automatic detection of the resource compiler fails on some Windows
// SDK layouts, so locate it explicitly.
if let Some(toolkit) = find_resource_compiler() {
resource.set_toolkit_path(&toolkit);
}
if let Err(error) = resource.compile() {
println!("cargo:warning=icon not embedded: {error}");
}
}
}
/// Finds the directory holding `rc.exe`, preferring the most recent SDK.
/// Returns `None` when no resource compiler is installed.
#[cfg(windows)]
fn find_resource_compiler() -> Option<String> {
let roots = [
r"C:\Program Files (x86)\Windows Kits\10\bin",
r"C:\Program Files\Windows Kits\10\bin",
];
let mut candidates: Vec<std::path::PathBuf> = Vec::new();
for root in roots {
let entries = match std::fs::read_dir(root) {
Ok(entries) => entries,
Err(_) => continue,
};
for entry in entries.flatten() {
let directory = entry.path().join("x64");
if directory.join("rc.exe").is_file() {
candidates.push(directory);
}
}
}
candidates.sort();
candidates
.pop()
.map(|path| path.to_string_lossy().to_string())
}