Browse Source

Don't depend on `num_cpus` for parallelism

We almost never use it anyway and it's an extra dependency that
complicates the build process of rust-lang/rust. Let's just stick to a
smaller default in the case that we're running entirely outside of a
Cargo context, which should be pretty rare anyway.
master
Alex Crichton 5 years ago
parent
commit
6fe23efe36
  1. 3
      Cargo.toml
  2. 10
      src/lib.rs

3
Cargo.toml

@ -18,11 +18,10 @@ exclude = ["/.travis.yml", "/appveyor.yml"]
edition = "2018"
[dependencies]
num_cpus = { version = "1.10", optional = true }
jobserver = { version = "0.1.16", optional = true }
[features]
parallel = ["num_cpus", "jobserver"]
parallel = ["jobserver"]
[dev-dependencies]
tempfile = "3"

10
src/lib.rs

@ -1101,9 +1101,13 @@ impl Build {
return client;
}
// ... but if that fails for whatever reason fall back to the number
// of cpus on the system or the `NUM_JOBS` env var.
let mut parallelism = num_cpus::get();
// ... but if that fails for whatever reason select something
// reasonable and crate a new jobserver. Use `NUM_JOBS` if set (it's
// configured by Cargo) and otherwise just fall back to a
// semi-reasonable number. Note that we could use `num_cpus` here
// but it's an extra dependency that will almost never be used, so
// it's generally not too worth it.
let mut parallelism = 4;
if let Ok(amt) = env::var("NUM_JOBS") {
if let Ok(amt) = amt.parse() {
parallelism = amt;

Loading…
Cancel
Save