Skip to content

Commit bf81d42

Browse files
committed
build-manifest: allow configuring the number of threads
1 parent 1681743 commit bf81d42

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ dependencies = [
243243
"anyhow",
244244
"flate2",
245245
"hex 0.4.2",
246+
"num_cpus",
246247
"rayon",
247248
"serde",
248249
"serde_json",

src/tools/build-manifest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ tar = "0.4.29"
1414
sha2 = "0.9.1"
1515
rayon = "1.3.1"
1616
hex = "0.4.2"
17+
num_cpus = "1.13.0"

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,18 @@ fn main() {
207207
// related code in this tool and ./x.py dist hash-and-sign can be removed.
208208
let legacy = env::var("BUILD_MANIFEST_LEGACY").is_ok();
209209

210-
// Avoid overloading the old server in legacy mode.
211-
if legacy {
212-
rayon::ThreadPoolBuilder::new()
213-
.num_threads(1)
214-
.build_global()
215-
.expect("failed to initialize Rayon");
216-
}
210+
let num_threads = if legacy {
211+
// Avoid overloading the old server in legacy mode.
212+
1
213+
} else if let Ok(num) = env::var("BUILD_MANIFEST_NUM_THREADS") {
214+
num.parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
215+
} else {
216+
num_cpus::get()
217+
};
218+
rayon::ThreadPoolBuilder::new()
219+
.num_threads(num_threads)
220+
.build_global()
221+
.expect("failed to initialize Rayon");
217222

218223
let mut args = env::args().skip(1);
219224
let input = PathBuf::from(args.next().unwrap());

0 commit comments

Comments
 (0)