Use template to create config.rs.
This commit is contained in:
parent
5035dcbf47
commit
9b226f321e
30
build.rs
30
build.rs
@ -1,26 +1,26 @@
|
|||||||
use std::{env, fs::File, io::Write};
|
use std::{
|
||||||
|
env,
|
||||||
const WRITE_ERROR: &str = "cannot write to `config.rs`";
|
fs::File,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Tell Cargo that if the given environment variable changes, to rerun this build script.
|
// Tell Cargo that if the given environment variable changes, to rerun this build script.
|
||||||
println!("cargo:rerun-if-env-changed=RHAI_AHASH_SEED");
|
println!("cargo:rerun-if-env-changed=RHAI_AHASH_SEED");
|
||||||
|
|
||||||
let mut f = File::create("src/config.rs").expect("cannot create `config.rs`");
|
let mut contents = String::new();
|
||||||
|
|
||||||
f.write_fmt(format_args!(
|
File::open("build.template")
|
||||||
"//! Configuration settings for this Rhai build
|
.expect("cannot open `build.template`")
|
||||||
|
.read_to_string(&mut contents)
|
||||||
"
|
.expect("cannot read from `build.template`");
|
||||||
))
|
|
||||||
.expect(WRITE_ERROR);
|
|
||||||
|
|
||||||
let seed = env::var("RHAI_AHASH_SEED").map_or_else(|_| "None".into(), |s| format!("Some({s})"));
|
let seed = env::var("RHAI_AHASH_SEED").map_or_else(|_| "None".into(), |s| format!("Some({s})"));
|
||||||
|
|
||||||
f.write_fmt(format_args!(
|
contents = contents.replace("{{AHASH_SEED}}", &seed);
|
||||||
"pub const AHASH_SEED: Option<[u64; 4]> = {seed};\n"
|
|
||||||
))
|
|
||||||
.expect(WRITE_ERROR);
|
|
||||||
|
|
||||||
f.flush().expect("cannot flush `config.rs`");
|
File::create("src/config.rs")
|
||||||
|
.expect("cannot create `config.rs`")
|
||||||
|
.write(contents.as_bytes())
|
||||||
|
.expect("cannot write to `config.rs`");
|
||||||
}
|
}
|
||||||
|
5
build.template
Normal file
5
build.template
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//! Configuration settings for this Rhai build
|
||||||
|
|
||||||
|
/// Fixed hashing seeds for stable hashing.
|
||||||
|
/// Set to [`None`] to disable stable hashing.
|
||||||
|
pub const AHASH_SEED: Option<[u64; 4]> = {{AHASH_SEED}};
|
@ -1,3 +1,5 @@
|
|||||||
//! Configuration settings for this Rhai build
|
//! Configuration settings for this Rhai build
|
||||||
|
|
||||||
|
/// Fixed hashing seeds for stable hashing.
|
||||||
|
/// Set to [`None`] to disable stable hashing.
|
||||||
pub const AHASH_SEED: Option<[u64; 4]> = None;
|
pub const AHASH_SEED: Option<[u64; 4]> = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user