-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.rs
More file actions
42 lines (34 loc) · 1.16 KB
/
Copy pathbuild.rs
File metadata and controls
42 lines (34 loc) · 1.16 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
use std::env;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
fn main() -> io::Result<()> {
println!("cargo:rerun-if-changed=assets");
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
let source_assets = manifest_dir.join("assets");
if !source_assets.is_dir() {
return Ok(());
}
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR"));
let profile_dir = out_dir
.ancestors()
.nth(3)
.expect("OUT_DIR should have target/<profile>/build/.../out layout");
let target_assets = profile_dir.join("assets");
copy_dir_all(&source_assets, &target_assets)
}
fn copy_dir_all(src: &Path, dst: &Path) -> io::Result<()> {
fs::create_dir_all(dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let entry_path = entry.path();
let target_path = dst.join(entry.file_name());
let file_type = entry.file_type()?;
if file_type.is_dir() {
copy_dir_all(&entry_path, &target_path)?;
} else if file_type.is_file() {
fs::copy(&entry_path, &target_path)?;
}
}
Ok(())
}