mirror of
https://github.com/fosskers/cargo-aur.git
synced 2026-03-24 15:31:29 -05:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7871899d9 | ||
|
|
06c5ab9b69 | ||
|
|
8903c72da6 | ||
|
|
109d9a66a7 | ||
|
|
8e223c5a2d | ||
|
|
b1383ff6ff | ||
|
|
c8892b4189 | ||
|
|
ab018dce5f |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,5 +1,28 @@
|
||||
# `cargo-aur` Changelog
|
||||
|
||||
## 1.2.0 (2020-08-24)
|
||||
|
||||
#### Added
|
||||
|
||||
- A `--version` flag to display the current version of `cargo-aur`.
|
||||
|
||||
## 1.1.2 (2020-08-11)
|
||||
|
||||
#### Added
|
||||
|
||||
- When using `--musl`, the user is warned if they don't have the
|
||||
`x86_64-unknown-linux-musl` target installed.
|
||||
|
||||
#### Changed
|
||||
|
||||
- Run `strip` on the release binary before `tar`ring it.
|
||||
|
||||
## 1.1.1 (2020-08-11)
|
||||
|
||||
#### Fixed
|
||||
|
||||
- A breaking bug in `1.1.0` which prevented it from working at all.
|
||||
|
||||
## 1.1.0 (2020-08-10)
|
||||
|
||||
#### Added
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cargo-aur"
|
||||
version = "1.1.0"
|
||||
version = "1.2.0"
|
||||
authors = ["Colin Woodbury <colin@fosskers.ca>"]
|
||||
edition = "2018"
|
||||
description = "Prepare Rust projects to be released on the Arch Linux User Repository."
|
||||
|
||||
12
README.md
12
README.md
@@ -61,3 +61,15 @@ At this point, it is up to you to:
|
||||
|
||||
Some of these steps may be automated in `cargo aur` at a later date if there is
|
||||
sufficient demand.
|
||||
|
||||
### Static Binaries
|
||||
|
||||
Run with `--musl` to produce a release binary that is statically linked via
|
||||
[MUSL](https://musl.libc.org/).
|
||||
|
||||
```
|
||||
> cargo aur --musl
|
||||
> cd target/x86_64-unknown-linux-musl/release/
|
||||
> ldd <your-binary>
|
||||
not a dynamic executable
|
||||
```
|
||||
|
||||
46
src/main.rs
46
src/main.rs
@@ -1,14 +1,24 @@
|
||||
use anyhow::anyhow;
|
||||
use gumdrop::{Options, ParsingStyle};
|
||||
use hmac_sha256::Hash;
|
||||
use itertools::Itertools;
|
||||
use serde_derive::Deserialize;
|
||||
use std::fs;
|
||||
use std::process::{self, Command};
|
||||
use std::str;
|
||||
|
||||
#[derive(Options)]
|
||||
struct Args {
|
||||
/// Display this help message.
|
||||
help: bool,
|
||||
|
||||
/// Display the current version of this software.
|
||||
version: bool,
|
||||
|
||||
/// Unused.
|
||||
#[options(free)]
|
||||
args: Vec<String>,
|
||||
|
||||
/// Use the MUSL build target to produce a static binary.
|
||||
musl: bool,
|
||||
}
|
||||
@@ -69,13 +79,22 @@ impl Package {
|
||||
fn main() {
|
||||
let args = Args::parse_args_or_exit(ParsingStyle::AllOptions);
|
||||
|
||||
if let Err(e) = work(args) {
|
||||
if args.version {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
println!("{}", version);
|
||||
} else if let Err(e) = work(args) {
|
||||
eprintln!("{}", e);
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
fn work(args: Args) -> anyhow::Result<()> {
|
||||
// We can't proceed if the user has specified `--musl` but doesn't have the
|
||||
// target installed.
|
||||
if args.musl {
|
||||
musl_check()?
|
||||
}
|
||||
|
||||
let config = cargo_config()?;
|
||||
release_build(args.musl)?;
|
||||
tarball(args.musl, &config.package)?;
|
||||
@@ -151,6 +170,7 @@ fn tarball(musl: bool, package: &Package) -> anyhow::Result<()> {
|
||||
format!("target/release/{}", package.name)
|
||||
};
|
||||
|
||||
strip(&binary)?;
|
||||
fs::copy(binary, &package.name)?;
|
||||
Command::new("tar")
|
||||
.arg("czf")
|
||||
@@ -162,9 +182,33 @@ fn tarball(musl: bool, package: &Package) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Strip the release binary, so that we aren't compressing more bytes than we
|
||||
/// need to.
|
||||
fn strip(path: &str) -> anyhow::Result<()> {
|
||||
Command::new("strip").arg(path).status()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sha256sum(package: &Package) -> anyhow::Result<String> {
|
||||
let bytes = fs::read(package.tarball())?;
|
||||
let digest = Hash::hash(&bytes);
|
||||
let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();
|
||||
Ok(hex)
|
||||
}
|
||||
|
||||
/// Does the user have the `x86_64-unknown-linux-musl` target installed?
|
||||
fn musl_check() -> anyhow::Result<()> {
|
||||
let args = vec!["target", "list", "--installed"];
|
||||
let output = Command::new("rustup").args(args).output()?.stdout;
|
||||
let installed = str::from_utf8(&output)?
|
||||
.lines()
|
||||
.any(|tc| tc == "x86_64-unknown-linux-musl");
|
||||
|
||||
if installed {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"Missing target! Try: rustup target add x86_64-unknown-linux-musl"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user