2022-10-15 06:04:14 +02:00
|
|
|
use std::{
|
|
|
|
env,
|
|
|
|
fs::File,
|
|
|
|
io::{Read, Write},
|
|
|
|
};
|
2022-09-27 07:23:47 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Tell Cargo that if the given environment variable changes, to rerun this build script.
|
2022-10-25 14:53:27 +02:00
|
|
|
println!("cargo:rerun-if-changed=build.template");
|
2022-09-27 07:23:47 +02:00
|
|
|
println!("cargo:rerun-if-env-changed=RHAI_AHASH_SEED");
|
2022-11-01 13:25:45 +01:00
|
|
|
let mut contents = String::new();
|
2022-09-27 07:23:47 +02:00
|
|
|
|
2022-11-01 13:25:45 +01:00
|
|
|
File::open("build.template")
|
|
|
|
.expect("cannot open `build.template`")
|
|
|
|
.read_to_string(&mut contents)
|
|
|
|
.expect("cannot read from `build.template`");
|
2022-09-27 07:23:47 +02:00
|
|
|
|
2022-11-01 13:25:45 +01:00
|
|
|
let seed = env::var("RHAI_AHASH_SEED").map_or_else(|_| "None".into(), |s| format!("Some({s})"));
|
2022-09-27 07:23:47 +02:00
|
|
|
|
2022-11-04 07:36:18 +01:00
|
|
|
contents = contents.replace("{{AHASH_SEED}}", &seed);
|
2022-09-27 07:23:47 +02:00
|
|
|
|
2022-11-04 07:36:18 +01:00
|
|
|
File::create("src/config/hashing_env.rs")
|
2022-11-01 13:25:45 +01:00
|
|
|
.expect("cannot create `config.rs`")
|
|
|
|
.write_all(contents.as_bytes())
|
2022-11-04 07:36:18 +01:00
|
|
|
.expect("cannot write to `config/hashing_env.rs`");
|
2022-09-27 07:23:47 +02:00
|
|
|
}
|