Meson package guidelines

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

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.

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.

Usage

Requirements

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

build()

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 , but it is discretionary.

Using meson binary directly

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

Example:

build() {
  meson --prefix=/usr --buildtype=plain source build
  meson compile -C build
}
is a wrapper for supported back-end build systems, which currently defaults to ninja
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".

Example:

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 (if present) and in . Look for in these files, then read the .

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

For instance, has the following build options:

meson_options.txt
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

check()

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

Example:

check() {
  meson test -C build
}

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

See and Unit tests in Meson docs for more info.

package()

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

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

Troubleshooting

ERROR: Function does not take positional arguments

Example of error output:

 data/meson.build:21:5: 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, had:

i18n.merge_file(
  'sol.metainfo.xml',
  input: desktop_in,
  output: '@BASENAME@',
  type: 'desktop',
  po_dir: po_dir,
  install: true,
  install_dir: desktopdatadir,
)

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 meson.build 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.

Template

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

makedepends=(meson)

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.

gollark: Clearly, what gollariosity SHOULD do is... something?
gollark: Gollariosity cooperates iff the opponent would cooperate in the same position. But this is actually suboptimal.
gollark: ```scheme(maybe-tit-for-tat-or-grudger 1280)(alt 982)(gollariosity 1254)(grudger 1307)(devil 1097)(mean-tit-for-tat 989)(tit-for-tat 1306)(angel 1198)```
gollark: I MAY have to improve gollariosity.
gollark: Actually, it doesn't.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.