-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
22 lines (18 loc) · 731 Bytes
/
Copy pathbuild.rs
File metadata and controls
22 lines (18 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::env;
use std::fs;
use std::path::Path;
fn main() {
let parallelism: usize = if let Ok(n) = std::thread::available_parallelism() {
n.into()
} else {
2
};
let environment =
env::var("OUT_DIR").expect("Could not interpret the OUT_DIR environment variable!");
let destination = Path::new(&environment).join("available.rs");
let data = format!("pub const AVAILABLE_PARALLELISM: usize = {};", parallelism);
fs::write(destination, data).expect("Full directory path does not exist!");
// Rerun the build script only if it changes because on any particular machine the amount of parallelism
// is going to be same!
println!("cargo::rerun-if-changed=build.rs");
}