17 Commits

Author SHA1 Message Date
Colin Woodbury
c2661279b7 1.5.0 2022-04-20 17:13:00 -07:00
Colin Woodbury
da899130ae docs(readme): explain new features 2022-04-20 17:12:09 -07:00
Colin Woodbury
8d0ba5be31 docs: update CHANGELOG 2022-04-20 17:04:30 -07:00
Colin Woodbury
227c3a7391 feat: use Display to pretty-print the arrays 2022-04-20 17:01:48 -07:00
Marcos Gutiérrez Alonso
0c485c43fc Added optional table 2022-04-20 16:32:05 -07:00
Marcos Gutiérrez Alonso
000b742a22 Added optional depends and optdepends 2022-04-20 16:32:05 -07:00
Colin Woodbury
861fa59aa3 fix: allow [[bin]] to be missing 2022-04-20 16:29:14 -07:00
Colin Woodbury
6a1269e4ae docs: update CHANGELOG 2022-04-20 16:19:40 -07:00
Colin Woodbury
7e353578c0 feat: alter which names appear where 2022-04-20 09:56:01 -07:00
Colin Woodbury
f837fd18a6 feat: account for custom binary names 2022-04-18 21:26:26 -07:00
Colin Woodbury
84f4a740b1 chore: bump dependencies 2022-04-18 20:11:03 -07:00
Colin Woodbury
d8105b04b3 Merge pull request #9 from fosskers/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2.4.0 to 3
2022-03-04 12:57:53 -08:00
dependabot[bot]
c64d112a5d Bump actions/checkout from 2.4.0 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 14:02:38 +00:00
Colin Woodbury
428b273d91 Merge pull request #8 from fosskers/dependabot/github_actions/actions/checkout-2.4.0
Bump actions/checkout from 2.3.5 to 2.4.0
2021-11-06 18:51:23 +01:00
dependabot[bot]
a8c3736539 Bump actions/checkout from 2.3.5 to 2.4.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.5 to 2.4.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.5...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-03 14:01:38 +00:00
Colin Woodbury
5b413061b5 Merge pull request #7 from fosskers/dependabot/github_actions/actions/checkout-2.3.5
Bump actions/checkout from 2.3.4 to 2.3.5
2021-10-21 13:59:33 -07:00
dependabot[bot]
a32a16489f Bump actions/checkout from 2.3.4 to 2.3.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-18 14:01:21 +00:00
5 changed files with 134 additions and 22 deletions

View File

@@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests

View File

