From 3b8b4b940fdbbf1be5b851f0c78cfd3b14ad98f9 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 1 Oct 2023 23:26:01 +1100 Subject: [PATCH] Add initial data structure for `dist-manifest.json` Signed-off-by: Jiahao XU --- Cargo.lock | 1 + crates/binstalk-fetchers/Cargo.toml | 3 +- .../src/dist_manifest_fetcher.rs | 51 +++++++++++++++++++ crates/binstalk-fetchers/src/lib.rs | 5 ++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 crates/binstalk-fetchers/src/dist_manifest_fetcher.rs diff --git a/Cargo.lock b/Cargo.lock index e2eb3740..634ad0d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,6 +303,7 @@ dependencies = [ "miette", "minisign-verify", "once_cell", + "serde", "strum", "thiserror", "tokio", diff --git a/crates/binstalk-fetchers/Cargo.toml b/crates/binstalk-fetchers/Cargo.toml index 1f2b17c6..947e7c74 100644 --- a/crates/binstalk-fetchers/Cargo.toml +++ b/crates/binstalk-fetchers/Cargo.toml @@ -24,6 +24,7 @@ leon-macros = { version = "1.0.0", path = "../leon-macros" } miette = "5.9.0" minisign-verify = "0.2.1" once_cell = "1.18.0" +serde = { version = "1.0.163", optional = true } strum = "0.25.0" thiserror = "1.0.52" tokio = { version = "1.35.0", features = ["rt", "sync"], default-features = false } @@ -35,7 +36,7 @@ binstalk-downloader = { version = "0.9.6", path = "../binstalk-downloader" } [features] quickinstall = [] -dist-manifest = ["dep:cargo-dist-schema"] +dist-manifest = ["dep:cargo-dist-schema", "dep:serde"] [package.metadata.docs.rs] rustdoc-args = ["--cfg", "docsrs"] diff --git a/crates/binstalk-fetchers/src/dist_manifest_fetcher.rs b/crates/binstalk-fetchers/src/dist_manifest_fetcher.rs new file mode 100644 index 00000000..ed7639d0 --- /dev/null +++ b/crates/binstalk-fetchers/src/dist_manifest_fetcher.rs @@ -0,0 +1,51 @@ +use std::collections::BTreeMap; + +use binstalk_downloader::remote::{Client, Response}; +use cargo_dist_schema::Format; +use compact_str::CompactString; + +use crate::FetchError; + +#[derive(Clone, Debug)] +struct Binary { + /// Key: target, value: artifact + artifacts: BTreeMap, +} + +/// An tarball/zip artifact. +#[derive(Clone, Debug)] +struct Artifact { + /// Filename of artifact on release artifacts, + /// need to infer the format. + filename: CompactString, + /// Path to the executable within the tarbal/zip. + path_to_exe: CompactString, + + /// Filename of the checksum file. + checksum_filename: Option, +} + +#[derive(Clone, Debug)] +pub(super) enum DistManifest { + NotSupported(Format), + /// Key: name of the binary + Binaries(BTreeMap), +} + +impl DistManifest { + async fn parse(response: Response) -> Result { + let manifest: cargo_dist_schema::DistManifest = response.json().await?; + let format = manifest.format(); + + if format.unsupported() { + return Ok(Self::NotSupported(format)); + } + + todo!() + } +} + +// TODO: Cache `DistManifest` in a new global http cacher for the fetchers +// Also cache the artifacts downloaded and extracted + +pub struct GhDistManifest {} diff --git a/crates/binstalk-fetchers/src/lib.rs b/crates/binstalk-fetchers/src/lib.rs index a742e87e..019993b1 100644 --- a/crates/binstalk-fetchers/src/lib.rs +++ b/crates/binstalk-fetchers/src/lib.rs @@ -18,6 +18,11 @@ mod quickinstall; #[cfg(feature = "quickinstall")] pub use quickinstall::*; +#[cfg(feature = "dist-manifest")] +mod dist_manifest_fetcher; +#[cfg(feature = "dist-manifest")] +pub use dist_manifest_fetcher::GhDistManifest; + mod common; use common::*;