Skip to content

Commit

Permalink
build-manifest: allow configuring the number of threads
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Oct 12, 2020
1 parent 24d04cc commit f3d07b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ dependencies = [
"anyhow",
"flate2",
"hex 0.4.2",
"num_cpus",
"rayon",
"serde",
"serde_json",
Expand Down
1 change: 1 addition & 0 deletions src/tools/build-manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 12 additions & 7 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit f3d07b3

Please sign in to comment.