8 releases
0.1.7 | Jan 5, 2024 |
---|---|
0.1.6 | Mar 10, 2023 |
0.1.5 | Feb 12, 2023 |
#331 in Operating systems
25KB
298 lines
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
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
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
~35–70MB
~1.5M SLoC