Rust package guidelines

From ArchWiki
Revision as of 04:56, 30 December 2019 by Kbumsik (talk | contribs) (Add how to use find command when there are more than one execuables in /usr/bin)
Jump to navigation Jump to search
Arch package guidelines

32-bitCLRCrossEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustVCSWebWine

This document covers standards and guidelines on writing PKGBUILDs for Rust.

General guidelines

Package naming

For Rust binaries use only the program name.

Note: The package name should be entirely lowercase.


Building a Rust package.

 build() {
   cargo build --release --locked --all-features


  • --release tells cargo to compile a release build
  • --locked tells cargo to adhere the Cargo.lock file and prevent it from updating dependencies which is important for reproducible builds.
  • --all-features tells cargo to compile with all features of the package enabled. Use --features FEATURE1,FEATURE2 instead if you enable only selected features.


Most Rust projects provide a simple way to run the testsuite.

 check() {
   cargo test --release --locked


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 --root "${pkgdir}"/usr --root "${srcdir}/${pkgname}-${pkgver}"

Unless necessary, this way should be avoided because cargo install also may create unwanted files such as /usr/.crates.toml or /usr/.crates2.json so the package maintainer should take extra care on what cargo install creates and manually delete those files.

Example packages

Click Package Actions -> Source Files in the package page to see its example PKGBUILD.