From 584d46b335fa1252fb1cf9b770de8bccfcec51fe Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Mon, 2 Sep 2024 09:39:44 -0500 Subject: [PATCH] Split code into two packages, one for the CLI tool and one for the library --- Cargo.lock | 15 +++++- Cargo.toml | 54 ++++--------------- Cross.toml | 11 ++++ ubi-cli/Cargo.toml | 22 ++++++++ {src => ubi-cli/src}/main.rs | 0 {tests => ubi-cli/tests}/ubi.rs | 13 +---- ubi/Cargo.toml | 50 +++++++++++++++++ build.rs => ubi/build.rs | 5 -- {src => ubi/src}/arch.rs | 0 {src => ubi/src}/extension.rs | 0 {src => ubi/src}/fetcher.rs | 0 {src => ubi/src}/installer.rs | 0 src/ubi.rs => ubi/src/lib.rs | 3 +- {src => ubi/src}/picker.rs | 0 {src => ubi/src}/release.rs | 0 {test-data => ubi/test-data}/project | 0 {test-data => ubi/test-data}/project.bz | Bin {test-data => ubi/test-data}/project.bz2 | Bin {test-data => ubi/test-data}/project.exe | 0 {test-data => ubi/test-data}/project.gz | Bin {test-data => ubi/test-data}/project.tar | Bin {test-data => ubi/test-data}/project.tar.bz | Bin {test-data => ubi/test-data}/project.tar.bz2 | Bin {test-data => ubi/test-data}/project.tar.gz | Bin {test-data => ubi/test-data}/project.tar.xz | Bin {test-data => ubi/test-data}/project.xz | Bin {test-data => ubi/test-data}/project.zip | Bin 27 files changed, 111 insertions(+), 62 deletions(-) create mode 100644 ubi-cli/Cargo.toml rename {src => ubi-cli/src}/main.rs (100%) rename {tests => ubi-cli/tests}/ubi.rs (97%) create mode 100644 ubi/Cargo.toml rename build.rs => ubi/build.rs (73%) rename {src => ubi/src}/arch.rs (100%) rename {src => ubi/src}/extension.rs (100%) rename {src => ubi/src}/fetcher.rs (100%) rename {src => ubi/src}/installer.rs (100%) rename src/ubi.rs => ubi/src/lib.rs (99%) rename {src => ubi/src}/picker.rs (100%) rename {src => ubi/src}/release.rs (100%) rename {test-data => ubi/test-data}/project (100%) rename {test-data => ubi/test-data}/project.bz (100%) rename {test-data => ubi/test-data}/project.bz2 (100%) rename {test-data => ubi/test-data}/project.exe (100%) rename {test-data => ubi/test-data}/project.gz (100%) rename {test-data => ubi/test-data}/project.tar (100%) rename {test-data => ubi/test-data}/project.tar.bz (100%) rename {test-data => ubi/test-data}/project.tar.bz2 (100%) rename {test-data => ubi/test-data}/project.tar.gz (100%) rename {test-data => ubi/test-data}/project.tar.xz (100%) rename {test-data => ubi/test-data}/project.xz (100%) rename {test-data => ubi/test-data}/project.zip (100%) diff --git a/Cargo.lock b/Cargo.lock index 0ba27c3..ca8bbe9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1892,7 +1892,7 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ubi" -version = "0.1.2" +version = "0.2.0" dependencies = [ "anyhow", "binstall-tar", @@ -1920,6 +1920,19 @@ dependencies = [ "zip", ] +[[package]] +name = "ubi-cli" +version = "0.2.0" +dependencies = [ + "anyhow", + "clap", + "log", + "tempfile", + "thiserror", + "tokio", + "ubi", +] + [[package]] name = "unicode-bidi" version = "0.3.15" diff --git a/Cargo.toml b/Cargo.toml index be69844..840bb48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,16 @@ -[package] -name = "ubi" -version = "0.1.2" +[workspace.package] authors = ["Dave Rolsky "] -description = "The Universal Binary Installer library and CLI tool" -repository = "https://github.com/houseabsolute/ubi" -documentation = "https://docs.rs/ubi/latest/ubi/" -readme = "README.md" -license = "MIT OR Apache-2.0" edition = "2021" +license = "MIT OR Apache-2.0" +readme = "README.md" +repository = "https://github.com/houseabsolute/precious" +version = "0.2.0" -[lib] -name = "ubi" -path = "src/ubi.rs" - -[[bin]] -name = "ubi" -path = "src/main.rs" +[workspace] +members = ["ubi", "ubi-cli"] +resolver = "2" -[dependencies] +[workspace.dependencies] anyhow = "1.0.86" binstall-tar = "0.4.42" bzip2 = "0.4.4" @@ -28,6 +21,7 @@ flate2 = "1.0.33" itertools = "0.13.0" lazy-regex = "3.3.0" log = "0.4.22" +mockito = "1.5.0" platforms = "=3.2.0" regex = "1.10.6" reqwest = { version = "0.12.7", default-features = false, features = ["gzip", "json"] } @@ -50,31 +44,3 @@ zip = { version = "2.2.0", default-features = false, features = [ "lzma", "zstd", ] } - -[features] -default = ["rustls-tls"] -## enables the `rustls-tls` feature for the `reqwest` crate. -rustls-tls = ["reqwest/rustls-tls"] -## enables the `rustls-tls-native-roots` feature for the `reqwest` crate. -rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"] -## enables the `native-tls` feature for the `reqwest` crate. -native-tls = ["reqwest/native-tls"] -## enables the `native-tls-vendored` feature for the `reqwest` crate. -native-tls-vendored = ["reqwest/native-tls-vendored"] - -[workspace.metadata.release] -allow-branch = ["master"] - -[dev-dependencies] -mockito = "1.5.0" - -# workaround for https://github.com/cross-rs/cross/issues/1345 -[package.metadata.cross.target.x86_64-unknown-netbsd] -pre-build = [ - "mkdir -p /tmp/netbsd", - "curl https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O", - "tar -C /tmp/netbsd -xJf base.tar.xz", - "cp /tmp/netbsd/usr/lib/libexecinfo.so /usr/local/x86_64-unknown-netbsd/lib", - "rm base.tar.xz", - "rm -rf /tmp/netbsd", -] diff --git a/Cross.toml b/Cross.toml index f457769..a4c7629 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,2 +1,13 @@ [build.env] passthrough = ["GITHUB_TOKEN"] + +# workaround for https://github.com/cross-rs/cross/issues/1345 +[target.x86_64-unknown-netbsd] +pre-build = [ + "mkdir -p /tmp/netbsd", + "curl https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O", + "tar -C /tmp/netbsd -xJf base.tar.xz", + "cp /tmp/netbsd/usr/lib/libexecinfo.so /usr/local/x86_64-unknown-netbsd/lib", + "rm base.tar.xz", + "rm -rf /tmp/netbsd", +] diff --git a/ubi-cli/Cargo.toml b/ubi-cli/Cargo.toml new file mode 100644 index 0000000..0585567 --- /dev/null +++ b/ubi-cli/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "ubi-cli" +version.workspace = true +authors.workspace = true +description = "The Universal Binary Installer CLI tool" +repository.workspace = true +readme.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +anyhow.workspace = true +clap.workspace = true +log.workspace = true +tempfile.workspace = true +thiserror.workspace = true +tokio.workspace = true +ubi = { version = "0.2.0", path = "../ubi" } + +[[bin]] +name = "ubi" +path = "src/main.rs" diff --git a/src/main.rs b/ubi-cli/src/main.rs similarity index 100% rename from src/main.rs rename to ubi-cli/src/main.rs diff --git a/tests/ubi.rs b/ubi-cli/tests/ubi.rs similarity index 97% rename from tests/ubi.rs rename to ubi-cli/tests/ubi.rs index 5ae58ce..fe9ff94 100644 --- a/tests/ubi.rs +++ b/ubi-cli/tests/ubi.rs @@ -54,19 +54,10 @@ impl PreservableTempdir { #[allow(clippy::too_many_lines)] fn integration_tests() -> Result<()> { let cargo = make_exe_pathbuf(&["cargo"]); - - let features = if env::var("CARGO_FEATURE_RUSTLS_TLS_NATIVE_ROOTS").unwrap_or_default() == "1" { - "rustls-tls-native-roots" - } else if env::var("CARGO_FEATURE_NATIVE_TLS").unwrap_or_default() == "1" { - "native-tls" - } else if env::var("CARGO_FEATURE_NATIVE_TLS_VENDORED").unwrap_or_default() == "1" { - "native-tls-vendored" - } else { - "default" - }; - run_command(&cargo, &["build", "--features", features])?; + run_command(&cargo, &["build"])?; let mut ubi = env::current_dir()?; + ubi.push(".."); ubi.push("target"); ubi.push("debug"); ubi.push(if cfg!(windows) { "ubi.exe" } else { "ubi" }); diff --git a/ubi/Cargo.toml b/ubi/Cargo.toml new file mode 100644 index 0000000..3b50978 --- /dev/null +++ b/ubi/Cargo.toml @@ -0,0 +1,50 @@ +[package] +name = "ubi" +version.workspace = true +authors.workspace = true +description = "The Universal Binary Installer library" +repository.workspace = true +readme.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +anyhow.workspace = true +binstall-tar.workspace = true +bzip2.workspace = true +clap.workspace = true +document-features.workspace = true +fern.workspace = true +flate2.workspace = true +itertools.workspace = true +lazy-regex.workspace = true +log.workspace = true +platforms.workspace = true +regex.workspace = true +reqwest.workspace = true +result.workspace = true +serde.workspace = true +strum.workspace = true +tempfile.workspace = true +test-case.workspace = true +thiserror.workspace = true +tokio.workspace = true +url.workspace = true +xz.workspace = true +zip.workspace = true + +[features] +default = ["rustls-tls"] +## enables the `rustls-tls` feature for the `reqwest` crate. +rustls-tls = ["reqwest/rustls-tls"] +## enables the `rustls-tls-native-roots` feature for the `reqwest` crate. +rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"] +## enables the `native-tls` feature for the `reqwest` crate. +native-tls = ["reqwest/native-tls"] +## enables the `native-tls-vendored` feature for the `reqwest` crate. +native-tls-vendored = ["reqwest/native-tls-vendored"] + +[dev-dependencies] +mockito.workspace = true +test-case.workspace = true +tokio.workspace = true diff --git a/build.rs b/ubi/build.rs similarity index 73% rename from build.rs rename to ubi/build.rs index f41487f..7909a32 100644 --- a/build.rs +++ b/ubi/build.rs @@ -2,11 +2,6 @@ use std::env; // mostly copied from the current_platform crate. fn main() { - // We need this to build `ubi` properly in the integration tests. - for (key, value) in env::vars().filter(|(k, _)| k.starts_with("CARGO_FEATURE_")) { - println!("cargo:rustc-env={key}={value}"); - } - // Cargo sets the host and target env vars for build scripts, but not // crates: // https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts diff --git a/src/arch.rs b/ubi/src/arch.rs similarity index 100% rename from src/arch.rs rename to ubi/src/arch.rs diff --git a/src/extension.rs b/ubi/src/extension.rs similarity index 100% rename from src/extension.rs rename to ubi/src/extension.rs diff --git a/src/fetcher.rs b/ubi/src/fetcher.rs similarity index 100% rename from src/fetcher.rs rename to ubi/src/fetcher.rs diff --git a/src/installer.rs b/ubi/src/installer.rs similarity index 100% rename from src/installer.rs rename to ubi/src/installer.rs diff --git a/src/ubi.rs b/ubi/src/lib.rs similarity index 99% rename from src/ubi.rs rename to ubi/src/lib.rs index fb06b12..fac2649 100644 --- a/src/ubi.rs +++ b/ubi/src/lib.rs @@ -1,4 +1,5 @@ -//! A library (and CLI tool) for downloading and installing pre-built binaries from GitHub. +//! A library for downloading and installing pre-built binaries from GitHub. +//! //! UBI stands for "Universal Binary Installer". It downloads and installs pre-built binaries from //! GitHub releases. It is designed to be used in shell scripts and other automation. //! diff --git a/src/picker.rs b/ubi/src/picker.rs similarity index 100% rename from src/picker.rs rename to ubi/src/picker.rs diff --git a/src/release.rs b/ubi/src/release.rs similarity index 100% rename from src/release.rs rename to ubi/src/release.rs diff --git a/test-data/project b/ubi/test-data/project similarity index 100% rename from test-data/project rename to ubi/test-data/project diff --git a/test-data/project.bz b/ubi/test-data/project.bz similarity index 100% rename from test-data/project.bz rename to ubi/test-data/project.bz diff --git a/test-data/project.bz2 b/ubi/test-data/project.bz2 similarity index 100% rename from test-data/project.bz2 rename to ubi/test-data/project.bz2 diff --git a/test-data/project.exe b/ubi/test-data/project.exe similarity index 100% rename from test-data/project.exe rename to ubi/test-data/project.exe diff --git a/test-data/project.gz b/ubi/test-data/project.gz similarity index 100% rename from test-data/project.gz rename to ubi/test-data/project.gz diff --git a/test-data/project.tar b/ubi/test-data/project.tar similarity index 100% rename from test-data/project.tar rename to ubi/test-data/project.tar diff --git a/test-data/project.tar.bz b/ubi/test-data/project.tar.bz similarity index 100% rename from test-data/project.tar.bz rename to ubi/test-data/project.tar.bz diff --git a/test-data/project.tar.bz2 b/ubi/test-data/project.tar.bz2 similarity index 100% rename from test-data/project.tar.bz2 rename to ubi/test-data/project.tar.bz2 diff --git a/test-data/project.tar.gz b/ubi/test-data/project.tar.gz similarity index 100% rename from test-data/project.tar.gz rename to ubi/test-data/project.tar.gz diff --git a/test-data/project.tar.xz b/ubi/test-data/project.tar.xz similarity index 100% rename from test-data/project.tar.xz rename to ubi/test-data/project.tar.xz diff --git a/test-data/project.xz b/ubi/test-data/project.xz similarity index 100% rename from test-data/project.xz rename to ubi/test-data/project.xz diff --git a/test-data/project.zip b/ubi/test-data/project.zip similarity index 100% rename from test-data/project.zip rename to ubi/test-data/project.zip