diff --git a/src/helpers.rs b/src/helpers.rs index 2732f1e7..c442e478 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,7 +1,9 @@ use std::fmt::Debug; use std::fs; use std::io; +use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; +use std::thread::available_parallelism; use bytes::Bytes; use cargo_toml::Manifest; @@ -42,6 +44,20 @@ pub async fn await_task(task: tokio::task::JoinHandle) -> miette::Result Result { + use jobserver::Client; + + // Safety: + // + // Client::from_env is unsafe because from_raw_fd is unsafe. + if let Some(client) = unsafe { Client::from_env() } { + Ok(client) + } else { + let ncore = available_parallelism().map(NonZeroUsize::get).unwrap_or(1); + Ok(Client::new(ncore)?) + } +} + /// Load binstall metadata from the crate `Cargo.toml` at the provided path pub fn load_manifest_path>( manifest_path: P,