mirror of https://github.com/rust-lang/cargo
Switch back to `available_parallelism`
This reverts commit 8345cf5037
. Since that
time, there are now multiple calls to get the number of CPUs, to handle
the `-j -NUM` case, so factor out a helper function.
This commit is contained in:
parent
ce40690a5e
commit
86163845a5
|
@ -44,7 +44,6 @@ libc = "0.2"
|
|||
log = "0.4.6"
|
||||
libgit2-sys = "0.13.2"
|
||||
memchr = "2.1.3"
|
||||
num_cpus = "1.0"
|
||||
opener = "0.5"
|
||||
os_info = "3.5.0"
|
||||
pathdiff = "0.2"
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use crate::core::compiler::CompileKind;
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::{CargoResult, Config, RustfixDiagnosticServer};
|
||||
use anyhow::bail;
|
||||
use anyhow::{bail, Context as _};
|
||||
use cargo_util::ProcessBuilder;
|
||||
use serde::ser;
|
||||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::thread::available_parallelism;
|
||||
|
||||
/// Configuration information for a rustc build.
|
||||
#[derive(Debug)]
|
||||
|
@ -45,6 +46,12 @@ pub struct BuildConfig {
|
|||
pub timing_outputs: Vec<TimingOutput>,
|
||||
}
|
||||
|
||||
fn default_parallelism() -> CargoResult<u32> {
|
||||
Ok(available_parallelism()
|
||||
.context("failed to determine the amount of parallelism available")?
|
||||
.get() as u32)
|
||||
}
|
||||
|
||||
impl BuildConfig {
|
||||
/// Parses all config files to learn about build configuration. Currently
|
||||
/// configured options are:
|
||||
|
@ -71,9 +78,9 @@ impl BuildConfig {
|
|||
)?;
|
||||
}
|
||||
let jobs = match jobs.or(cfg.jobs) {
|
||||
None => ::num_cpus::get() as u32,
|
||||
None => default_parallelism()?,
|
||||
Some(0) => anyhow::bail!("jobs may not be 0"),
|
||||
Some(j) if j < 0 => (::num_cpus::get() as i32 + j).max(1) as u32,
|
||||
Some(j) if j < 0 => (default_parallelism()? as i32 + j).max(1) as u32,
|
||||
Some(j) => j as u32,
|
||||
};
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use anyhow::Context as _;
|
|||
use cargo_util::paths;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{BufWriter, Write};
|
||||
use std::thread::available_parallelism;
|
||||
use std::time::{Duration, Instant, SystemTime};
|
||||
|
||||
pub struct Timings<'cfg> {
|
||||
|
@ -380,6 +381,9 @@ impl<'cfg> Timings<'cfg> {
|
|||
};
|
||||
let total_time = format!("{:.1}s{}", duration, time_human);
|
||||
let max_concurrency = self.concurrency.iter().map(|c| c.active).max().unwrap();
|
||||
let num_cpus = available_parallelism()
|
||||
.map(|x| x.get().to_string())
|
||||
.unwrap_or_else(|_| "n/a".into());
|
||||
let max_rustc_concurrency = self
|
||||
.concurrency
|
||||
.iter()
|
||||
|
@ -442,7 +446,7 @@ impl<'cfg> Timings<'cfg> {
|
|||
self.total_fresh + self.total_dirty,
|
||||
max_concurrency,
|
||||
bcx.jobs(),
|
||||
num_cpus::get(),
|
||||
num_cpus,
|
||||
self.start_str,
|
||||
total_time,
|
||||
rustc_info,
|
||||
|
|
Loading…
Reference in New Issue