Rust package guidelines
32-bit – CLR – CMake – Cross – Eclipse – Electron – Font – Free Pascal – GNOME – Go – Haskell – Java – KDE – Kernel – Lisp – MinGW – Node.js – Nonfree – OCaml – Perl – PHP – Python – R – Ruby – Rust – VCS – Web – Wine
This document covers standards and guidelines on writing PKGBUILDs for Rust.
Contents
General guidelines
Package naming
For Rust binaries use only the program name.
Building
Building a Rust package.
build() {
cargo build --release --locked --all-features
}
where:
-
--releasetells cargo to compile a release build -
--lockedtells cargo to adhere theCargo.lockfile and prevent it from updating dependencies which is important for reproducible builds. -
--all-featurestells cargo to compile with all features of the package enabled. Use--features FEATURE1,FEATURE2instead if you enable only selected features.
Check
Most Rust projects provide a simple way to run the testsuite.
check() {
cargo test --release --locked
}
Package
Rust builds binaries in target/release and can simply be installed to /usr/bin.
package() {
install -Dm 755 target/release/${pkgname} -t "${pkgdir}/usr/bin"
}
If a package has more than one executables in /usr/bin you can use find command:
package() {
find target/release \
-maxdepth 1 \
-executable \
-type f \
-exec install -m 755 "{}" "$pkgdir"/usr/bin \;
}
Notes about using cargo install
Some packages should install more files such as a man page, so in that case it would be better to use cargo, in this case build() is unnecessary because cargo install forces rebuilding even if the package already has been built by using cargo build.:
build() {
return 0
}
package() {
cargo install --no-track --root "${pkgdir}"/usr --root "${srcdir}/${pkgname}-${pkgver}"
}
The --no-track argument should always be used, because cargo install may create unwanted files such as /usr/.crates.toml or /usr/.crates2.json unless it is specified.
Example packages
Click Package Actions > Source Files in the package page to see its example PKGBUILD.