-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.rs
37 lines (32 loc) · 1.14 KB
/
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
30
31
32
33
34
35
36
37
use std::env;
use std::fs;
use std::path::Path;
use std::process;
const CARGO_TALLY_MEMORY_LIMIT: &str = "CARGO_TALLY_MEMORY_LIMIT";
fn main() {
let limit = if let Some(value) = env::var_os(CARGO_TALLY_MEMORY_LIMIT) {
let Some(value) = value.to_str() else {
eprintln!("failed to parse ${CARGO_TALLY_MEMORY_LIMIT}");
process::exit(1);
};
let value = match value.parse::<u64>() {
Ok(int) => int,
Err(err) => {
eprintln!("failed to parse ${CARGO_TALLY_MEMORY_LIMIT}: {err}");
process::exit(1);
}
};
Some(value)
} else {
None
};
let out_dir = env::var_os("OUT_DIR").unwrap();
let out = Path::new(&out_dir).join("limit.mem");
fs::write(out, format!("{limit:?}\n")).unwrap();
let host = env::var_os("HOST").unwrap();
if let Some("windows") = host.to_str().unwrap().split('-').nth(2) {
println!("cargo:rustc-cfg=host_os=\"windows\"");
}
println!("cargo:rerun-if-env-changed={CARGO_TALLY_MEMORY_LIMIT}");
println!("cargo:rustc-check-cfg=cfg(host_os, values(\"windows\"))");
}