mirror of
https://github.com/fosskers/cargo-aur.git
synced 2026-03-09 07:13:12 -05:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2661279b7 | ||
|
|
da899130ae | ||
|
|
8d0ba5be31 | ||
|
|
227c3a7391 | ||
|
|
0c485c43fc | ||
|
|
000b742a22 | ||
|
|
861fa59aa3 | ||
|
|
6a1269e4ae | ||
|
|
7e353578c0 | ||
|
|
f837fd18a6 | ||
|
|
84f4a740b1 | ||
|
|
d8105b04b3 | ||
|
|
c64d112a5d | ||
|
|
428b273d91 | ||
|
|
a8c3736539 | ||
|
|
5b413061b5 | ||
|
|
a32a16489f |
2
.github/workflows/rust.yml
vendored
2
.github/workflows/rust.yml
vendored
@@ -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
|
||||
|
||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
20
README.md
20
README.md
@@ -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
|
||||
|
||||
110
src/main.rs
110
src/main.rs
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user