forked from thirtythreeforty/neolink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
58 lines (48 loc) · 1.39 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
use std::env;
use std::process::Command;
fn main() {
build_ver();
platform_cfg();
}
fn build_ver() {
let cargo_ver = env::var("CARGO_PKG_VERSION").unwrap();
let version = git_ver().unwrap_or(format!("{} (unknown commit)", cargo_ver));
println!("cargo:rustc-env=NEOLINK_VERSION={}", version);
println!(
"cargo:rustc-env=NEOLINK_PROFILE={}",
env::var("PROFILE").unwrap()
);
}
fn git_ver() -> Option<String> {
github_ver().or_else(git_cmd_ver)
}
fn git_cmd_ver() -> Option<String> {
let mut git_cmd = Command::new("git");
git_cmd.args(&["describe", "--tags"]);
if let Some(true) = git_cmd.status().ok().map(|exit| exit.success()) {
println!("cargo:rerun-if-changed=.git/HEAD");
git_cmd
.output()
.ok()
.map(|o| String::from_utf8(o.stdout).unwrap())
} else {
None
}
}
fn github_ver() -> Option<String> {
if let Ok(sha1) = env::var("GITHUB_SHA") {
println!("cargo:rerun-if-env-changed=GITHUB_SHA");
Some(sha1)
} else {
None
}
}
#[cfg(windows)]
fn platform_cfg() {
let gstreamer_dir = env::var_os("GSTREAMER_1_0_ROOT_X86_64")
.and_then(|x| x.into_string().ok())
.unwrap_or_else(|| r#"C:\gstreamer\1.0\x86_64\"#.to_string());
println!(r"cargo:rustc-link-search=native={}\lib", gstreamer_dir);
}
#[cfg(not(windows))]
fn platform_cfg() {}