From 6fe23efe369a19bcaca0539f970162a2ae4bb03b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 8 Jan 2020 07:54:17 -0800 Subject: [PATCH] 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. --- Cargo.toml | 3 +-- src/lib.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b8b8ec..3217642 100644 --- a/Cargo.toml +++ b/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" diff --git a/src/lib.rs b/src/lib.rs index 2b15d17..cc1d58c 100644 --- a/src/lib.rs +++ b/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;