Split crates and clean up structure of codebase (#294)

Co-authored-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Félix Saparelli 2022-08-20 23:24:12 +12:00 committed by GitHub
parent bf700f9012
commit 4b00f5f143
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 2989 additions and 1423 deletions

View file

@ -0,0 +1,102 @@
//! The format of the `[package.metadata.binstall]` manifest.
//!
//! This manifest defines how a particular binary crate may be installed by Binstall.
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[doc(inline)]
pub use package_formats::*;
mod package_formats;
/// Default package path template (may be overridden in package Cargo.toml)
pub const DEFAULT_PKG_URL: &str =
"{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }";
/// Default binary name template (may be overridden in package Cargo.toml)
pub const DEFAULT_BIN_DIR: &str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
/// `binstall` metadata container
///
/// Required to nest metadata under `package.metadata.binstall`
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Meta {
pub binstall: Option<PkgMeta>,
}
/// Metadata for binary installation use.
///
/// Exposed via `[package.metadata]` in `Cargo.toml`
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct PkgMeta {
/// URL template for package downloads
pub pkg_url: String,
/// Format for package downloads
pub pkg_fmt: PkgFmt,
/// Path template for binary files in packages
pub bin_dir: String,
/// Public key for package verification (base64 encoded)
pub pub_key: Option<String>,
/// Target specific overrides
pub overrides: HashMap<String, PkgOverride>,
}
impl Default for PkgMeta {
fn default() -> Self {
Self {
pkg_url: DEFAULT_PKG_URL.to_string(),
pkg_fmt: PkgFmt::default(),
bin_dir: DEFAULT_BIN_DIR.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_url {
self.pkg_url = o.clone();
}
if let Some(o) = &pkg_override.pkg_fmt {
self.pkg_fmt = *o;
}
if let Some(o) = &pkg_override.bin_dir {
self.bin_dir = o.clone();
}
}
}
/// Target specific overrides for binary installation
///
/// Exposed via `[package.metadata.TARGET]` in `Cargo.toml`
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct PkgOverride {
/// URL template override for package downloads
pub pkg_url: Option<String>,
/// Format override for package downloads
pub pkg_fmt: Option<PkgFmt>,
/// Path template override for binary files in packages
pub bin_dir: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct BinMeta {
/// Binary name
pub name: String,
/// Binary template path (within package)
pub path: String,
}