-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
35 lines (30 loc) · 1.15 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
use std::path::Path;
use std::{env, fs};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=soundboard.toml");
println!("cargo:rerun-if-changed=soundboards");
let target_dir_path = Path::new(&env::var("OUT_DIR").unwrap())
.join("..")
.join("..")
.join("..");
copy_file(&target_dir_path, "soundboard.toml");
let out_soundboards_path = Path::new(&target_dir_path).join("soundboards");
if out_soundboards_path.exists() && out_soundboards_path.is_dir() {
std::fs::remove_dir_all(&out_soundboards_path).unwrap();
}
let copy_options = fs_extra::dir::CopyOptions::new();
if Path::new("soundboards").exists() {
fs_extra::dir::copy("soundboards", target_dir_path, ©_options).expect("copy failed");
}
tonic_build::configure().format(false).compile(
&["src/download/ttsclient/cloud_tts.proto"],
&["src/download/ttsclient"],
)?;
Ok(())
}
fn copy_file<S: AsRef<std::ffi::OsStr> + ?Sized, P: Copy + AsRef<Path>>(
target_dir_path: &S,
file_name: P,
) {
fs::copy(file_name, Path::new(&target_dir_path).join(file_name)).unwrap();
}