Skip to content

Different Package Build Systems

Elsie edited this page Jul 4, 2024 · 2 revisions

Introduction

As you are making Pacscripts with certain build systems, such as Cargo, CMake, Make, Meson, Poetry, Shell, etc, you should know of some best practices in order to get the most out of your scripts.

Cargo

There are a couple practices that should be used when using Cargo, such as:

  • Using the Cargo.lock file, instead of the Cargo.toml file, by supplying the --locked flag. This is used in order to make sure that you are using precise dependency version specifications chosen by upstream.
  • Using the --release flag, in order to build the fastest and smallest binary.
  • Use -j"${NCPU}" to build with all cores.

All together, your command to build the package should be this:

cargo build -j"${NCPU}" --release --locked

and all together for installation of the binary would be:

build() {
  cargo build -j"${NCPU}" --release --locked
}

package() {
  install -Dm755 "target/release/binary" -t "${pkgdir}/usr/bin"
}

Meson

All together, your Pacscript should look similar to this:

prepare() {
  # Use `build` as the build directory
  meson build --buildtype=release --prefix=/usr
}

build() {
  ninja -C build -j"${NCPU}"
}

package() {
  DESTDIR="${pkgdir}" ninja -C build install
}

Make

Generally, make follows a cycle that is very easy to follow. Check with upstream first if they use anything else before running make, but if they don't have that, generally you run:

  • make -j"${NCPU}" to build the package with all cores.
  • make DESTDIR="${pkgdir}" install to install the package to the staging area for package creation.

All together your Pacscript might look like this:

build() {
  make -j"${NCPU}"
}

package() {
  make DESTDIR="${pkgdir}" install
}

Binary

Binary packages are one of the easiest package types to make besides -deb. Most binary packages will have one required command to install the program, and maybe a couple more for the license and documentation if provided. The install command is recommended because it can create the full directory you're installing to without needing mkdir, and it offers install permissions all in one command.

package() {
  install -Dm755 "binary" -t "${pkgdir}/usr/bin/"
  # Or to install to another name
  install -Dm755 "binary" "${pkgdir}/usr/bin/other_name"
}