You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
|
|
extern crate rustc_version;
|
|
extern crate num_cpus;
|
|
|
|
use rustc_version::{version, version_meta, Channel};
|
|
use std::io::{self, Write};
|
|
use std::fs::OpenOptions;
|
|
|
|
pub const DEFAULT_CPU_FILE: &str = "./src/consts.rs";
|
|
|
|
fn write_numcpus() -> io::Result<()>
|
|
{
|
|
let mut file = OpenOptions::new()
|
|
.write(true)
|
|
.create(true)
|
|
.truncate(true)
|
|
.open(DEFAULT_CPU_FILE)?;
|
|
|
|
writeln!(&mut file, "pub const CPUS: usize = {};", num_cpus::get())?;
|
|
writeln!(&mut file, "pub type PoolContainer<T> = [T; CPUS+1];")?;
|
|
file.flush()?;
|
|
Ok(())
|
|
}
|
|
|
|
fn main() {
|
|
// Assert we haven't travelled back in time
|
|
assert!(version().unwrap().major >= 1);
|
|
|
|
// Set cfg flags depending on release channel
|
|
match version_meta().unwrap().channel {
|
|
Channel::Stable => {
|
|
println!("cargo:rustc-cfg=stable");
|
|
}
|
|
Channel::Beta => {
|
|
println!("cargo:rustc-cfg=beta");
|
|
}
|
|
Channel::Nightly => {
|
|
println!("cargo:rustc-cfg=nightly");
|
|
}
|
|
Channel::Dev => {
|
|
println!("cargo:rustc-cfg=dev");
|
|
}
|
|
}
|
|
|
|
write_numcpus().expect("Failed to write comptime cpu info to source")
|
|
}
|