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", "anyhow",
"flate2", "flate2",
"hex 0.4.2", "hex 0.4.2",
"num_cpus",
"rayon", "rayon",
"serde", "serde",
"serde_json", "serde_json",

View File

@ -14,3 +14,4 @@ tar = "0.4.29"
sha2 = "0.9.1" sha2 = "0.9.1"
rayon = "1.3.1" rayon = "1.3.1"
hex = "0.4.2" 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. // related code in this tool and ./x.py dist hash-and-sign can be removed.
let legacy = env::var("BUILD_MANIFEST_LEGACY").is_ok(); let legacy = env::var("BUILD_MANIFEST_LEGACY").is_ok();
// Avoid overloading the old server in legacy mode. let num_threads = if legacy {
if legacy { // Avoid overloading the old server in legacy mode.
rayon::ThreadPoolBuilder::new() 1
.num_threads(1) } else if let Ok(num) = env::var("BUILD_MANIFEST_NUM_THREADS") {
.build_global() num.parse().expect("invalid number for BUILD_MANIFEST_NUM_THREADS")
.expect("failed to initialize Rayon"); } 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 mut args = env::args().skip(1);
let input = PathBuf::from(args.next().unwrap()); let input = PathBuf::from(args.next().unwrap());