@@ -1,5 +1,22 @@
# `cargo-aur` Changelog
## 1.5.0 (2022-04-20)
#### Added
- Support for `[[bin]]` sections in `Cargo.toml`, allowing you to specify custom
binary names separate from the package name. [#13]
- Support for specifying PKGBUILD `depends` and `optdepends` via
`[package.metadata]`, as in:
```toml
[package.metadata]
depends = ["nachos", "pizza"]
optdepends = ["sushi", "ramen"]
```
[#13]: https://github.com/fosskers/cargo-aur/pull/13
## 1.4.1 (2021-09-06)
#### Fixed

View File

@@ -1,8 +1,8 @@
[package]
name = "cargo-aur"
version = "1.4.1"
version = "1.5.0"
authors = ["Colin Woodbury <colin@fosskers.ca>"]
edition = "2018"
edition = "2021"
description = "Prepare Rust projects to be released on the Arch Linux User Repository."
homepage = "https://github.com/fosskers/cargo-aur"
repository = "https://github.com/fosskers/cargo-aur"
@@ -14,7 +14,7 @@ categories = ["command-line-utilities"]
[dependencies]
colored = "2.0"
gumdrop = "0.8"
hmac-sha256 = "0.1"
hmac-sha256 = "1.1"
itertools = "0.10"
serde = "1.0"
serde_derive = "1.0"
@@ -22,3 +22,4 @@ toml = "0.5"
[profile.release]
lto = true
strip = true

View File

@@ -29,6 +29,8 @@ cargo install cargo-aur
## Usage
### Basics
Navigate to a Rust project, and run:
```
@@ -62,6 +64,24 @@ 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.
### Custom Binary Names
If you specify a `[[bin]]` section in your `Cargo.toml` and set the `name`
field, this will be used as the binary name to install within the PKGBUILD.
### `depends` and `optdepends`
If your package requires other Arch packages at runtime, you can specify these
within your `Cargo.toml` like this:
```toml
[package.metadata]
depends = ["nachos", "pizza"]
optdepends = ["sushi", "ramen"]
```
And these settings will be copied to your PKGBUILD.
### Static Binaries
Run with `--musl` to produce a release binary that is statically linked via

View File

@@ -35,6 +35,9 @@ struct Args {
/// Use the MUSL build target to produce a static binary.
musl: bool,
/// Don't actually build anything.
dryrun: bool,
}
enum GitHost {
@@ -60,6 +63,18 @@ impl GitHost {
#[derive(Deserialize, Debug)]
struct Config {
package: Package,
#[serde(default)]
bin: Vec<Binary>,
}
impl Config {
/// The name of the compiled binary that should be copied to the tarball.
fn binary_name(&self) -> &str {
self.bin
.first()
.map(|bin| bin.name.as_str())
.unwrap_or(self.package.name.as_str())
}
}
#[derive(Deserialize, Debug)]
@@ -71,6 +86,52 @@ struct Package {
homepage: String,
repository: String,
license: String,
metadata: Option<Metadata>,
}
#[derive(Deserialize, Debug)]
struct Metadata {
#[serde(default)]
depends: Vec<String>,
#[serde(default)]
optdepends: Vec<String>,
}
impl std::fmt::Display for Metadata {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.depends.as_slice() {
[middle @ .., last] => {
write!(f, "depends=(")?;
for item in middle {
write!(f, "\"{}\" ", item)?;
}
if self.optdepends.is_empty().not() {
writeln!(f, "\"{}\")", last)?;
} else {
write!(f, "\"{}\")", last)?;
}
}
[] => {}
}
match self.optdepends.as_slice() {
[middle @ .., last] => {
write!(f, "optdepends=(")?;
for item in middle {
write!(f, "\"{}\" ", item)?;
}
write!(f, "\"{}\")", last)?;
}
[] => {}
}
Ok(())
}
}
#[derive(Deserialize, Debug)]
struct Binary {
name: String,
}
impl Package {
@@ -112,28 +173,31 @@ fn work(args: Args) -> Result<(), Error> {
musl_check()?
}
let package = cargo_config()?;
let license = if must_copy_license(&package.license) {
let config = cargo_config()?;
let license = if must_copy_license(&config.package.license) {
p("LICENSE file will be installed manually.".bold().yellow());
Some(license_file()?)
} else {
None
};
release_build(args.musl)?;
tarball(args.musl, license.as_ref(), &package)?;
let sha256: String = sha256sum(&package)?;
// Write the PKGBUILD.
let file = BufWriter::new(File::create("PKGBUILD")?);
pkgbuild(file, &package, &sha256, license.as_ref())?;
if args.dryrun.not() {
release_build(args.musl)?;
tarball(args.musl, license.as_ref(), &config)?;
let sha256: String = sha256sum(&config.package)?;
// Write the PKGBUILD.
let file = BufWriter::new(File::create("PKGBUILD")?);
pkgbuild(file, &config, &sha256, license.as_ref())?;
}
Ok(())
}
fn cargo_config() -> Result<Package, Error> {
fn cargo_config() -> Result<Config, Error> {
let content = std::fs::read_to_string("Cargo.toml")?;
let proj: Config = toml::from_str(&content)?;
Ok(proj.package)
Ok(proj)
}
/// If a AUR package's license isn't included in `/usr/share/licenses/common/`,
@@ -160,10 +224,11 @@ fn license_file() -> Result<DirEntry, Error> {
/// Write a legal PKGBUILD to some `Write` instance (a `File` in this case).
fn pkgbuild<T: Write>(
mut file: T,
package: &Package,
config: &Config,
sha256: &str,
license: Option<&DirEntry>,
) -> Result<(), Error> {
let package = &config.package;
let authors = package
.authors
.iter()
@@ -172,7 +237,7 @@ fn pkgbuild<T: Write>(
let source = package
.git_host()
.unwrap_or(GitHost::Github)
.source(package);
.source(&config.package);
writeln!(file, "{}", authors)?;
writeln!(file, "#")?;
@@ -190,6 +255,11 @@ fn pkgbuild<T: Write>(
writeln!(file, "arch=(\"x86_64\")")?;
writeln!(file, "provides=(\"{}\")", package.name)?;
writeln!(file, "conflicts=(\"{}\")", package.name)?;
if let Some(metadata) = package.metadata.as_ref() {
writeln!(file, "{}", metadata)?;
}
writeln!(file, "source=(\"{}\")", source)?;
writeln!(file, "sha256sums=(\"{}\")", sha256)?;
writeln!(file)?;
@@ -197,7 +267,7 @@ fn pkgbuild<T: Write>(
writeln!(
file,
" install -Dm755 {} -t \"$pkgdir/usr/bin\"",
package.name
config.binary_name()
)?;
if let Some(lic) = license {
@@ -229,7 +299,7 @@ fn release_build(musl: bool) -> Result<(), Error> {
Ok(())
}
fn tarball(musl: bool, license: Option<&DirEntry>, package: &Package) -> Result<(), Error> {
fn tarball(musl: bool, license: Option<&DirEntry>, config: &Config) -> Result<(), Error> {
let target_dir: OsString = match std::env::var_os("CARGO_TARGET_DIR") {
Some(p) => p,
None => "target".into(),
@@ -241,23 +311,27 @@ fn tarball(musl: bool, license: Option<&DirEntry>, package: &Package) -> Result<
"release"
};
let binary_name = config.binary_name();
let mut binary: PathBuf = target_dir.into();
binary.push(release_dir);
binary.push(&package.name);
binary.push(binary_name);
strip(&binary)?;
std::fs::copy(binary, &package.name)?;
std::fs::copy(binary, binary_name)?;
// Create the tarball.
p("Packing tarball...".bold());
let mut command = Command::new("tar");
command.arg("czf").arg(package.tarball()).arg(&package.name);
command
.arg("czf")
.arg(config.package.tarball())
.arg(binary_name);
if let Some(lic) = license {
command.arg(lic.path());
}
command.status()?;
std::fs::remove_file(&package.name)?;
std::fs::remove_file(binary_name)?;
Ok(())
}