Skip to content

Commit 2d854f9

Browse files
committed
Remove num_cpus dependency from bootstrap, build-manifest and rustc_session
1 parent c42d846 commit 2d854f9

File tree

9 files changed

+7
-11
lines changed

9 files changed

+7
-11
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ dependencies = [
221221
"getopts",
222222
"ignore",
223223
"libc",
224-
"num_cpus",
225224
"once_cell",
226225
"opener",
227226
"pretty_assertions",
@@ -249,7 +248,6 @@ dependencies = [
249248
"anyhow",
250249
"flate2",
251250
"hex 0.4.2",
252-
"num_cpus",
253251
"rayon",
254252
"serde",
255253
"serde_json",
@@ -4241,7 +4239,6 @@ name = "rustc_session"
42414239
version = "0.0.0"
42424240
dependencies = [
42434241
"getopts",
4244-
"num_cpus",
42454242
"rustc_ast",
42464243
"rustc_data_structures",
42474244
"rustc_errors",

compiler/rustc_session/Cargo.toml

-1
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

+1-1
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

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ test = false
3737
build_helper = { path = "../build_helper" }
3838
cmake = "0.1.38"
3939
filetime = "0.2"
40-
num_cpus = "1.0"
4140
getopts = "0.2.19"
4241
cc = "1.0.69"
4342
libc = "0.2"

src/bootstrap/config.rs

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

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

src/bootstrap/flags.rs

+1-1
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

+3-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,9 @@ impl Build {
917917
/// Returns the number of parallel jobs that have been configured for this
918918
/// build.
919919
fn jobs(&self) -> u32 {
920-
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
920+
self.config.jobs.unwrap_or_else(|| {
921+
std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
922+
})
921923
}
922924

923925
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,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

+1-1
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)