9 Commits

Author SHA1 Message Date
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
5 changed files with 74 additions and 36 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"

View File

@@ -1,5 +1,19 @@
# `cargo-aur` Changelog
## 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

View File

@@ -1,6 +1,6 @@
[package]
name = "cargo-aur"
version = "1.0.1"
version = "1.0.3"
authors = ["Colin Woodbury <colin@fosskers.ca>"]
edition = "2018"
description = "Prepare Rust projects to be released on the Arch Linux User Repository."
@@ -12,9 +12,12 @@ keywords = ["cargo", "subcommand", "archlinux", "aur"]
categories = ["command-line-utilities"]
[dependencies]
auto_from = "0.3"
anyhow = "1.0"
hmac-sha256 = "0.1"
itertools = "0.9"
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,9 +1,28 @@
use auto_from::From;
use hmac_sha256::Hash;
use itertools::Itertools;
use serde_derive::Deserialize;
use std::fs;
use std::process::{self, Command};
use std::{fmt, fs, io};
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 {
@@ -26,21 +45,14 @@ 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),
Utf8(std::string::FromUtf8Error),
}
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),
Error::Utf8(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
}
}
}
@@ -52,7 +64,7 @@ fn main() {
}
}
fn work() -> Result<(), Error> {
fn work() -> anyhow::Result<()> {
let config = cargo_config()?;
release_build()?;
tarball(&config.package)?;
@@ -63,14 +75,14 @@ fn work() -> Result<(), Error> {
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,12 +90,12 @@ pkgver={}
pkgrel=1
pkgdesc="{}"
url="{}"
license=('{}')
arch=('x86_64')
provides=('{}')
options=('strip')
source=("{}/releases/download/v$pkgver/{}-$pkgver-x86_64.tar.gz")
sha256sums=('{}')
license=("{}")
arch=("x86_64")
provides=("{}")
options=("strip")
source=("{}")
sha256sums=("{}")
package() {{
install -Dm755 {} -t "$pkgdir/usr/bin/"
@@ -100,15 +112,17 @@ 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> {
fn release_build() -> anyhow::Result<()> {
Command::new("cargo")
.arg("build")
.arg("--release")
@@ -116,7 +130,7 @@ fn release_build() -> Result<(), Error> {
Ok(())
}
fn tarball(package: &Package) -> Result<(), Error> {
fn tarball(package: &Package) -> anyhow::Result<()> {
let binary = format!("target/release/{}", package.name);
fs::copy(binary, &package.name)?;
@@ -130,7 +144,7 @@ fn tarball(package: &Package) -> Result<(), Error> {
Ok(())
}
fn sha256sum(package: &Package) -> Result<String, Error> {
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();