Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
44 lines (37 loc) · 1.63 KB
/
Copy pathbuild.rs
File metadata and controls
44 lines (37 loc) · 1.63 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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");
println!("cargo:rerun-if-env-changed=RHAI_NO_ATOMIC64");
// The operations count is a `Cell<u64>` without `sync`. With `sync`, it is an
// `AtomicU64` where the target has 64-bit atomics, and a plain `u64` otherwise.
// Setting `RHAI_NO_ATOMIC64` forces the plain `u64` fallback for `sync` builds.
println!("cargo:rustc-check-cfg=cfg(atomic_ops_count)");
let has_atomic64 =
env::var("CARGO_CFG_TARGET_HAS_ATOMIC").map_or(false, |v| v.split(',').any(|w| w == "64"));
if env::var_os("CARGO_FEATURE_SYNC").is_some()
&& has_atomic64
&& env::var_os("RHAI_NO_ATOMIC64").is_none()
{
println!("cargo:rustc-cfg=atomic_ops_count");
}
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 `hashing_env.rs`")
.write_all(contents.as_bytes())
.expect("cannot write to `config/hashing_env.rs`");
}