18 Commits

Author SHA1 Message Date
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
Colin Woodbury
e92757c05f 1.1.0 2020-08-10 16:37:01 -07:00
Colin Woodbury
86adc54767 New --musl flag to link statically 2020-08-10 16:35:20 -07:00
Colin Woodbury
1a9d6d4a5d 1.0.3 2020-07-18 08:07:12 -07:00
Colin Woodbury
4d49e5de70 Dependabot config 2020-07-09 18:46:41 -07:00
Colin Woodbury
a7069f4516 AUR readme badge 2020-06-22 12:08:38 -07:00
Colin Woodbury
386817305a 1.0.2 2020-06-22 12:00:32 -07:00
Colin Woodbury
700cd6ca81 Drop auto_from for anyhow 2020-06-22 11:57:09 -07:00
Colin Woodbury
523c30c138 Update README 2020-06-17 19:03:36 -07:00
Colin Woodbury
d04ece223f CHANGELOG 2020-06-17 18:50:15 -07:00
Colin Woodbury
d2753668c1 Auto-detect the git host instead 2020-06-17 18:48:36 -07:00
Colin Woodbury
2e89c3f8cb Provide --gitlab to override source link 2020-06-17 18:40:16 -07:00
Colin Woodbury
8806637927 1.0.1 2020-06-17 11:23:18 -07:00
Colin Woodbury
7585a5e683 Make sure to not silently dropping leading hex 0s 2020-06-17 11:20:30 -07:00
Colin Woodbury
5ece70fa6d Use sha256 instead 2020-06-17 11:15:35 -07:00
Colin Woodbury
0be17929dd Minor lint 2020-06-15 10:13:55 -07:00
Colin Woodbury
46f14155f4 Remove bad category slug 2020-06-10 20:39:50 -07:00
6 changed files with 137 additions and 56 deletions

6
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/target
deps.png
pkg/
Cargo.lock

View File

@@ -1,5 +1,39 @@
# `cargo-aur` Changelog
## 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
- The `--musl` flag to compile the release binary with the MUSL target. In most
cases, this will result in a fully statically linked binary.
## 1.0.3 (2020-07-18)
#### Changed
- Better release profile which produces smaller binaries.
## 1.0.2 (2020-06-22)
#### Changed
- `cargo aur` will now auto-detect the git host (Github or Gitlab) and generated
a `source` link based on that.
- Fewer dependencies.
## 1.0.1 (2020-06-17)
#### Changed
- Use `sha256` instead of `md5`.
- The `install` line in `package()` is now more modern as a one-liner.
## 1.0.0 (2020-06-10)
This is the initial release.

View File

@@ -1,6 +1,6 @@
[package]
name = "cargo-aur"
version = "1.0.0"
version = "1.1.1"
authors = ["Colin Woodbury <colin@fosskers.ca>"]
edition = "2018"
description = "Prepare Rust projects to be released on the Arch Linux User Repository."
@@ -9,12 +9,16 @@ repository = "https://github.com/fosskers/cargo-aur"
readme = "README.md"
license = "MIT"
keywords = ["cargo", "subcommand", "archlinux", "aur"]
categories = ["cargo-plugins", "command-line-utilities"]
categories = ["command-line-utilities"]
[dependencies]
auto_from = "0.3"
anyhow = "1.0"
gumdrop = "0.8"
hmac-sha256 = "0.1"
itertools = "0.9"
md5 = "0.7"
serde = "1.0"
serde_derive = "1.0"
toml = "0.5"
[profile.release]
lto = true

View File

