mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Merge pull request #39 from passcod/feat-36-tar-xz
Add support for Txz archives
This commit is contained in:
commit
c0adc3241d
6 changed files with 51 additions and 14 deletions
15
.github/workflows/rust.yml
vendored
15
.github/workflows/rust.yml
vendored
|
@ -25,7 +25,7 @@ jobs:
|
||||||
- target: x86_64-apple-darwin
|
- target: x86_64-apple-darwin
|
||||||
os: macos-latest
|
os: macos-latest
|
||||||
output: cargo-binstall
|
output: cargo-binstall
|
||||||
- target: armv7-unknown-linux-gnueabihf
|
- target: armv7-unknown-linux-gnueabihf
|
||||||
os: ubuntu-20.04
|
os: ubuntu-20.04
|
||||||
output: cargo-binstall
|
output: cargo-binstall
|
||||||
- target: x86_64-pc-windows-msvc
|
- target: x86_64-pc-windows-msvc
|
||||||
|
@ -35,15 +35,15 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: FranzDiebold/github-env-vars-action@v1.2.1
|
- uses: FranzDiebold/github-env-vars-action@v1.2.1
|
||||||
|
|
||||||
- name: Configure toolchain
|
- name: Configure toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Configure caching
|
- name: Configure caching
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
# Caching disabled on macos due to https://github.com/actions/cache/issues/403
|
# Caching disabled on macos due to https://github.com/actions/cache/issues/403
|
||||||
if: ${{ matrix.os != 'macos-latest' }}
|
if: ${{ matrix.os != 'macos-latest' }}
|
||||||
|
@ -68,6 +68,7 @@ jobs:
|
||||||
if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
|
if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
|
||||||
run: |
|
run: |
|
||||||
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
|
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
|
||||||
|
echo "LZMA_API_STATIC=1" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Install openssl (vcpkg)
|
- name: Install openssl (vcpkg)
|
||||||
if: ${{ matrix.os == 'windows-latest' }}
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
|
@ -135,13 +136,13 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: FranzDiebold/github-env-vars-action@v1.2.1
|
- uses: FranzDiebold/github-env-vars-action@v1.2.1
|
||||||
|
|
||||||
- uses: actions/download-artifact@v2
|
- uses: actions/download-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: cargo-binstall-${{ matrix.target }}.tgz
|
name: cargo-binstall-${{ matrix.target }}.tgz
|
||||||
|
|
||||||
- name: "Extract build artifact"
|
- name: "Extract build artifact"
|
||||||
run: tar -xvf cargo-binstall-${{ matrix.target }}.tgz
|
run: tar -xvf cargo-binstall-${{ matrix.target }}.tgz
|
||||||
|
|
||||||
- name: "Run binstall"
|
- name: "Run binstall"
|
||||||
run: ./${{ matrix.output }} cargo-binstall --manifest-path . --no-confirm
|
run: ./${{ matrix.output }} cargo-binstall --manifest-path . --no-confirm
|
||||||
|
|
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -119,6 +119,7 @@ dependencies = [
|
||||||
"tempdir",
|
"tempdir",
|
||||||
"tinytemplate",
|
"tinytemplate",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"xz2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -796,6 +797,17 @@ dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lzma-sys"
|
||||||
|
version = "0.1.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bdb4b7c3eddad11d3af9e86c487607d2d2442d185d848575365c4856ba96d619"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matches"
|
name = "matches"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
|
@ -1931,3 +1943,12 @@ checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xz2"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c179869f34fc7c01830d3ce7ea2086bc3a07e0d35289b667d0a8bf910258926c"
|
||||||
|
dependencies = [
|
||||||
|
"lzma-sys",
|
||||||
|
]
|
||||||
|
|
|
@ -35,6 +35,7 @@ dirs = "3.0.1"
|
||||||
serde_derive = "1.0.118"
|
serde_derive = "1.0.118"
|
||||||
crates-index = "0.16.2"
|
crates-index = "0.16.2"
|
||||||
semver = "0.11.0"
|
semver = "0.11.0"
|
||||||
|
xz2 = "0.1.6"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.8.2"
|
env_logger = "0.8.2"
|
||||||
|
|
|
@ -39,6 +39,7 @@ yes
|
||||||
- [ ] Unofficial packaging
|
- [ ] Unofficial packaging
|
||||||
- Package formats
|
- Package formats
|
||||||
- [x] Tgz
|
- [x] Tgz
|
||||||
|
- [x] Txz
|
||||||
- [x] Tar
|
- [x] Tar
|
||||||
- [x] Bin
|
- [x] Bin
|
||||||
- Extraction / Transformation
|
- Extraction / Transformation
|
||||||
|
@ -51,7 +52,7 @@ yes
|
||||||
|
|
||||||
## Supporting Binary Installation
|
## Supporting Binary Installation
|
||||||
|
|
||||||
`binstall` works with existing CI-built binary outputs, with configuration via `[package.metadata.binstall]` keys in the relevant crate manifest.
|
`binstall` works with existing CI-built binary outputs, with configuration via `[package.metadata.binstall]` keys in the relevant crate manifest.
|
||||||
When configuring `binstall` you can test against a local manifest with `--manifest-path=PATH` argument to use the crate and manifest at the provided `PATH`, skipping crate discovery and download.
|
When configuring `binstall` you can test against a local manifest with `--manifest-path=PATH` argument to use the crate and manifest at the provided `PATH`, skipping crate discovery and download.
|
||||||
|
|
||||||
To get started, add a `[package.metadata.binstall]` section to your `Cargo.toml. As an example, the default configuration would be:
|
To get started, add a `[package.metadata.binstall]` section to your `Cargo.toml. As an example, the default configuration would be:
|
||||||
|
@ -102,7 +103,7 @@ For example, the default configuration (as shown above) for a crate called `radi
|
||||||
- Installed to`$HOME/.cargo/bin/rust-radio-sx128x-v0.14.1-alpha.5`
|
- Installed to`$HOME/.cargo/bin/rust-radio-sx128x-v0.14.1-alpha.5`
|
||||||
- With a symlink from `$HOME/.cargo/bin/rust-radio-sx128x`
|
- With a symlink from `$HOME/.cargo/bin/rust-radio-sx128x`
|
||||||
|
|
||||||
#### If the package name does not match the crate name
|
#### If the package name does not match the crate name
|
||||||
|
|
||||||
As is common with libraries / utilities (and the `radio-sx128x` example), this can be overridden by specifying the `pkg-url`:
|
As is common with libraries / utilities (and the `radio-sx128x` example), this can be overridden by specifying the `pkg-url`:
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ Which provides a binary path of: `sx128x-util-x86_64-unknown-linux-gnu[.exe]`. I
|
||||||
- Because `wget`-ing releases is frustrating, `cargo install` takes a not inconsequential portion of forever on constrained devices,
|
- Because `wget`-ing releases is frustrating, `cargo install` takes a not inconsequential portion of forever on constrained devices,
|
||||||
and often putting together actual _packages_ is overkill.
|
and often putting together actual _packages_ is overkill.
|
||||||
- Why use the cargo manifest?
|
- Why use the cargo manifest?
|
||||||
- Crates already have these, and they already contain a significant portion of the required information.
|
- Crates already have these, and they already contain a significant portion of the required information.
|
||||||
Also there's this great and woefully underused (imo) `[package.metadata]` field.
|
Also there's this great and woefully underused (imo) `[package.metadata]` field.
|
||||||
- Why not use a binary repository instead?
|
- Why not use a binary repository instead?
|
||||||
- Then we'd need to _host_ a binary repository, and worry about publishing and all the other fun things that come with releasing software.
|
- Then we'd need to _host_ a binary repository, and worry about publishing and all the other fun things that come with releasing software.
|
||||||
|
|
|
@ -6,6 +6,7 @@ use log::{debug, info, error};
|
||||||
use cargo_toml::{Manifest};
|
use cargo_toml::{Manifest};
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
|
use xz2::read::XzDecoder;
|
||||||
|
|
||||||
|
|
||||||
use crate::{Meta};
|
use crate::{Meta};
|
||||||
|
@ -66,6 +67,16 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(source: S, fmt: PkgFmt, path: P)
|
||||||
|
|
||||||
tgz.unpack(path)?;
|
tgz.unpack(path)?;
|
||||||
},
|
},
|
||||||
|
PkgFmt::Txz => {
|
||||||
|
// Extract to install dir
|
||||||
|
debug!("Decompressing from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||||
|
|
||||||
|
let dat = std::fs::File::open(source)?;
|
||||||
|
let tar = XzDecoder::new(dat);
|
||||||
|
let mut txz = Archive::new(tar);
|
||||||
|
|
||||||
|
txz.unpack(path)?;
|
||||||
|
},
|
||||||
PkgFmt::Bin => {
|
PkgFmt::Bin => {
|
||||||
debug!("Copying data from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
debug!("Copying data from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||||
// Copy to install dir
|
// Copy to install dir
|
||||||
|
@ -117,10 +128,10 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
|
||||||
|
|
||||||
pub fn confirm() -> Result<bool, anyhow::Error> {
|
pub fn confirm() -> Result<bool, anyhow::Error> {
|
||||||
info!("Do you wish to continue? yes/no");
|
info!("Do you wish to continue? yes/no");
|
||||||
|
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input)?;
|
std::io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
match input.as_str().trim() {
|
match input.as_str().trim() {
|
||||||
"yes" => Ok(true),
|
"yes" => Ok(true),
|
||||||
"no" => Ok(false),
|
"no" => Ok(false),
|
||||||
|
|
|
@ -30,6 +30,8 @@ pub enum PkgFmt {
|
||||||
Tar,
|
Tar,
|
||||||
/// Download format is TGZ (TAR + GZip)
|
/// Download format is TGZ (TAR + GZip)
|
||||||
Tgz,
|
Tgz,
|
||||||
|
/// Download format is TAR + XZ
|
||||||
|
Txz,
|
||||||
/// Download format is raw / binary
|
/// Download format is raw / binary
|
||||||
Bin,
|
Bin,
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,7 @@ pub struct Meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Metadata for binary installation use.
|
/// Metadata for binary installation use.
|
||||||
///
|
///
|
||||||
/// Exposed via `[package.metadata]` in `Cargo.toml`
|
/// Exposed via `[package.metadata]` in `Cargo.toml`
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case", default)]
|
#[serde(rename_all = "kebab-case", default)]
|
||||||
|
@ -146,7 +148,7 @@ mod test {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
manifest.bin.as_slice(),
|
manifest.bin.as_slice(),
|
||||||
&[
|
&[
|
||||||
Product{
|
Product{
|
||||||
name: Some("cargo-binstall".to_string()),
|
name: Some("cargo-binstall".to_string()),
|
||||||
path: Some("src/main.rs".to_string()),
|
path: Some("src/main.rs".to_string()),
|
||||||
edition: Some(cargo_toml::Edition::E2018),
|
edition: Some(cargo_toml::Edition::E2018),
|
||||||
|
|
Loading…
Add table
Reference in a new issue