parent
9271879298
commit
8b996f5698
@ -0,0 +1,46 @@
|
||||
|
||||
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")
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
pub const CPUS: usize = 8;
|
||||
pub type PoolContainer<T> = [T; CPUS+1];
|
Loading…
Reference in new issue