8 Commits

Author SHA1 Message Date
Colin Woodbury
f7871899d9 1.2.0 2020-08-24 14:19:46 -07:00
Colin Woodbury
06c5ab9b69 Add --version flag 2020-08-24 14:17:55 -07:00
Colin Woodbury
8903c72da6 1.1.2 2020-08-11 14:24:24 -07:00
Colin Woodbury
109d9a66a7 Mention --musl in the README 2020-08-11 14:20:52 -07:00
Colin Woodbury
8e223c5a2d Warn if the MUSL target is missing when using --musl 2020-08-11 14:14:26 -07:00
Colin Woodbury
b1383ff6ff Strip the release binary before tarring it 2020-08-11 13:49:18 -07:00
Colin Woodbury
c8892b4189 1.1.1 2020-08-11 13:28:35 -07:00
Colin Woodbury
ab018dce5f Capture all free arguments 2020-08-11 13:27:40 -07:00
4 changed files with 81 additions and 2 deletions

View File

@@ -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

View File

@@ -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."

View File

@@ -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
```

View File

@@ -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"
))
}
}