From fde0f1195f5381c36af2d23b24f7627ef91519f9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 9 Jun 2022 03:07:19 -0700 Subject: [PATCH 1/3] Update cargo 1 commit in 85e457e158db216a2938d51bc3b617a5a7fe6015..4d92f07f34ba7fb7d7f207564942508f46c225d3 2022-06-07 21:57:52 +0000 to 2022-06-09 01:18:36 +0000 - Revert 10427: switch from num_cpus --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 85e457e158db2..4d92f07f34ba7 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 85e457e158db216a2938d51bc3b617a5a7fe6015 +Subproject commit 4d92f07f34ba7fb7d7f207564942508f46c225d3 From 1ae4b258267462da0b1aae1badcf83578153c799 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 9 Jun 2022 03:10:15 -0700 Subject: [PATCH 2/3] Revert "Remove num_cpus dependency from bootstrap, build-manifest and rustc_session" This reverts commit 2d854f9c340df887e30896f49270ae81feb3e227. --- Cargo.lock | 3 +++ compiler/rustc_session/Cargo.toml | 1 + compiler/rustc_session/src/options.rs | 2 +- src/bootstrap/Cargo.toml | 1 + src/bootstrap/config.rs | 2 +- src/bootstrap/flags.rs | 2 +- src/bootstrap/lib.rs | 4 +--- src/tools/build-manifest/Cargo.toml | 1 + src/tools/build-manifest/src/main.rs | 2 +- 9 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72fa97d1f77e3..2611a8f682407 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -219,6 +219,7 @@ dependencies = [ "hex 0.4.2", "ignore", "libc", + "num_cpus", "once_cell", "opener", "pretty_assertions 0.7.2", @@ -250,6 +251,7 @@ dependencies = [ "anyhow", "flate2", "hex 0.4.2", + "num_cpus", "rayon", "serde", "serde_json", @@ -4419,6 +4421,7 @@ name = "rustc_session" version = "0.0.0" dependencies = [ "getopts", + "num_cpus", "rustc_ast", "rustc_data_structures", "rustc_errors", diff --git a/compiler/rustc_session/Cargo.toml b/compiler/rustc_session/Cargo.toml index 6b1eaa4d399d9..37cfc4a0dc3c2 100644 --- a/compiler/rustc_session/Cargo.toml +++ b/compiler/rustc_session/Cargo.toml @@ -15,5 +15,6 @@ rustc_serialize = { path = "../rustc_serialize" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_span = { path = "../rustc_span" } rustc_fs_util = { path = "../rustc_fs_util" } +num_cpus = "1.0" rustc_ast = { path = "../rustc_ast" } rustc_lint_defs = { path = "../rustc_lint_defs" } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 181acc224fa9c..d89c61c2e44c6 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -578,7 +578,7 @@ mod parse { pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool { match v.and_then(|s| s.parse().ok()) { Some(0) => { - *slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get); + *slot = ::num_cpus::get(); true } Some(i) => { diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 0e54837610a4b..f5d9e46f9e21b 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -37,6 +37,7 @@ test = false [dependencies] cmake = "0.1.38" filetime = "0.2" +num_cpus = "1.0" getopts = "0.2.19" cc = "1.0.69" libc = "0.2" diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 99b69ee9a4fd1..28663af135cd8 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1418,7 +1418,7 @@ fn set(field: &mut T, val: Option) { fn threads_from_config(v: u32) -> u32 { match v { - 0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32, + 0 => num_cpus::get() as u32, n => n, } } diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index f692ff72d4eb9..9d4bb978bdc4d 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -210,7 +210,7 @@ To learn more about a subcommand, run `./x.py -h`", let j_msg = format!( "number of jobs to run in parallel; \ defaults to {} (this host's logical CPU count)", - std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) + num_cpus::get() ); opts.optopt("j", "jobs", &j_msg, "JOBS"); opts.optflag("h", "help", "print this help message"); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 022f2e0fc1387..b4333566f07d9 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1032,9 +1032,7 @@ impl Build { /// Returns the number of parallel jobs that have been configured for this /// build. fn jobs(&self) -> u32 { - self.config.jobs.unwrap_or_else(|| { - std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32 - }) + self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32) } fn debuginfo_map_to(&self, which: GitRepo) -> Option { diff --git a/src/tools/build-manifest/Cargo.toml b/src/tools/build-manifest/Cargo.toml index c437bde5ae69a..c022d3aa0acd7 100644 --- a/src/tools/build-manifest/Cargo.toml +++ b/src/tools/build-manifest/Cargo.toml @@ -13,3 +13,4 @@ tar = "0.4.29" sha2 = "0.10.1" rayon = "1.5.1" hex = "0.4.2" +num_cpus = "1.13.0" diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index a1dfbef0601ad..6338e467055cd 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -210,7 +210,7 @@ fn main() { let num_threads = if let Some(num) = env::var_os("BUILD_MANIFEST_NUM_THREADS") { num.to_str().unwrap().parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS") } else { - std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) + num_cpus::get() }; rayon::ThreadPoolBuilder::new() .num_threads(num_threads) From fbc86e07a94490fd23b9ef0fdd0f9118c50e5780 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 9 Jun 2022 03:52:43 -0700 Subject: [PATCH 3/3] Regenerate lockfile to include cargo's dependency on num_cpus --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 2611a8f682407..51b0da65b3145 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,6 +351,7 @@ dependencies = [ "libgit2-sys", "log", "memchr", + "num_cpus", "opener", "openssl", "os_info",