APKBUILD examples:Rust: Difference between revisions

From Alpine Linux
(use CHOST instead of CTARGET like in the latest newapkbuild)
(add info about an issue with cargo-auditable, fix typo)
 
Line 3: Line 3:
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.
One may encounter an issue when a package refuses to build using <code>cargo-auditable</code>, but successfully builds with <code>cargo</code>. This is because <code>cargo</code> itself exposes faulty data. More info can be found [https://github.com/rust-secure-code/cargo-auditable/issues/124 here].
 
Most Rust projects use <code>cargo</code> to fetch Rust library dependencies. The current convention is 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 ==

Latest revision as of 18:40, 29 October 2025

Considerations

Use cargo-auditable to encode dependency information into binaries.

One may encounter an issue when a package refuses to build using cargo-auditable, but successfully builds with cargo. This is because cargo itself exposes faulty data. More info can be found here.

Most Rust projects use cargo to fetch Rust library dependencies. The current convention is 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