-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
56 lines (51 loc) · 1.8 KB
/
build.rs
File metadata and controls
56 lines (51 loc) · 1.8 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
use std::env;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
fn copy_dir_all(src: &Path, dst: &Path) -> io::Result<()> {
if !dst.exists() {
fs::create_dir_all(dst)?;
}
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
let src_path = entry.path();
let dst_path = dst.join(entry.file_name());
if ty.is_dir() {
copy_dir_all(&src_path, &dst_path)?;
} else {
fs::copy(&src_path, &dst_path)?;
}
}
Ok(())
}
fn main() {
// Always rerun if assets change so we recopy them beside the built binary.
println!("cargo:rerun-if-changed=assets");
// Copy assets into target/{profile}/assets for running the built binary directly.
if let Ok(profile) = env::var("PROFILE") {
let target_dir = env::var("CARGO_TARGET_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from("target"));
let dest = target_dir.join(&profile).join("assets");
let src = Path::new("assets");
if src.exists() {
if let Err(err) = copy_dir_all(src, &dest) {
println!("cargo:warning=Failed to copy assets: {}", err);
}
}
}
if cfg!(target_os = "windows") {
let mut res = winres::WindowsResource::new();
// Prefer the new app icon if the .ico is present; otherwise build without it.
let ico_path = Path::new("assets/icon.ico");
if ico_path.exists() {
res.set_icon(ico_path.to_str().unwrap());
} else if Path::new("assets/icon.svg").exists() {
println!(
"cargo:warning=assets/icon.ico missing; convert assets/icon.svg -> assets/icon.ico to bundle the app icon"
);
}
res.compile().unwrap();
}
}