-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
59 lines (52 loc) · 1.62 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
58
59
use std::{
fs::{create_dir_all, File},
io::Write,
path::Path,
process::ExitCode,
};
use anyhow::{Context, Result};
use stockfish_fetch::{consts::*, core::StockfishBuilder, utils::LogWriter};
use tracing::error;
use tracing_subscriber::fmt::{time::LocalTime, SubscriberBuilder};
fn main() -> ExitCode {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=target/stockfish");
println!();
// Open and prepare log file
let log_file_p = Path::new(LOG_FILE_PATH);
let mut log_file = match File::options().create(true).append(true).open(log_file_p) {
Ok(f) => f,
Err(err) => {
eprintln!("Failed to open log file: {LOG_FILE_PATH}");
eprintln!("\n {err:#}");
return ExitCode::FAILURE;
}
};
writeln!(
log_file,
"\n--------------------------------[ BEGIN BUILD ]--------------------------------\n"
)
.unwrap();
// Setup log subscriber
SubscriberBuilder::default()
.with_writer(LogWriter::new(log_file))
.with_ansi(false)
.with_timer(LocalTime::rfc_3339())
.with_target(false)
.init();
match main2() {
Ok(_) => ExitCode::SUCCESS,
Err(err) => {
error!("{:?}", err);
ExitCode::FAILURE
}
}
}
fn main2() -> Result<()> {
// Ensure that the script working directory in target/ exists
create_dir_all(WORKING_DIR).with_context(|| {
format!("Failed to ensure that the Stockfish working directory exists: {WORKING_DIR}")
})?;
// Core logic
StockfishBuilder::default().run()
}