@@ -2,6 +2,7 @@
[![Build](https://github.com/fosskers/cargo-aur/workflows/Build/badge.svg)](https://github.com/fosskers/cargo-aur/actions)
[![](https://img.shields.io/crates/v/cargo-aur.svg)](https://crates.io/crates/cargo-aur)
![AUR version](https://img.shields.io/aur/version/cargo-aur-bin)
`cargo-aur` is a new subcommand for `cargo` that produces a release tarball and
PKGBUILD file for a Rust project, so that it can be released on the Arch Linux
@@ -14,7 +15,7 @@ a PKGBUILD will be generated with all the necessary sections filled out.
## Installation
Guess what? `cargo-aur` itself is on the AUR! Install it with an AUR-compatible
package manager:
package manager like [`aura`](https://github.com/fosskers/aura):
```
sudo aura -A cargo-aur-bin
@@ -52,8 +53,8 @@ AUR standard.
At this point, it is up to you to:
1. Create an official `Release` on Github, attaching the original binary tarball
that `cargo aur` produced.
1. Create an official `Release` on Github/Gitlab, attaching the original binary
tarball that `cargo aur` produced.
2. Copy the PKGBUILD to a git repo that tracks releases of your package.
3. Run `makepkg --printsrcinfo > .SRCINFO`.
4. Commit both files and push to the AUR.

View File

@@ -1,8 +1,40 @@
use auto_from::From;
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::{fmt, fs, io};
#[derive(Options)]
struct Args {
help: bool,
#[options(free)]
args: Vec<String>,
/// Use the MUSL build target to produce a static binary.
musl: bool,
}
enum GitHost {
Github,
Gitlab,
}
impl GitHost {
fn source(&self, package: &Package) -> String {
match self {
GitHost::Github => format!(
"{}/releases/download/v$pkgver/{}-$pkgver-x86_64.tar.gz",
package.repository, package.name
),
GitHost::Gitlab => format!(
"{}/-/archive/v$pkgver/{}-$pkgver-x86_64.tar.gz",
package.repository, package.name
),
}
}
}
#[derive(Deserialize, Debug)]
struct Config {
@@ -25,52 +57,46 @@ impl Package {
fn tarball(&self) -> String {
format!("{}-{}-x86_64.tar.gz", self.name, self.version)
}
}
#[derive(From)]
enum Error {
Io(io::Error),
Parsing(toml::de::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Io(e) => write!(f, "{}", e),
Error::Parsing(e) => write!(f, "{}", e),
fn git_host(&self) -> Option<GitHost> {
if self.repository.starts_with("https://github") {
Some(GitHost::Github)
} else if self.repository.starts_with("https://gitlab") {
Some(GitHost::Gitlab)
} else {
None
}
}
}
fn main() {
match work() {
Err(e) => {
eprintln!("{}", e);
process::exit(1)
}
Ok(_) => {}
let args = Args::parse_args_or_exit(ParsingStyle::AllOptions);
if let Err(e) = work(args) {
eprintln!("{}", e);
process::exit(1)
}
}
fn work() -> Result<(), Error> {
fn work(args: Args) -> anyhow::Result<()> {
let config = cargo_config()?;
release_build()?;
tarball(&config.package)?;
let md5 = md5sum(&config.package)?;
let pkgbuild = pkgbuild(&config.package, &md5);
release_build(args.musl)?;
tarball(args.musl, &config.package)?;
let sha256 = sha256sum(&config.package)?;
let pkgbuild = pkgbuild(&config.package, &sha256);
fs::write("PKGBUILD", pkgbuild)?;
Ok(())
}
fn cargo_config() -> Result<Config, Error> {
fn cargo_config() -> anyhow::Result<Config> {
let content = fs::read_to_string("Cargo.toml")?;
let proj = toml::from_str(&content)?;
Ok(proj) // TODO Would like to do this in one line with the above.
}
/// Produce a legal PKGBUILD.
fn pkgbuild(package: &Package, md5: &str) -> String {
fn pkgbuild(package: &Package, sha256: &str) -> String {
format!(
r#"{}
pkgname={}-bin
@@ -78,16 +104,15 @@ pkgver={}
pkgrel=1
pkgdesc="{}"
url="{}"
license=('{}')
arch=('x86_64')
provides=('{}')
options=('strip')
source=({}/releases/download/v$pkgver/{}-$pkgver-x86_64.tar.gz)
md5sums=('{}')
license=("{}")
arch=("x86_64")
provides=("{}")
options=("strip")
source=("{}")
sha256sums=("{}")
package() {{
mkdir -p "$pkgdir/usr/bin/"
install -m 755 {} "$pkgdir/usr/bin/"
install -Dm755 {} -t "$pkgdir/usr/bin/"
}}
"#,
package
@@ -101,24 +126,33 @@ package() {{
package.homepage,
package.license,
package.name,
package.repository,
package.name,
md5,
package
.git_host()
.unwrap_or(GitHost::Github)
.source(package),
sha256,
package.name,
)
}
/// Run `cargo build --release`.
fn release_build() -> Result<(), Error> {
Command::new("cargo")
.arg("build")
.arg("--release")
.status()?;
/// Run `cargo build --release`, potentially building statically.
fn release_build(musl: bool) -> anyhow::Result<()> {
let mut args = vec!["build", "--release"];
if musl {
args.push("--target=x86_64-unknown-linux-musl");
}
Command::new("cargo").args(args).status()?;
Ok(())
}
fn tarball(package: &Package) -> Result<(), Error> {
let binary = format!("target/release/{}", package.name);
fn tarball(musl: bool, package: &Package) -> anyhow::Result<()> {
let binary = if musl {
format!("target/x86_64-unknown-linux-musl/release/{}", package.name)
} else {
format!("target/release/{}", package.name)
};
fs::copy(binary, &package.name)?;
Command::new("tar")
@@ -131,8 +165,9 @@ fn tarball(package: &Package) -> Result<(), Error> {
Ok(())
}
fn md5sum(package: &Package) -> Result<String, Error> {
fn sha256sum(package: &Package) -> anyhow::Result<String> {
let bytes = fs::read(package.tarball())?;
let digest = md5::compute(bytes);
Ok(format!("{:x}", digest))
let digest = Hash::hash(&bytes);
let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();
Ok(hex)
}