mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Refactor: Extract new mod jobserver_client.rs
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
2490cd5a84
commit
a1d7a7c117
2 changed files with 23 additions and 18 deletions
|
@ -1,9 +1,7 @@
|
|||
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;
|
||||
|
@ -30,6 +28,9 @@ pub use ui_thread::UIThread;
|
|||
mod extracter;
|
||||
mod stream_readable;
|
||||
|
||||
mod jobserver_client;
|
||||
pub use jobserver_client::*;
|
||||
|
||||
mod path_ext;
|
||||
pub use path_ext::*;
|
||||
|
||||
|
@ -46,22 +47,6 @@ pub async fn await_task<T>(task: tokio::task::JoinHandle<miette::Result<T>>) ->
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_jobserver_client() -> Result<jobserver::Client, BinstallError> {
|
||||
use jobserver::Client;
|
||||
|
||||
// Safety:
|
||||
//
|
||||
// Client::from_env is unsafe because from_raw_fd is unsafe.
|
||||
// It doesn't do anything that is actually unsafe, like
|
||||
// dereferencing pointer.
|
||||
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,
|
||||
|
|
20
src/helpers/jobserver_client.rs
Normal file
20
src/helpers/jobserver_client.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use std::num::NonZeroUsize;
|
||||
use std::thread::available_parallelism;
|
||||
|
||||
use crate::BinstallError;
|
||||
|
||||
pub fn create_jobserver_client() -> Result<jobserver::Client, BinstallError> {
|
||||
use jobserver::Client;
|
||||
|
||||
// Safety:
|
||||
//
|
||||
// Client::from_env is unsafe because from_raw_fd is unsafe.
|
||||
// It doesn't do anything that is actually unsafe, like
|
||||
// dereferencing pointer.
|
||||
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)?)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue