CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Different Package Build Systems
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.
Whenever possible, make sure to use the upstream developer's build system to install files as well.
For this guide, we are using the hypothetical directory source/
as the directory where our sources were extracted to.
There are a couple practices that should be used when using Cargo, such as:
- Using the
Cargo.lock
file, instead of theCargo.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. - Trying not to fiddle with build flags enabled in
Cargo.toml
. We believe that upstream knows best for their package and therefore try not to mess with their setup. The one exception is feature flags, which you can change if enabling (or disabling) a feature would allow for better system integration or a generally better user experience. - Use
cargo msrv find
to find the lowest possible cargo version that can be used to build this package and version lock it inmakedepends
.
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() {
cd source/
cargo build -j"${NCPU}" --release --locked
}
package() {
cd source/
install -Dm755 "target/release/binary" -t "${pkgdir}/usr/bin"
}
- Set the package prefix to
/usr
using--prefix=/usr
(as to not default to/usr/local
as mandated by Debian packaging guidelines). - Set the buildtype to
release
, using--buildtype=release
. - Install using
DESTDIR
.
All together, your Pacscript should look similar to this:
prepare() {
cd source/
# Use `build` as the build directory
meson setup build/ --buildtype=release --prefix=/usr
}
build() {
cd source/
ninja -C build/ -j"${NCPU}"
}
package() {
cd source/
DESTDIR="${pkgdir}" ninja -C build/ install
}
CMake can be a little tricky because some projects have very specific instructions for building their package, so please check with upstream first before using this guide.
Generally, you will want to:
- Setup a build directory in
prepare()
. - Build inside that directory with a release flag and compile it.
-
make install
after.
All together, your pacscript might look like this:
prepare() {
cd source/
mkdir build/
}
build() {
cd source/build/
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j"${NCPU}"
}
package() {
cd source/
make DESTDIR="${pkgdir}" install
}
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() {
cd source/
make -j"${NCPU}"
}
package() {
cd source/
make DESTDIR="${pkgdir}" install
}
While technically not a build system, there are some packaging guidelines for these packages.
- Never extract appimages out of their compressed format to install to
/
. - If you ship a desktop file, modify the
Exec
line toExec=env APPIMAGELAUNCHER_DISABLE=1 $COMMAND$
in order to prevent AppImageLauncher from trying to integrate an already integrated appimage to the system.
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() {
cd source/
install -Dm755 "binary" -t "${pkgdir}/usr/bin/"
# Or to install to another name
install -Dm755 "binary" "${pkgdir}/usr/bin/other_name"
}