forked from rhaiscript/rhai
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
29 lines (24 loc) · 975 Bytes
/
build.rs
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
use std::{
env,
fs::File,
io::{Read, Write},
};
fn main() {
// Tell Cargo that if the given environment variable changes, to rerun this build script.
println!("cargo:rerun-if-changed=build.template");
println!("cargo:rerun-if-env-changed=RHAI_AHASH_SEED");
println!("cargo:rerun-if-env-changed=RHAI_HASHING_SEED");
let mut contents = String::new();
File::open("build.template")
.expect("cannot open `build.template`")
.read_to_string(&mut contents)
.expect("cannot read from `build.template`");
let seed = env::var("RHAI_HASHING_SEED")
.or_else(|_| env::var("RHAI_AHASH_SEED"))
.map_or_else(|_| "None".into(), |s| format!("Some({s})"));
contents = contents.replace("{{HASHING_SEED}}", &seed);
File::create("src/config/hashing_env.rs")
.expect("cannot create `config.rs`")
.write_all(contents.as_bytes())
.expect("cannot write to `config/hashing_env.rs`");
}