build-manifest: allow configuring the number of threads

This commit is contained in:
Pietro Albini 2020-10-12 17:47:37 +02:00
parent 24d04ccd39
commit f3d07b36ed
No known key found for this signature in database
GPG Key ID: 3E06ABE80BAAF19C
3 changed files with 14 additions and 7 deletions

View File

@ -243,6 +243,7 @@ dependencies = [
"anyhow",
"flate2",
"hex 0.4.2",
"num_cpus",
"rayon",
"serde",
"serde_json",

View File

@ -14,3 +14,4 @@ tar = "0.4.29"
sha2 = "0.9.1"
rayon = "1.3.1"
hex = "0.4.2"
num_cpus = "1.13.0"

View File

@ -207,13 +207,18 @@ fn main() {
// related code in this tool and ./x.py dist hash-and-sign can be removed.
let legacy = env::var("BUILD_MANIFEST_LEGACY").is_ok();
// Avoid overloading the old server in legacy mode.
if legacy {
rayon::ThreadPoolBuilder::new()
.num_threads(1)
.build_global()
.expect("failed to initialize Rayon");
}
let num_threads = if legacy {
// Avoid overloading the old server in legacy mode.
1
} else if let Ok(num) = env::var("BUILD_MANIFEST_NUM_THREADS") {
num.parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
} else {
num_cpus::get()
};
rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build_global()
.expect("failed to initialize Rayon");
let mut args = env::args().skip(1);
let input = PathBuf::from(args.next().unwrap());