-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
58 lines (53 loc) · 1.98 KB
/
Copy pathbuild.rs
File metadata and controls
58 lines (53 loc) · 1.98 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
//! Build script: embed the application icon (and version info) into the
//! Windows executable. `rc.exe` (the Windows Resource Compiler, shipped with
//! the Windows SDK / Visual Studio) must be reachable; on this machine it is
//! installed but not on `PATH`, so we locate it under the Windows SDK and
//! prepend it to `PATH` before invoking `winres`.
fn main() {
#[cfg(windows)]
{
ensure_rc_on_path();
let mut res = winres::WindowsResource::new();
res.set_icon("public/app-icon.ico");
res.set("ProductName", "MS Audio Dock Remapper");
res.set(
"FileDescription",
"Remap the Microsoft Audio Dock Teams key",
);
res.set("LegalCopyright", "MIT");
res.compile()
.expect("failed to embed Windows resources (rc.exe)");
}
#[cfg(not(windows))]
{
// Nothing to do off-Windows.
let _ = std::env::var("CARGO_PKG_NAME");
}
}
/// Find `rc.exe` inside the Windows SDK and add its directory to `PATH` so the
/// resource compiler invoked by `winres` can be located. Searches the common
/// SDK install locations and accepts the first match.
fn ensure_rc_on_path() {
let candidates = [
r"C:\Program Files (x86)\Windows Kits\10\bin",
r"C:\Program Files\Windows Kits\10\bin",
];
for base in candidates {
let Ok(entries) = std::fs::read_dir(base) else {
continue;
};
for entry in entries.flatten() {
let rc = entry.path().join("x64").join("rc.exe");
if rc.is_file() {
if let Some(dir) = rc.parent() {
let dir = dir.to_string_lossy().to_string();
let path = std::env::var("PATH").unwrap_or_default();
if !path.split(';').any(|p| p.eq_ignore_ascii_case(&dir)) {
std::env::set_var("PATH", format!("{dir};{path}"));
}
}
return;
}
}
}
}