librespot/core/build.rs

37 lines
757 B
Rust
Raw Normal View History

2017-08-03 18:58:44 +00:00
extern crate rand;
2018-02-11 11:37:08 +00:00
extern crate vergen;
2017-08-03 18:58:44 +00:00
use rand::Rng;
use std::env;
use std::fs::OpenOptions;
use std::io::Write;
2018-02-11 11:37:08 +00:00
use std::path::PathBuf;
2017-08-03 18:58:44 +00:00
fn main() {
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
vergen::vergen(vergen::OutputFns::all()).unwrap();
2018-02-11 11:37:08 +00:00
let build_id: String = rand::thread_rng().gen_ascii_chars().take(8).collect();
2017-08-03 18:58:44 +00:00
2018-02-11 11:37:08 +00:00
let mut version_file = OpenOptions::new()
2017-08-03 18:58:44 +00:00
.write(true)
.append(true)
.open(&out.join("version.rs"))
.unwrap();
2018-02-11 11:37:08 +00:00
let build_id_fn = format!(
"
2017-08-03 18:58:44 +00:00
/// Generate a random build id.
pub fn build_id() -> &'static str {{
\"{}\"
}}
2018-02-11 11:37:08 +00:00
",
build_id
);
2017-08-03 18:58:44 +00:00
if let Err(e) = version_file.write_all(build_id_fn.as_bytes()) {
println!("{}", e);
}
}