Skip to content

Commit

Permalink
Allow configuring thread count.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Oct 2, 2022
1 parent a6a1143 commit bb2e4a9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ struct Flavor {
target: String,
}

const NUM_THREADS: usize = 4;

fn load_manifest_bytes(crate_path: &Path) -> Vec<u8> {
let manifest_path = crate_path.join("Cargo.toml");
fs::read(&manifest_path).unwrap()
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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 = &rx;
let crate_path = &crate_path;
Expand Down

0 comments on commit bb2e4a9

Please sign in to comment.