Meson package guidelines

From ArchWiki
(Redirected from Meson)
Arch package guidelines

32-bitCLRCMakeCrossDKMSEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMesonMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustShellVCSWebWine

From Meson's official website:

Meson is an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible.

Written in Python, Meson features multi-platform support, support several programming languages, cross compilation, and more.

Meson does not build software directly, but rather sets up a back-end build system. While it is commonly used with ninja, other build systems can be used. It is commonly used to replace GNU Build System.

This document covers standards and guidelines on writing PKGBUILDs for software that uses Meson.



meson has to be included to the PKGBUILD's makedepends array.


Configuring and building is normally done using meson binary, but it can also be done by using Arch Linux's arch-meson wrapper script.

Both meson and arch-meson commands include in the usage syntax options, source directory and build directory:

  • options: must include at least --prefix /usr, but make sure to check other options with meson configure --help; also check software-specific build options.
  • source directory (or "sourcedir"): where the software's source code is stored, e.g. ., $pkgname or $pkgname-$pkgver.
  • build directory (or "builddir"): where the build files will stored by Meson; commonly named build or _build, but it is discretionary.
Note: It does not matter if source directory is passed to meson before the build directory, and vice-versa, as Meson will know which is which and will set up the environment properly.

Using meson binary directly

Notice --prefix=/usr always needs to be passed to meson binary because Arch Linux packages must not install files to /usr/local, according Arch package guidelines#Package etiquette. The --buildtype=plain built-in option can be set to another value, if you know what you are doing.


build() {
  meson --prefix=/usr --buildtype=plain source build
  meson compile -C build

meson compile is a wrapper for supported back-end build systems, which currently defaults to ninja[1]

Tip: ninja -C build could be directly used instead.

Using arch-meson wrapper script

arch-meson is a wrapper script included in meson package which has the advantage of setting some of Meson built-in options that would probably be used in an Arch package, saving packager's time and code in the PKGBUILD. Quoting the description written in arch-meson, it is a "Highly opinionated wrapper for Arch Linux packaging".


build() {
  arch-meson source build
  meson compile -C build

Setting software-specific build options

While Meson has some built-in build options (e.g. --prefix), the software being packaged could have other build options which the packager should consider. Valid software-specific build options are normally found in a file named meson_options.txt (if present) and in Look for option(settings) in these files, then read the settings.

To use a software-specific build option, use the notation -D key=value, where key is the build option name set in the project and value is a valid value, like e.g. true.

For instance, gtranslator has the following build options:

option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')

So, to build its documentation, one must run Meson appending -D gtk_doc=true build option, resulting in a command line like e.g.

arch-meson $pkgname-$pkgver build -Dgtk_doc=true


If the software being packaged provides test suite, consider running it in the PKGBUILD's check() function. This can be accomplished with meson test command.


check() {
  meson test -C build

where build is the same build directory name used in the above #build() step.

  • ninja test -C build could be directly used instead.
  • The --print-errorlogs parameter can be added to meson test in order to report the output produced by the failing tests along with other useful information as the environmental variables.

See meson test --help and Unit tests in Meson docs for more info.


Packaging normally requires running only meson install, but check if another installation command is required (e.g. an uncommon license). Use the same build directory as above and set the --destdir flag:

package() {
  meson install -C build --destdir "$pkgdir"
Note: Appending DESTDIR="$pkgdir" is also a valid alternative to --destdir.[2]
Tip: ninja install -C build could be directly used instead.


ERROR: Function does not take positional arguments

Example of error output:

 data/ ERROR: Function does not take positional arguments.

Error present since Meson 0.60, which promoted from warning to error the use of positional arguments. One very common example of this error is to add invalid arguments to i18n.merge_file(). For instance, aisleriot had:

  input: '',
  output: '@BASENAME@',
  po_dir: po_dir,`

where 'sol.metainfo.xml' is the now invalid argument that should be removed. For the fix applied in the upstream, see this commit.

Measures to be taken in this case:

  1. Patch the reported in the error to fix the build, and the publish the updated PKGBUILD (if that is case)
  2. Contribute to the upstream repository with your patch, to fix it for everyone and to avoid having patches in the source array in the next versions.


To sum up the above instructions and to provide a single copy-and-paste point, see the template below:


build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build

check() {
  meson test -C build --print-errorlogs

package() {
  meson install -C build --destdir "$pkgdir"

Example packages

This is a small list of packages that use Meson. See other packages in the list "Required by" in meson package's page.

See also