mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Merge pull request #161 from NobodyXu/feature/bin-multi-targets
This commit is contained in:
commit
6877a0c3a9
4 changed files with 30 additions and 11 deletions
|
@ -32,6 +32,9 @@ pub trait Fetcher: Send + Sync {
|
||||||
|
|
||||||
/// Should return true if the remote is from a third-party source
|
/// Should return true if the remote is from a third-party source
|
||||||
fn is_third_party(&self) -> bool;
|
fn is_third_party(&self) -> bool;
|
||||||
|
|
||||||
|
/// Return the target for this fetcher
|
||||||
|
fn target(&self) -> &str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data required to fetch a package
|
/// Data required to fetch a package
|
||||||
|
|
|
@ -67,6 +67,10 @@ impl super::Fetcher for GhCrateMeta {
|
||||||
fn is_third_party(&self) -> bool {
|
fn is_third_party(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn target(&self) -> &str {
|
||||||
|
&self.data.target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Template for constructing download paths
|
/// Template for constructing download paths
|
||||||
|
|
|
@ -14,6 +14,7 @@ const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VE
|
||||||
|
|
||||||
pub struct QuickInstall {
|
pub struct QuickInstall {
|
||||||
package: String,
|
package: String,
|
||||||
|
target: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -21,9 +22,10 @@ impl super::Fetcher for QuickInstall {
|
||||||
async fn new(data: &Data) -> Arc<Self> {
|
async fn new(data: &Data) -> Arc<Self> {
|
||||||
let crate_name = &data.name;
|
let crate_name = &data.name;
|
||||||
let version = &data.version;
|
let version = &data.version;
|
||||||
let target = &data.target;
|
let target = data.target.clone();
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
package: format!("{crate_name}-{version}-{target}"),
|
package: format!("{crate_name}-{version}-{target}"),
|
||||||
|
target,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +53,10 @@ impl super::Fetcher for QuickInstall {
|
||||||
fn is_third_party(&self) -> bool {
|
fn is_third_party(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn target(&self) -> &str {
|
||||||
|
&self.target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QuickInstall {
|
impl QuickInstall {
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -225,18 +225,24 @@ async fn entry() -> Result<()> {
|
||||||
.join(format!("pkg-{}.{}", opts.name, meta.pkg_fmt));
|
.join(format!("pkg-{}.{}", opts.name, meta.pkg_fmt));
|
||||||
debug!("Using temporary download path: {}", pkg_path.display());
|
debug!("Using temporary download path: {}", pkg_path.display());
|
||||||
|
|
||||||
let fetcher_data = Data {
|
let fetcher_data: Vec<_> = detect_targets()
|
||||||
name: package.name.clone(),
|
.await
|
||||||
target: opts.target.clone(),
|
.into_iter()
|
||||||
version: package.version.clone(),
|
.map(|target| Data {
|
||||||
repo: package.repository.clone(),
|
name: package.name.clone(),
|
||||||
meta: meta.clone(),
|
target: target.into(),
|
||||||
};
|
version: package.version.clone(),
|
||||||
|
repo: package.repository.clone(),
|
||||||
|
meta: meta.clone(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
// Try github releases, then quickinstall
|
// Try github releases, then quickinstall
|
||||||
let mut fetchers = MultiFetcher::default();
|
let mut fetchers = MultiFetcher::default();
|
||||||
fetchers.add(GhCrateMeta::new(&fetcher_data).await);
|
for data in &fetcher_data {
|
||||||
fetchers.add(QuickInstall::new(&fetcher_data).await);
|
fetchers.add(GhCrateMeta::new(data).await);
|
||||||
|
fetchers.add(QuickInstall::new(data).await);
|
||||||
|
}
|
||||||
|
|
||||||
match fetchers.first_available().await {
|
match fetchers.first_available().await {
|
||||||
Some(fetcher) => {
|
Some(fetcher) => {
|
||||||
|
@ -343,7 +349,7 @@ async fn install_from_package(
|
||||||
// based on those found via Cargo.toml
|
// based on those found via Cargo.toml
|
||||||
let bin_data = bins::Data {
|
let bin_data = bins::Data {
|
||||||
name: package.name.clone(),
|
name: package.name.clone(),
|
||||||
target: opts.target.clone(),
|
target: fetcher.target().to_string(),
|
||||||
version: package.version.clone(),
|
version: package.version.clone(),
|
||||||
repo: package.repository.clone(),
|
repo: package.repository.clone(),
|
||||||
meta,
|
meta,
|
||||||
|
|
Loading…
Add table
Reference in a new issue