APKBUILD examples:Rust: Difference between revisions

From Alpine Linux
(Add some outgoing links)
(use CHOST instead of CTARGET like in the latest newapkbuild)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:


Use <code>cargo-auditable</code> to encode dependency information into binaries.
Use <code>cargo-auditable</code> to encode dependency information into binaries.
Most Rust projects use <code>cargo</code> to fetch Rust library dependencies. The current convention it to use <code>options="net"</code> fetch these during the <code>prepare()</code> phase. Use the <code>--locked</code> flag to ensure that the exact same versions of dependencies are fetched on each rebuild. If a package is missing a lockfile, include one with the aport and attempt to recommend upstream to include one.


== Examples ==
== Examples ==
Line 23: Line 25:
default_prepare
default_prepare


cargo fetch --target="$CTARGET" --locked
cargo fetch --target="$CHOST" --locked
}
}



Latest revision as of 12:51, 5 October 2025

Considerations

Use cargo-auditable to encode dependency information into binaries.

Most Rust projects use cargo to fetch Rust library dependencies. The current convention it to use options="net" fetch these during the prepare() phase. Use the --locked flag to ensure that the exact same versions of dependencies are fetched on each rebuild. If a package is missing a lockfile, include one with the aport and attempt to recommend upstream to include one.

Examples

Basic example

maintainer="Hugo Osvaldo Barrera <hugo@whynothugo.nl>"
pkgname=harper
pkgver=0.59.0
pkgrel=0
pkgdesc="Grammar checker that respects your privacy"
url="https://github.com/elijah-potter/harper"
arch="all"
license="Apache-2.0"
makedepends="cargo-auditable rust"
source="harper-$pkgver.tar.gz::https://github.com/elijah-potter/harper/archive/v$pkgver/harper-$pkgver.tar.gz"
options="net"

prepare() {
	default_prepare

	cargo fetch --target="$CHOST" --locked
}

build() {
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/harper-cli "$pkgdir"/usr/bin/harper-cli
	install -Dm755 target/release/harper-ls "$pkgdir"/usr/bin/harper-ls
}

sha512sums="
e5be781b33ba624e2447464a51ff8c0b565a42d7bf957c2fd6655f4bf312211fcf669bbb152b62a57494f89fd7fbee7eda37bbbaf7a61c5d4c8c9684ffe687bd  harper-0.48.0.tar.gz
"

See also