-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
43 lines (39 loc) · 1.31 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
use std::{env, fs::File, io::Read, process::Command};
fn main() {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
let mut version = "".to_string();
File::open("version.txt")
.unwrap()
.read_to_string(&mut version)
.unwrap();
println!("cargo:rustc-env=VERSION={}", version);
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
// possible architecture: win-x64 win-x86 linux osx
let target = std::env::var("TARGET").unwrap();
let target = target.split('-').collect::<Vec<_>>();
let target = target[2];
let target = match target {
"windows" => {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
match arch.as_str() {
"x86_64" => "win-x64",
"x86" => "win-x86",
_ => panic!("Unsupported target"),
}
}
"linux" => "linux",
"darwin" => "osx",
_ => panic!("Unsupported target"),
};
println!("cargo:rustc-env=TARGET={}", target);
use winres::WindowsResource;
if env::var_os("CARGO_CFG_WINDOWS").is_some() {
WindowsResource::new()
.set_icon("icon.ico")
.compile().unwrap();
}
}