librespot/core/build.rs

39 lines
856 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;
2019-01-17 07:59:25 +00:00
use rand::distributions::Alphanumeric;
2017-08-03 18:58:44 +00:00
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();
2019-01-17 07:59:25 +00:00
let mut rng = rand::thread_rng();
let build_id: String = ::std::iter::repeat(()).map(|()| rng.sample(Alphanumeric)).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);
}
}