From bb2e4a93ca242bada80f2fc5cbd9c42573c3f35f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 2 Oct 2022 22:55:32 +0200 Subject: [PATCH] Allow configuring thread count. --- src/bin/builder.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bin/builder.rs b/src/bin/builder.rs index f8f4b34..6c903cf 100644 --- a/src/bin/builder.rs +++ b/src/bin/builder.rs @@ -96,8 +96,6 @@ struct Flavor { target: String, } -const NUM_THREADS: usize = 4; - fn load_manifest_bytes(crate_path: &Path) -> Vec { let manifest_path = crate_path.join("Cargo.toml"); fs::read(&manifest_path).unwrap() @@ -170,6 +168,14 @@ fn main() -> io::Result<()> { let mut zup_tree = zup::write::Tree::new(); let mut zup_flavors = Vec::new(); + let mut num_threads = 1usize; + if let Ok(v) = env::var("BUILDER_THREADS") { + if let Ok(n) = v.parse() { + num_threads = n; + } + } + println!("using {} threads", num_threads); + let args: Vec<_> = env::args().collect(); let crate_path = PathBuf::from(&args[1]); let output_path = PathBuf::from(&args[2]); @@ -197,7 +203,7 @@ fn main() -> io::Result<()> { thread::scope(|s| { // Spawn workers - for i in 0..NUM_THREADS { + for i in 0..num_threads { let j = i; let rx = ℞ let crate_path = &crate_path;