-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
57 lines (48 loc) · 1.82 KB
/
build.rs
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
use std::{env, fs, path::PathBuf, process, sync::LazyLock};
static BUILD_PROFILE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
PathBuf::from(env::var("OUT_DIR").unwrap())
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf()
});
fn main() {
// Link libraries/frameworks required for MacOS clipboard stuff
if cfg!(target_os = "macos") {
println!("cargo::rustc-link-arg=-lobjc");
println!("cargo::rustc-link-arg=-framework");
println!("cargo::rustc-link-arg=AppKit");
println!("cargo::rustc-link-lib=framework=ServiceManagement");
}
// Compile & link resource file for Windows
if cfg!(target_os = "windows") {
println!("cargo::rerun-if-changed=bundling\\windows\\resources.rc");
println!("cargo::rerun-if-changed=resources\\icon.ico");
let build_profile_bundle_path = BUILD_PROFILE_DIR.join("bundle");
fs::create_dir_all(&build_profile_bundle_path).unwrap();
let res_file_path = build_profile_bundle_path.join("resources.res");
let res_file_path = res_file_path.as_os_str().to_string_lossy();
// TODO: Rerun if resources.rc or icon.ico changes
let windres_cmd = process::Command::new("windres")
.args([
"bundling\\windows\\resources.rc",
"-O",
"coff",
"-o",
&res_file_path,
])
.output()
.unwrap();
if !windres_cmd.status.success() {
panic!(
"Failed to build resources.rc:\n{}\n{}",
String::from_utf8_lossy(&windres_cmd.stdout),
String::from_utf8_lossy(&windres_cmd.stderr)
)
}
println!("cargo::rustc-link-arg={res_file_path}");
}
}