-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
36 lines (30 loc) · 1.08 KB
/
build.rs
File metadata and controls
36 lines (30 loc) · 1.08 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
use std::io::Write;
fn get_out_dir() -> Result<String, std::ffi::OsString> {
std::env::var_os("OUT_DIR")
.ok_or_else(std::ffi::OsString::new)?
.into_string()
}
fn main() {
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
// Create a version.rs file in the output directory, that takes
// the Cargo.toml package version.
// This is used by the /status endpoint to report the version.
let version = env!("CARGO_PKG_VERSION");
let version_file_path: std::path::PathBuf;
if let Ok(out_dir) = get_out_dir() {
version_file_path = std::path::Path::new(&out_dir).join("version.rs".to_string());
} else {
panic!("in the streets of London.");
};
// (re)create the rs file output file.
let mut version_file_buf = std::fs::File::create(&version_file_path).unwrap();
version_file_buf
.write_all(
format!(
"\n//autogenerated by build.rs\npub fn version() -> String {{ \"{}\".to_string() }}",
version
)
.as_bytes(),
)
.unwrap();
}