#github

binswap-github

Download and swap binaries from GitHub

8 releases

0.1.7 Jan 5, 2024
0.1.6 Mar 10, 2023
0.1.5 Feb 12, 2023

#304 in Operating systems

MIT/Apache and GPL-3.0-only

25KB
298 lines

Crates.io Workflow Status

binswap-github

Download and swap binaries from GitHub

Usage

binswap uses the same infrastructure as cargo-binstall to determine where the latest binaries are stored. binswap-github is the backend to do this for GitHub specifically. It uses the GitHub releases to download binaries for a supported target, and then downloads them to a specified location, or optionally swaps them with the currently executed binary.

This is particularly useful if you distribute binaries outside of package managers or in environments where the users are not expected to have Rust nor installed. With crate, you can bundle the updating mechanism into the distributed binary.

Example

The following example downloads the latest release ripgrep from GitHub, and swaps it with the currently executed binary. .dry_run(true) is added here to simulate the execution, but not perform the update.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    binswap_github::builder()
        .repo_author("BurntSushi")
        .repo_name("ripgrep")
        .asset_name("ripgrep")
        .bin_name("rg")
        .dry_run(true)
        .build()?
        .fetch_and_write_in_place_of_current_exec()
        .await?;

    Ok(())
}

The following does the same, but just writes the resulting binary to a new file.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    binswap_github::builder()
        .repo_author("BurntSushi")
        .repo_name("ripgrep")
        .asset_name("ripgrep")
        .bin_name("rg")
        .dry_run(true)
        .build()?
        .fetch_and_write_to("./rg")
        .await?;

    Ok(())
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~33–68MB
~1.5M SLoC