mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 04:00:02 +00:00
added zip support, pkg-fmt override
swapped CI to build zips for windows
This commit is contained in:
parent
94ad0db41d
commit
1c25b1346f
7 changed files with 160 additions and 24 deletions
|
@ -7,7 +7,7 @@ use cargo_toml::{Manifest};
|
|||
use flate2::read::GzDecoder;
|
||||
use tar::Archive;
|
||||
use xz2::read::XzDecoder;
|
||||
|
||||
use zip::read::ZipArchive;
|
||||
|
||||
use crate::{Meta};
|
||||
|
||||
|
@ -77,6 +77,15 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(source: S, fmt: PkgFmt, path: P)
|
|||
|
||||
txz.unpack(path)?;
|
||||
},
|
||||
PkgFmt::Zip => {
|
||||
// Extract to install dir
|
||||
debug!("Decompressing from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||
|
||||
let dat = std::fs::File::open(source)?;
|
||||
let mut zip = ZipArchive::new(dat)?;
|
||||
|
||||
zip.extract(path)?;
|
||||
},
|
||||
PkgFmt::Bin => {
|
||||
debug!("Copying data from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||
// Copy to install dir
|
||||
|
|
38
src/lib.rs
38
src/lib.rs
|
@ -1,3 +1,6 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use strum_macros::{Display, EnumString, EnumVariantNames};
|
||||
use tinytemplate::TinyTemplate;
|
||||
|
@ -21,6 +24,7 @@ pub const DEFAULT_BIN_PATH: &'static str = "{ name }-{ target }-v{ version }/{ b
|
|||
|
||||
|
||||
/// Binary format enumeration
|
||||
/// This defaults to .zip on windows and .tgz on all other platforms
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Display, EnumString, EnumVariantNames)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
|
@ -32,6 +36,8 @@ pub enum PkgFmt {
|
|||
Tgz,
|
||||
/// Download format is TAR + XZ
|
||||
Txz,
|
||||
/// Download format is Zip
|
||||
Zip,
|
||||
/// Download format is raw / binary
|
||||
Bin,
|
||||
}
|
||||
|
@ -68,6 +74,9 @@ pub struct PkgMeta {
|
|||
|
||||
/// Public key for package verification (base64 encoded)
|
||||
pub pub_key: Option<String>,
|
||||
|
||||
/// Target specific overrides
|
||||
pub overrides: HashMap<String, PkgOverride>,
|
||||
}
|
||||
|
||||
impl Default for PkgMeta {
|
||||
|
@ -77,10 +86,39 @@ impl Default for PkgMeta {
|
|||
pkg_fmt: PkgFmt::default(),
|
||||
bin_dir: DEFAULT_BIN_PATH.to_string(),
|
||||
pub_key: None,
|
||||
overrides: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PkgMeta {
|
||||
/// Merge configuration overrides into object
|
||||
pub fn merge(&mut self, pkg_override: &PkgOverride) {
|
||||
if let Some(o) = pkg_override.pkg_fmt {
|
||||
self.pkg_fmt = o;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Target specific overrides for binary installation
|
||||
///
|
||||
/// Exposed via `[package.metadata.TARGET]` in `Cargo.toml`
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case", default)]
|
||||
pub struct PkgOverride {
|
||||
/// Format for package downloads
|
||||
pub pkg_fmt: Option<PkgFmt>,
|
||||
}
|
||||
|
||||
impl Default for PkgOverride {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pkg_fmt: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct BinMeta {
|
||||
|
|
|
@ -97,11 +97,18 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
let manifest = load_manifest_path(manifest_path.join("Cargo.toml"))?;
|
||||
let package = manifest.package.unwrap();
|
||||
|
||||
let (meta, binaries) = (
|
||||
let (mut meta, binaries) = (
|
||||
package.metadata.map(|m| m.binstall ).flatten().unwrap_or(PkgMeta::default()),
|
||||
manifest.bin,
|
||||
);
|
||||
|
||||
// Merge any overrides
|
||||
if let Some(o) = meta.overrides.remove(&opts.target) {
|
||||
meta.merge(&o);
|
||||
}
|
||||
|
||||
debug!("Found metadata: {:?}", meta);
|
||||
|
||||
// Generate context for URL interpolation
|
||||
let ctx = Context {
|
||||
name: opts.name.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue