forked from SpaceManiac/SpacemanDMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
60 lines (53 loc) · 1.87 KB
/
build.rs
File metadata and controls
60 lines (53 loc) · 1.87 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
57
58
59
60
extern crate chrono;
extern crate git2;
use std::env;
use std::fs::File;
use std::io::Write;
use std::process::Command;
use std::path::{Path, PathBuf};
fn main() {
// build info
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let mut f = File::create(&out_dir.join("build-info.txt")).unwrap();
if let Ok(commit) = read_commit() {
writeln!(f, "commit: {}", commit).unwrap();
}
writeln!(f, "build date: {}", chrono::Utc::today()).unwrap();
// windres icon
if cfg!(windows) {
let out_dir = env::var("OUT_DIR").ok().expect("can't find out_dir");
if cfg!(target_env="msvc") {
if let Err(e) = Command::new("windres")
.args(&["res/editor.rc", "-o"])
.arg(&format!("{}/editor_rc.lib", out_dir))
.status()
{
println!("cargo:warning=`windres` unavailable: {}", e);
return;
}
} else {
if let Err(e) = Command::new("windres")
.args(&["res/editor.rc", "-o"])
.arg(&format!("{}/editor.rc.o", out_dir))
.status()
{
println!("cargo:warning=`windres` unavailable: {}", e);
return;
}
Command::new("ar")
.args(&["crus", "libeditor_rc.a", "editor.rc.o"])
.current_dir(Path::new(&out_dir))
.status()
.unwrap();
}
println!("cargo:rerun-if-changed=editor.rc");
println!("cargo:rerun-if-changed=gasmask.ico");
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=editor_rc");
}
}
fn read_commit() -> Result<String, git2::Error> {
let repo = git2::Repository::discover(".")?;
let hash = repo.head()?.peel_to_commit()?.id().to_string();
Ok(hash)
}