Skip to content

Commit 0d09da8

Browse files
authored
Rollup merge of rust-lang#94524 - bjorn3:remove_num_cpus, r=Mark-Simulacrum
Remove num_cpus dependency from bootstrap, build-manifest and rustc_s… …ession `std::threads::available_parallelism` was stabilized in rust 1.59. r? `````````````````````````@Mark-Simulacrum`````````````````````````
2 parents 0f0be41 + 2d854f9 commit 0d09da8

File tree

9 files changed

+7
-11
lines changed

9 files changed

+7
-11
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ dependencies = [
220220
"getopts",
221221
"ignore",
222222
"libc",
223-
"num_cpus",
224223
"once_cell",
225224
"opener",
226225
"pretty_assertions",
@@ -248,7 +247,6 @@ dependencies = [
248247
"anyhow",
249248
"flate2",
250249
"hex 0.4.2",
251-
"num_cpus",
252250
"rayon",
253251
"serde",
254252
"serde_json",
@@ -4236,7 +4234,6 @@ name = "rustc_session"
42364234
version = "0.0.0"
42374235
dependencies = [
42384236
"getopts",
4239-
"num_cpus",
42404237
"rustc_ast",
42414238
"rustc_data_structures",
42424239
"rustc_errors",

compiler/rustc_session/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ rustc_serialize = { path = "../rustc_serialize" }
1515
rustc_data_structures = { path = "../rustc_data_structures" }
1616
rustc_span = { path = "../rustc_span" }
1717
rustc_fs_util = { path = "../rustc_fs_util" }
18-
num_cpus = "1.0"
1918
rustc_ast = { path = "../rustc_ast" }
2019
rustc_lint_defs = { path = "../rustc_lint_defs" }

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ mod parse {
551551
crate fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
552552
match v.and_then(|s| s.parse().ok()) {
553553
Some(0) => {
554-
*slot = ::num_cpus::get();
554+
*slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
555555
true
556556
}
557557
Some(i) => {

src/bootstrap/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ test = false
3636
[dependencies]
3737
cmake = "0.1.38"
3838
filetime = "0.2"
39-
num_cpus = "1.0"
4039
getopts = "0.2.19"
4140
cc = "1.0.69"
4241
libc = "0.2"

src/bootstrap/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ fn set<T>(field: &mut T, val: Option<T>) {
11861186

11871187
fn threads_from_config(v: u32) -> u32 {
11881188
match v {
1189-
0 => num_cpus::get() as u32,
1189+
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
11901190
n => n,
11911191
}
11921192
}

src/bootstrap/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
208208
let j_msg = format!(
209209
"number of jobs to run in parallel; \
210210
defaults to {} (this host's logical CPU count)",
211-
num_cpus::get()
211+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
212212
);
213213
opts.optopt("j", "jobs", &j_msg, "JOBS");
214214
opts.optflag("h", "help", "print this help message");

src/bootstrap/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,9 @@ impl Build {
923923
/// Returns the number of parallel jobs that have been configured for this
924924
/// build.
925925
fn jobs(&self) -> u32 {
926-
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
926+
self.config.jobs.unwrap_or_else(|| {
927+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
928+
})
927929
}
928930

929931
fn debuginfo_map_to(&self, which: GitRepo) -> Option<String> {

src/tools/build-manifest/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ tar = "0.4.29"
1313
sha2 = "0.10.1"
1414
rayon = "1.5.1"
1515
hex = "0.4.2"
16-
num_cpus = "1.13.0"

src/tools/build-manifest/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn main() {
208208
let num_threads = if let Some(num) = env::var_os("BUILD_MANIFEST_NUM_THREADS") {
209209
num.to_str().unwrap().parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
210210
} else {
211-
num_cpus::get()
211+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
212212
};
213213
rayon::ThreadPoolBuilder::new()
214214
.num_threads(num_threads)

0 commit comments

Comments
 (0)