mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Impl new fn helpers::create_jobserver_client
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
8cc085b1b6
commit
c67c59b3ca
1 changed files with 16 additions and 0 deletions
|
@ -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<T>(task: tokio::task::JoinHandle<T>) -> miette::Result<T
|
|||
.map_err(|join_err| miette::miette!("Task failed to join: {}", join_err))
|
||||
}
|
||||
|
||||
pub fn create_jobserver_client() -> Result<jobserver::Client, BinstallError> {
|
||||
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<P: AsRef<Path>>(
|
||||
manifest_path: P,
|
||||
|
|
Loading…
Add table
Reference in a new issue