diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f293064b7..be6147174 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,6 +20,10 @@ updates: directory: "/crates/binstalk-manifests" schedule: interval: "daily" + - package-ecosystem: "cargo" + directory: "/crates/binstalk-types" + schedule: + interval: "daily" - package-ecosystem: "cargo" directory: "/crates/binstalk" schedule: diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index 68fae36b1..a075de664 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -10,6 +10,7 @@ on: - bin - binstalk - binstalk-manifests + - binstalk-types - binstalk-downloader - detect-targets - detect-wasi diff --git a/Cargo.lock b/Cargo.lock index a0ba4d9af..5a35e5a4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,7 +110,7 @@ version = "0.4.1" dependencies = [ "async-trait", "binstalk-downloader", - "binstalk-manifests", + "binstalk-types", "cargo_toml", "compact_str", "crates_io_api", @@ -138,7 +138,7 @@ dependencies = [ name = "binstalk-downloader" version = "0.1.0" dependencies = [ - "binstalk-manifests", + "binstalk-types", "binstall-tar", "bytes", "bzip2", @@ -165,24 +165,35 @@ dependencies = [ name = "binstalk-manifests" version = "0.1.0" dependencies = [ + "binstalk-types", "compact_str", "detect-targets", "fs-lock", "home", "miette", - "once_cell", "semver", "serde", "serde-tuple-vec-map", "serde_json", - "strum", - "strum_macros", "tempfile", "thiserror", "toml_edit", "url", ] +[[package]] +name = "binstalk-types" +version = "0.1.0" +dependencies = [ + "compact_str", + "once_cell", + "semver", + "serde", + "strum", + "strum_macros", + "url", +] + [[package]] name = "binstall-tar" version = "0.4.39" @@ -274,6 +285,7 @@ name = "cargo-binstall" version = "0.16.0" dependencies = [ "binstalk", + "binstalk-manifests", "clap", "crates_io_api", "dirs", diff --git a/Cargo.toml b/Cargo.toml index bd0cb700b..4e3e1f522 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "crates/bin", "crates/binstalk", "crates/binstalk-manifests", + "crates/binstalk-types", "crates/binstalk-downloader", "crates/detect-wasi", "crates/fs-lock", diff --git a/crates/bin/Cargo.toml b/crates/bin/Cargo.toml index b40c5ce67..c04f34a09 100644 --- a/crates/bin/Cargo.toml +++ b/crates/bin/Cargo.toml @@ -23,6 +23,7 @@ pkg-fmt = "zip" [dependencies] binstalk = { path = "../binstalk", version = "0.4.1" } +binstalk-manifests = { path = "../binstalk-manifests", version = "0.1.0" } clap = { version = "4.0.25", features = ["derive"] } crates_io_api = { version = "0.8.1", default-features = false } dirs = "4.0.0" diff --git a/crates/bin/src/entry.rs b/crates/bin/src/entry.rs index 649a72ff5..48e509404 100644 --- a/crates/bin/src/entry.rs +++ b/crates/bin/src/entry.rs @@ -5,14 +5,14 @@ use binstalk::{ fetchers::{Fetcher, GhCrateMeta, QuickInstall}, get_desired_targets, helpers::{jobserver_client::LazyJobserverClient, remote::Client, tasks::AutoAbortJoinHandle}, - manifests::{ - binstall_crates_v1::Records, cargo_crates_v1::CratesToml, cargo_toml_binstall::PkgOverride, - }, ops::{ self, resolve::{CrateName, Resolution, VersionReqExt}, }, }; +use binstalk_manifests::{ + binstall_crates_v1::Records, cargo_crates_v1::CratesToml, cargo_toml_binstall::PkgOverride, +}; use log::LevelFilter; use miette::{miette, Result, WrapErr}; use tokio::task::block_in_place; diff --git a/crates/binstalk-downloader/Cargo.toml b/crates/binstalk-downloader/Cargo.toml index 86764ee4b..f4b1ff903 100644 --- a/crates/binstalk-downloader/Cargo.toml +++ b/crates/binstalk-downloader/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" license = "GPL-3.0" [dependencies] -binstalk-manifests = { version = "0.1.0", path = "../binstalk-manifests" } +binstalk-types = { version = "0.1.0", path = "../binstalk-types" } bytes = "1.2.1" bzip2 = "0.4.3" digest = "0.10.5" diff --git a/crates/binstalk-downloader/src/download.rs b/crates/binstalk-downloader/src/download.rs index 276d5a390..18d41a5c5 100644 --- a/crates/binstalk-downloader/src/download.rs +++ b/crates/binstalk-downloader/src/download.rs @@ -1,11 +1,11 @@ use std::{fmt::Debug, future::Future, io, marker::PhantomData, path::Path, pin::Pin}; -use binstalk_manifests::cargo_toml_binstall::{PkgFmtDecomposed, TarBasedFmt}; +use binstalk_types::cargo_toml_binstall::{PkgFmtDecomposed, TarBasedFmt}; use digest::{Digest, FixedOutput, HashMarker, Output, OutputSizeUser, Update}; use thiserror::Error as ThisError; use tracing::{debug, instrument}; -pub use binstalk_manifests::cargo_toml_binstall::PkgFmt; +pub use binstalk_types::cargo_toml_binstall::PkgFmt; pub use tar::Entries; pub use zip::result::ZipError; diff --git a/crates/binstalk-manifests/Cargo.toml b/crates/binstalk-manifests/Cargo.toml index 45a572885..4dec53706 100644 --- a/crates/binstalk-manifests/Cargo.toml +++ b/crates/binstalk-manifests/Cargo.toml @@ -10,17 +10,15 @@ edition = "2021" license = "Apache-2.0 OR MIT" [dependencies] +binstalk-types = { version = "0.1.0", path = "../binstalk-types" } compact_str = { version = "0.6.0", features = ["serde"] } fs-lock = { version = "0.1.0", path = "../fs-lock" } home = "0.5.4" miette = "5.4.1" -once_cell = "1.16.0" semver = { version = "1.0.14", features = ["serde"] } serde = { version = "1.0.147", features = ["derive"] } serde-tuple-vec-map = "1.0.1" serde_json = "1.0.87" -strum = "0.24.1" -strum_macros = "0.24.3" thiserror = "1.0.37" toml_edit = { version = "0.15.0", features = ["easy"] } url = { version = "2.3.1", features = ["serde"] } diff --git a/crates/binstalk-manifests/src/binstall_crates_v1.rs b/crates/binstalk-manifests/src/binstall_crates_v1.rs index 1eb4bbdd9..3cac5e653 100644 --- a/crates/binstalk-manifests/src/binstall_crates_v1.rs +++ b/crates/binstalk-manifests/src/binstall_crates_v1.rs @@ -7,6 +7,8 @@ //! NLJSON to the file will be understood fine. use std::{ + borrow::Borrow, + cmp, collections::{btree_set, BTreeSet}, fs, io::{self, Seek, Write}, @@ -14,17 +16,17 @@ use std::{ path::{Path, PathBuf}, }; +use compact_str::CompactString; use fs_lock::FileLock; use home::cargo_home; use miette::Diagnostic; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::helpers::create_if_not_exist; - -use super::crate_info::CrateInfo; +use crate::{crate_info::CrateInfo, helpers::create_if_not_exist}; #[derive(Debug, Diagnostic, Error)] +#[non_exhaustive] pub enum Error { #[error(transparent)] Io(#[from] io::Error), @@ -33,28 +35,27 @@ pub enum Error { SerdeJsonParse(#[from] serde_json::Error), } -pub fn append_to_path(path: impl AsRef, iter: Iter) -> Result<(), Error> +pub fn append_to_path(path: impl AsRef, iter: Iter) -> Result<(), Error> where - Iter: IntoIterator, + Iter: IntoIterator, + Data: From, { let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?; // Move the cursor to EOF file.seek(io::SeekFrom::End(0))?; - write_to(&mut file, &mut iter.into_iter()) + write_to(&mut file, &mut iter.into_iter().map(Data::from)) } -pub fn append(iter: Iter) -> Result<(), Error> +pub fn append(iter: Iter) -> Result<(), Error> where - Iter: IntoIterator, + Iter: IntoIterator, + Data: From, { append_to_path(default_path()?, iter) } -pub fn write_to( - file: &mut FileLock, - iter: &mut dyn Iterator, -) -> Result<(), Error> { +pub fn write_to(file: &mut FileLock, iter: &mut dyn Iterator) -> Result<(), Error> { let writer = io::BufWriter::with_capacity(512, file); let mut ser = serde_json::Serializer::new(writer); @@ -76,11 +77,74 @@ pub fn default_path() -> Result { Ok(dir.join("crates-v1.json")) } +#[derive(Debug, Deserialize, Serialize)] +pub struct Data { + #[serde(flatten)] + pub crate_info: CrateInfo, + + /// Forwards compatibility. Unknown keys from future versions + /// will be stored here and retained when the file is saved. + /// + /// We use an `Vec` here since it is never accessed in Rust. + #[serde(flatten, with = "tuple_vec_map")] + pub other: Vec<(CompactString, serde_json::Value)>, +} + +impl From for Data { + fn from(crate_info: CrateInfo) -> Self { + Self { + crate_info, + other: Vec::new(), + } + } +} + +impl From for CrateInfo { + fn from(data: Data) -> Self { + data.crate_info + } +} + +impl Borrow for Data { + fn borrow(&self) -> &str { + &self.crate_info.name + } +} + +impl PartialEq for Data { + fn eq(&self, other: &Self) -> bool { + self.crate_info.name == other.crate_info.name + } +} +impl PartialEq for Data { + fn eq(&self, other: &CrateInfo) -> bool { + self.crate_info.name == other.name + } +} +impl PartialEq for CrateInfo { + fn eq(&self, other: &Data) -> bool { + self.name == other.crate_info.name + } +} +impl Eq for Data {} + +impl PartialOrd for Data { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Data { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.crate_info.name.cmp(&other.crate_info.name) + } +} + #[derive(Debug)] pub struct Records { file: FileLock, /// Use BTreeSet to dedup the metadata - data: BTreeSet, + data: BTreeSet, } impl Records { @@ -122,7 +186,7 @@ impl Records { } pub fn get(&self, value: impl AsRef) -> Option<&CrateInfo> { - self.data.get(value.as_ref()) + self.data.get(value.as_ref()).map(|data| &data.crate_info) } pub fn contains(&self, value: impl AsRef) -> bool { @@ -134,11 +198,12 @@ impl Records { /// If the set did have an equal element present, false is returned, /// and the entry is not updated. pub fn insert(&mut self, value: CrateInfo) -> bool { - self.data.insert(value) + self.data.insert(Data::from(value)) } + /// Return the previous `CrateInfo` for the package if there is any. pub fn replace(&mut self, value: CrateInfo) -> Option { - self.data.replace(value) + self.data.replace(Data::from(value)).map(CrateInfo::from) } pub fn remove(&mut self, value: impl AsRef) -> bool { @@ -146,7 +211,7 @@ impl Records { } pub fn take(&mut self, value: impl AsRef) -> Option { - self.data.take(value.as_ref()) + self.data.take(value.as_ref()).map(CrateInfo::from) } pub fn len(&self) -> usize { @@ -159,9 +224,9 @@ impl Records { } impl<'a> IntoIterator for &'a Records { - type Item = &'a CrateInfo; + type Item = &'a Data; - type IntoIter = btree_set::Iter<'a, CrateInfo>; + type IntoIter = btree_set::Iter<'a, Data>; fn into_iter(self) -> Self::IntoIter { self.data.iter() @@ -202,7 +267,6 @@ mod test { source: CrateSource::cratesio_registry(), target: target.clone(), bins: vec!["1".into(), "2".into()], - other: Default::default(), }, CrateInfo { name: "b".into(), @@ -211,7 +275,6 @@ mod test { source: CrateSource::cratesio_registry(), target: target.clone(), bins: vec!["1".into(), "2".into()], - other: Default::default(), }, CrateInfo { name: "a".into(), @@ -220,7 +283,6 @@ mod test { source: CrateSource::cratesio_registry(), target: target.clone(), bins: vec!["1".into()], - other: Default::default(), }, ]; @@ -234,11 +296,11 @@ mod test { let mut records = Records::load_from_path(path).unwrap(); assert_records_eq!(&records, &metadata_set); - records.remove("b"); - assert_eq!(records.len(), metadata_set.len() - 1); + assert!(records.remove("b")); + metadata_set.remove("b"); + assert_eq!(records.len(), metadata_set.len()); records.overwrite().unwrap(); - metadata_set.remove("b"); let records = Records::load_from_path(path).unwrap(); assert_records_eq!(&records, &metadata_set); // Drop the exclusive file lock @@ -251,7 +313,6 @@ mod test { source: CrateSource::cratesio_registry(), target, bins: vec!["1".into(), "2".into()], - other: Default::default(), }; append_to_path(path, [new_metadata.clone()]).unwrap(); metadata_set.insert(new_metadata); diff --git a/crates/binstalk-manifests/src/cargo_crates_v1.rs b/crates/binstalk-manifests/src/cargo_crates_v1.rs index 9d3aad477..8d9033fa6 100644 --- a/crates/binstalk-manifests/src/cargo_crates_v1.rs +++ b/crates/binstalk-manifests/src/cargo_crates_v1.rs @@ -114,6 +114,7 @@ impl CratesToml { } #[derive(Debug, Diagnostic, Error)] +#[non_exhaustive] pub enum CratesTomlParseError { #[error(transparent)] Io(#[from] io::Error), @@ -122,10 +123,22 @@ pub enum CratesTomlParseError { TomlParse(#[from] toml_edit::easy::de::Error), #[error(transparent)] - TomlWrite(#[from] toml_edit::easy::ser::Error), + TomlWrite(Box), #[error(transparent)] - CvsParse(#[from] CvsParseError), + CvsParse(Box), +} + +impl From for CratesTomlParseError { + fn from(e: CvsParseError) -> Self { + CratesTomlParseError::CvsParse(Box::new(e)) + } +} + +impl From for CratesTomlParseError { + fn from(e: toml_edit::easy::ser::Error) -> Self { + CratesTomlParseError::TomlWrite(Box::new(e)) + } } #[cfg(test)] @@ -151,7 +164,6 @@ mod tests { source: CrateSource::cratesio_registry(), target: TARGET.into(), bins: vec!["cargo-binstall".into()], - other: Default::default(), }], ) .unwrap(); diff --git a/crates/binstalk-manifests/src/cargo_crates_v1/crate_version_source.rs b/crates/binstalk-manifests/src/cargo_crates_v1/crate_version_source.rs index 43c5ef546..1ed770115 100644 --- a/crates/binstalk-manifests/src/cargo_crates_v1/crate_version_source.rs +++ b/crates/binstalk-manifests/src/cargo_crates_v1/crate_version_source.rs @@ -1,5 +1,6 @@ use std::{borrow::Cow, fmt, str::FromStr}; +use binstalk_types::crate_info::cratesio_url; use compact_str::CompactString; use miette::Diagnostic; use semver::Version; @@ -7,10 +8,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use thiserror::Error; use url::Url; -use crate::{ - crate_info::{CrateInfo, CrateSource, SourceType}, - helpers::cratesio_url, -}; +use crate::crate_info::{CrateInfo, CrateSource, SourceType}; #[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)] pub struct CrateVersionSource { @@ -72,8 +70,8 @@ impl FromStr for CrateVersionSource { ["registry", url] => Source::Registry(Url::parse(url)?), [kind, arg] => { return Err(CvsParseError::UnknownSourceType { - kind: kind.to_string(), - arg: arg.to_string(), + kind: kind.to_string().into_boxed_str(), + arg: arg.to_string().into_boxed_str(), }) } _ => return Err(CvsParseError::BadSource), @@ -90,6 +88,7 @@ impl FromStr for CrateVersionSource { } #[derive(Debug, Diagnostic, Error)] +#[non_exhaustive] pub enum CvsParseError { #[error(transparent)] UrlParse(#[from] url::ParseError), @@ -98,7 +97,7 @@ pub enum CvsParseError { VersionParse(#[from] semver::Error), #[error("unknown source type {kind}+{arg}")] - UnknownSourceType { kind: String, arg: String }, + UnknownSourceType { kind: Box, arg: Box }, #[error("bad source format")] BadSource, diff --git a/crates/binstalk-manifests/src/helpers.rs b/crates/binstalk-manifests/src/helpers.rs index f748d4652..ac5b35e2e 100644 --- a/crates/binstalk-manifests/src/helpers.rs +++ b/crates/binstalk-manifests/src/helpers.rs @@ -1,8 +1,5 @@ use std::{fs, io, path::Path}; -use once_cell::sync::Lazy; -use url::Url; - /// Returned file is readable and writable. pub(crate) fn create_if_not_exist(path: impl AsRef) -> io::Result { let path = path.as_ref(); @@ -16,10 +13,3 @@ pub(crate) fn create_if_not_exist(path: impl AsRef) -> io::Result &'static Url { - static CRATESIO: Lazy Url> = - Lazy::new(|| Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()); - - &CRATESIO -} diff --git a/crates/binstalk-manifests/src/lib.rs b/crates/binstalk-manifests/src/lib.rs index ed655d1f4..a87d5bccf 100644 --- a/crates/binstalk-manifests/src/lib.rs +++ b/crates/binstalk-manifests/src/lib.rs @@ -12,5 +12,5 @@ mod helpers; pub mod binstall_crates_v1; pub mod cargo_crates_v1; -pub mod cargo_toml_binstall; -pub mod crate_info; + +pub use binstalk_types::{cargo_toml_binstall, crate_info}; diff --git a/crates/binstalk-types/Cargo.toml b/crates/binstalk-types/Cargo.toml new file mode 100644 index 000000000..c109ed7c8 --- /dev/null +++ b/crates/binstalk-types/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "binstalk-types" +description = "The binstall toolkit that contains basic types for binstalk crates" +repository = "https://github.com/cargo-bins/cargo-binstall" +documentation = "https://docs.rs/binstalk-types" +version = "0.1.0" +rust-version = "1.61.0" +authors = ["ryan "] +edition = "2021" +license = "Apache-2.0 OR MIT" + +[dependencies] +compact_str = { version = "0.6.0", features = ["serde"] } +once_cell = "1.16.0" +semver = { version = "1.0.14", features = ["serde"] } +serde = { version = "1.0.147", features = ["derive"] } +strum = "0.24.1" +strum_macros = "0.24.3" +url = { version = "2.3.1", features = ["serde"] } diff --git a/crates/binstalk-types/LICENSE-APACHE b/crates/binstalk-types/LICENSE-APACHE new file mode 100644 index 000000000..1b5ec8b78 --- /dev/null +++ b/crates/binstalk-types/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/crates/binstalk-types/LICENSE-MIT b/crates/binstalk-types/LICENSE-MIT new file mode 100644 index 000000000..31aa79387 --- /dev/null +++ b/crates/binstalk-types/LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/crates/binstalk-manifests/src/cargo_toml_binstall.rs b/crates/binstalk-types/src/cargo_toml_binstall.rs similarity index 99% rename from crates/binstalk-manifests/src/cargo_toml_binstall.rs rename to crates/binstalk-types/src/cargo_toml_binstall.rs index 9e785f201..b941d0630 100644 --- a/crates/binstalk-manifests/src/cargo_toml_binstall.rs +++ b/crates/binstalk-types/src/cargo_toml_binstall.rs @@ -6,11 +6,10 @@ use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; +mod package_formats; #[doc(inline)] pub use package_formats::*; -mod package_formats; - /// `binstall` metadata container /// /// Required to nest metadata under `package.metadata.binstall` diff --git a/crates/binstalk-manifests/src/cargo_toml_binstall/package_formats.rs b/crates/binstalk-types/src/cargo_toml_binstall/package_formats.rs similarity index 100% rename from crates/binstalk-manifests/src/cargo_toml_binstall/package_formats.rs rename to crates/binstalk-types/src/cargo_toml_binstall/package_formats.rs diff --git a/crates/binstalk-manifests/src/crate_info.rs b/crates/binstalk-types/src/crate_info.rs similarity index 82% rename from crates/binstalk-manifests/src/crate_info.rs rename to crates/binstalk-types/src/crate_info.rs index dd5601ce2..6d019593b 100644 --- a/crates/binstalk-manifests/src/crate_info.rs +++ b/crates/binstalk-types/src/crate_info.rs @@ -3,11 +3,17 @@ use std::{borrow, cmp, hash}; use compact_str::CompactString; +use once_cell::sync::Lazy; use semver::Version; use serde::{Deserialize, Serialize}; use url::Url; -use crate::helpers::cratesio_url; +pub fn cratesio_url() -> &'static Url { + static CRATESIO: Lazy Url> = + Lazy::new(|| Url::parse("https://github.com/rust-lang/crates.io-index").unwrap()); + + &CRATESIO +} #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CrateInfo { @@ -17,13 +23,6 @@ pub struct CrateInfo { pub source: CrateSource, pub target: CompactString, pub bins: Vec, - - /// Forwards compatibility. Unknown keys from future versions - /// will be stored here and retained when the file is saved. - /// - /// We use an `Vec` here since it is never accessed in Rust. - #[serde(flatten, with = "tuple_vec_map")] - pub other: Vec<(CompactString, serde_json::Value)>, } impl borrow::Borrow for CrateInfo { diff --git a/crates/binstalk-types/src/lib.rs b/crates/binstalk-types/src/lib.rs new file mode 100644 index 000000000..f4c48c853 --- /dev/null +++ b/crates/binstalk-types/src/lib.rs @@ -0,0 +1,2 @@ +pub mod cargo_toml_binstall; +pub mod crate_info; diff --git a/crates/binstalk/Cargo.toml b/crates/binstalk/Cargo.toml index 87e259d0f..9c3373e0b 100644 --- a/crates/binstalk/Cargo.toml +++ b/crates/binstalk/Cargo.toml @@ -12,7 +12,7 @@ license = "GPL-3.0" [dependencies] async-trait = "0.1.58" binstalk-downloader = { version = "0.1.0", path = "../binstalk-downloader" } -binstalk-manifests = { version = "0.1.0", path = "../binstalk-manifests" } +binstalk-types = { version = "0.1.0", path = "../binstalk-types" } cargo_toml = "0.13.0" compact_str = { version = "0.6.0", features = ["serde"] } crates_io_api = { version = "0.8.1", default-features = false } diff --git a/crates/binstalk/src/lib.rs b/crates/binstalk/src/lib.rs index 7f00da4b8..b4c67f0b2 100644 --- a/crates/binstalk/src/lib.rs +++ b/crates/binstalk/src/lib.rs @@ -6,6 +6,6 @@ pub mod fs; pub mod helpers; pub mod ops; -pub use binstalk_manifests as manifests; +pub use binstalk_types as manifests; pub use detect_targets::{get_desired_targets, DesiredTargets}; pub use home; diff --git a/crates/binstalk/src/ops/install.rs b/crates/binstalk/src/ops/install.rs index 8fbca294a..a5c95ee01 100644 --- a/crates/binstalk/src/ops/install.rs +++ b/crates/binstalk/src/ops/install.rs @@ -37,7 +37,6 @@ pub async fn install( source: CrateSource::cratesio_registry(), target, bins, - other: Default::default(), }) }) }