Skip to content

Commit 1ae4b25

Browse files
committed
Revert "Remove num_cpus dependency from bootstrap, build-manifest and rustc_session"
This reverts commit 2d854f9.
1 parent fde0f11 commit 1ae4b25

File tree

9 files changed

+11
-7
lines changed

9 files changed

+11
-7
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ dependencies = [
219219
"hex 0.4.2",
220220
"ignore",
221221
"libc",
222+
"num_cpus",
222223
"once_cell",
223224
"opener",
224225
"pretty_assertions 0.7.2",
@@ -250,6 +251,7 @@ dependencies = [
250251
"anyhow",
251252
"flate2",
252253
"hex 0.4.2",
254+
"num_cpus",
253255
"rayon",
254256
"serde",
255257
"serde_json",
@@ -4419,6 +4421,7 @@ name = "rustc_session"
44194421
version = "0.0.0"
44204422
dependencies = [
44214423
"getopts",
4424+
"num_cpus",
44224425
"rustc_ast",
44234426
"rustc_data_structures",
44244427
"rustc_errors",

compiler/rustc_session/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ 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"
1819
rustc_ast = { path = "../rustc_ast" }
1920
rustc_lint_defs = { path = "../rustc_lint_defs" }

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ mod parse {
578578
pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
579579
match v.and_then(|s| s.parse().ok()) {
580580
Some(0) => {
581-
*slot = std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get);
581+
*slot = ::num_cpus::get();
582582
true
583583
}
584584
Some(i) => {

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ test = false
3737
[dependencies]
3838
cmake = "0.1.38"
3939
filetime = "0.2"
40+
num_cpus = "1.0"
4041
getopts = "0.2.19"
4142
cc = "1.0.69"
4243
libc = "0.2"

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ fn set<T>(field: &mut T, val: Option<T>) {
14181418

14191419
fn threads_from_config(v: u32) -> u32 {
14201420
match v {
1421-
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
1421+
0 => num_cpus::get() as u32,
14221422
n => n,
14231423
}
14241424
}

src/bootstrap/flags.rs

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

src/bootstrap/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1032,9 +1032,7 @@ impl Build {
10321032
/// Returns the number of parallel jobs that have been configured for this
10331033
/// build.
10341034
fn jobs(&self) -> u32 {
1035-
self.config.jobs.unwrap_or_else(|| {
1036-
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
1037-
})
1035+
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
10381036
}
10391037

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

src/tools/build-manifest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ 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

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn main() {
210210
let num_threads = if let Some(num) = env::var_os("BUILD_MANIFEST_NUM_THREADS") {
211211
num.to_str().unwrap().parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
212212
} else {
213-
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get)
213+
num_cpus::get()
214214
};
215215
rayon::ThreadPoolBuilder::new()
216216
.num_threads(num_threads)

0 commit comments

Comments
 (0)