-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
41 lines (35 loc) · 1.18 KB
/
build.rs
File metadata and controls
41 lines (35 loc) · 1.18 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
use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;
fn main() {
// Make cargo track changes to Cargo.toml
println!("cargo:rerun-if-changed=Cargo.toml");
// Configure Windows to use the windows subsystem (no console window)
if env::var("CARGO_CFG_TARGET_OS").unwrap_or_default() == "windows" {
println!("cargo:rustc-link-arg=/SUBSYSTEM:WINDOWS");
println!("cargo:rustc-link-arg=/ENTRY:mainCRTStartup");
}
// Get version from Cargo.toml
let version = env!("CARGO_PKG_VERSION");
// Try to get git commit hash
let git_hash = match Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
{
Ok(output) if output.status.success() => {
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
_ => "unknown".to_string(),
};
// Create a version info module
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("version_info.rs");
fs::write(
&dest_path,
format!(
"pub const VERSION: &str = \"{version}\";\npub const GIT_HASH: &str = \"{git_hash}\";\n"
),
)
.unwrap();
}